mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +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/domain"
|
|
"github.com/caos/zitadel/internal/v2/repository/iam"
|
|
)
|
|
|
|
type IAMMemberWriteModel struct {
|
|
MemberWriteModel
|
|
}
|
|
|
|
func NewIAMMemberWriteModel(userID string) *IAMMemberWriteModel {
|
|
return &IAMMemberWriteModel{
|
|
MemberWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: domain.IAMID,
|
|
ResourceOwner: domain.IAMID,
|
|
},
|
|
UserID: userID,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *IAMMemberWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *iam.MemberAddedEvent:
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
continue
|
|
}
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberAddedEvent)
|
|
case *iam.MemberChangedEvent:
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
continue
|
|
}
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberChangedEvent)
|
|
case *iam.MemberRemovedEvent:
|
|
if e.UserID != wm.MemberWriteModel.UserID {
|
|
continue
|
|
}
|
|
wm.MemberWriteModel.AppendEvents(&e.MemberRemovedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *IAMMemberWriteModel) Reduce() error {
|
|
return wm.MemberWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *IAMMemberWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, iam.AggregateType).
|
|
AggregateIDs(wm.MemberWriteModel.AggregateID).ResourceOwner(wm.ResourceOwner)
|
|
}
|