2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/iam"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type IAMWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
SetUpStarted domain.Step
|
|
|
|
SetUpDone domain.Step
|
|
|
|
|
|
|
|
GlobalOrgID string
|
|
|
|
ProjectID string
|
|
|
|
}
|
|
|
|
|
2021-01-12 11:59:51 +00:00
|
|
|
func NewIAMWriteModel() *IAMWriteModel {
|
2021-01-04 13:52:13 +00:00
|
|
|
return &IAMWriteModel{
|
|
|
|
WriteModel: eventstore.WriteModel{
|
2021-01-12 11:59:51 +00:00
|
|
|
AggregateID: domain.IAMID,
|
|
|
|
ResourceOwner: domain.IAMID,
|
2021-01-04 13:52:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *IAMWriteModel) Reduce() error {
|
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *iam.ProjectSetEvent:
|
|
|
|
wm.ProjectID = e.ProjectID
|
|
|
|
case *iam.GlobalOrgSetEvent:
|
|
|
|
wm.GlobalOrgID = e.OrgID
|
|
|
|
case *iam.SetupStepEvent:
|
|
|
|
if e.Done {
|
|
|
|
wm.SetUpDone = e.Step
|
|
|
|
} else {
|
|
|
|
wm.SetUpStarted = e.Step
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *IAMWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, iam.AggregateType).
|
2021-01-12 11:59:51 +00:00
|
|
|
AggregateIDs(wm.AggregateID).
|
2021-02-18 13:48:27 +00:00
|
|
|
ResourceOwner(wm.ResourceOwner).
|
|
|
|
EventTypes(
|
|
|
|
iam.ProjectSetEventType,
|
|
|
|
iam.GlobalOrgSetEventType,
|
|
|
|
iam.SetupStartedEventType,
|
|
|
|
iam.SetupDoneEventType)
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 13:48:27 +00:00
|
|
|
func IAMAggregateFromWriteModel(wm *eventstore.WriteModel) *eventstore.Aggregate {
|
|
|
|
return eventstore.AggregateFromWriteModel(wm, iam.AggregateType, iam.AggregateVersion)
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|