mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
c65331df1a
* fix: project events * fix: project events * fix: project events * fix: eventmapper * fix: project commands * fix: project role commands * fix: project command side * fix: oidc application * fix: oidc application * fix: reduce * fix: reduce * fix: project member * fix: project grant command side * fix: application command side * fix: project grant member remove * Update internal/v2/command/project.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/project.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/project_application.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/project_application.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/project_application.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: oidc application string pw * fix: project events * fix: project grant member * feat: change application to interface Co-authored-by: Livio Amstutz <livio.a@gmail.com>
105 lines
2.8 KiB
Go
105 lines
2.8 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
|
"github.com/caos/zitadel/internal/v2/repository/project"
|
|
)
|
|
|
|
type ProjectGrantWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
GrantID string
|
|
GrantedOrgID string
|
|
RoleKeys []string
|
|
State domain.ProjectGrantState
|
|
}
|
|
|
|
func NewProjectGrantWriteModel(grantID, projectID, resourceOwner string) *ProjectGrantWriteModel {
|
|
return &ProjectGrantWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: projectID,
|
|
ResourceOwner: resourceOwner,
|
|
},
|
|
GrantID: grantID,
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectGrantWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *project.GrantAddedEvent:
|
|
if e.GrantID == wm.GrantID {
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
case *project.GrantChangedEvent:
|
|
if e.GrantID == wm.GrantID {
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
case *project.GrantCascadeChangedEvent:
|
|
if e.GrantID == wm.GrantID {
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
case *project.GrantDeactivateEvent:
|
|
if e.GrantID == wm.GrantID {
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
case *project.GrantReactivatedEvent:
|
|
if e.GrantID == wm.GrantID {
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
case *project.GrantRemovedEvent:
|
|
if e.GrantID == wm.GrantID {
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
case *project.ProjectRemovedEvent:
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectGrantWriteModel) Reduce() error {
|
|
for _, event := range wm.Events {
|
|
switch e := event.(type) {
|
|
case *project.GrantAddedEvent:
|
|
wm.GrantID = e.GrantID
|
|
wm.GrantedOrgID = e.GrantedOrgID
|
|
wm.RoleKeys = e.RoleKeys
|
|
wm.State = domain.ProjectGrantStateActive
|
|
case *project.GrantChangedEvent:
|
|
wm.RoleKeys = e.RoleKeys
|
|
case *project.GrantCascadeChangedEvent:
|
|
wm.RoleKeys = e.RoleKeys
|
|
case *project.GrantDeactivateEvent:
|
|
if wm.State == domain.ProjectGrantStateRemoved {
|
|
continue
|
|
}
|
|
wm.State = domain.ProjectGrantStateInactive
|
|
case *project.GrantReactivatedEvent:
|
|
if wm.State == domain.ProjectGrantStateRemoved {
|
|
continue
|
|
}
|
|
wm.State = domain.ProjectGrantStateActive
|
|
case *project.GrantRemovedEvent:
|
|
wm.State = domain.ProjectGrantStateRemoved
|
|
case *project.ProjectRemovedEvent:
|
|
wm.State = domain.ProjectGrantStateRemoved
|
|
}
|
|
}
|
|
return wm.WriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *ProjectGrantWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, project.AggregateType).
|
|
AggregateIDs(wm.AggregateID).
|
|
ResourceOwner(wm.ResourceOwner)
|
|
//EventTypes(
|
|
// project.GrantAddedType,
|
|
// project.GrantChangedType,
|
|
// project.GrantCascadeChangedType,
|
|
// project.GrantDeactivatedType,
|
|
// project.GrantReactivatedType,
|
|
// project.GrantRemovedType,
|
|
// project.ProjectRemovedType)
|
|
}
|