mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
e5731b0d3b
* add setup steps * refactoring * omitempty * cleanup * begin org * create org * setup org * setup org * merge * fixes * fixes * fixes * add project * add oidc application * fix app creation * add resourceOwner to writemodels * resource owner * cleanup * global org, iam project and iam member in setup * logs * logs * logs * cleanup * Update internal/v2/command/project.go Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * check project state Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package command
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
"github.com/caos/zitadel/internal/v2/repository/project"
|
|
)
|
|
|
|
type ProjectMemberWriteModel struct {
|
|
MemberWriteModel
|
|
}
|
|
|
|
func NewProjectMemberWriteModel(projectID, userID, resourceOwner string) *ProjectMemberWriteModel {
|
|
return &ProjectMemberWriteModel{
|
|
MemberWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: projectID,
|
|
ResourceOwner: resourceOwner,
|
|
},
|
|
UserID: userID,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectMemberWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *project.MemberAddedEvent:
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
continue
|
|
}
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberAddedEvent)
|
|
case *project.MemberChangedEvent:
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
continue
|
|
}
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberChangedEvent)
|
|
case *project.MemberRemovedEvent:
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
continue
|
|
}
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberRemovedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectMemberWriteModel) Reduce() error {
|
|
return wm.MemberWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *ProjectMemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, project.AggregateType).
|
|
AggregateIDs(wm.MemberWriteModel.AggregateID).
|
|
ResourceOwner(wm.ResourceOwner)
|
|
}
|