mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +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>
83 lines
2.2 KiB
Go
83 lines
2.2 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 ProjectGrantMemberWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
GrantID string
|
|
UserID string
|
|
Roles []string
|
|
|
|
State domain.MemberState
|
|
}
|
|
|
|
func NewProjectGrantMemberWriteModel(projectID, userID, grantID string) *ProjectGrantMemberWriteModel {
|
|
return &ProjectGrantMemberWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: projectID,
|
|
},
|
|
UserID: userID,
|
|
GrantID: grantID,
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectGrantMemberWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *project.GrantMemberAddedEvent:
|
|
if e.UserID != wm.UserID || e.GrantID != wm.GrantID {
|
|
continue
|
|
}
|
|
wm.WriteModel.AppendEvents(e)
|
|
case *project.GrantMemberChangedEvent:
|
|
if e.UserID != wm.UserID || e.GrantID != wm.GrantID {
|
|
continue
|
|
}
|
|
wm.WriteModel.AppendEvents(e)
|
|
case *project.GrantMemberRemovedEvent:
|
|
if e.UserID != wm.UserID || e.GrantID != wm.GrantID {
|
|
continue
|
|
}
|
|
wm.WriteModel.AppendEvents(e)
|
|
case *project.GrantRemovedEvent:
|
|
if e.GrantID != wm.GrantID {
|
|
continue
|
|
}
|
|
wm.WriteModel.AppendEvents(e)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectGrantMemberWriteModel) Reduce() error {
|
|
for _, event := range wm.Events {
|
|
switch e := event.(type) {
|
|
case *project.GrantMemberAddedEvent:
|
|
wm.Roles = e.Roles
|
|
wm.State = domain.MemberStateActive
|
|
case *project.GrantMemberChangedEvent:
|
|
wm.Roles = e.Roles
|
|
case *project.GrantMemberRemovedEvent:
|
|
wm.State = domain.MemberStateRemoved
|
|
case *project.GrantRemovedEvent, *project.ProjectRemovedEvent:
|
|
wm.State = domain.MemberStateRemoved
|
|
}
|
|
}
|
|
return wm.WriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *ProjectGrantMemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, project.AggregateType).
|
|
AggregateIDs(wm.AggregateID)
|
|
//EventTypes(
|
|
// project.GrantMemberAddedType,
|
|
// project.GrantMemberChangedType,
|
|
// project.GrantMemberRemovedType,
|
|
// project.GrantRemovedType,
|
|
// project.ProjectRemovedType)
|
|
}
|