mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 03:54:21 +00:00
61d16e4621
* add setup steps * refactoring * omitempty * cleanup * fixes
78 lines
1.9 KiB
Go
78 lines
1.9 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 IAMWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
SetUpStarted domain.Step
|
|
SetUpDone domain.Step
|
|
|
|
GlobalOrgID string
|
|
ProjectID string
|
|
}
|
|
|
|
func NewIAMWriteModel(iamID string) *IAMWriteModel {
|
|
return &IAMWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: iamID,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *IAMWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
wm.WriteModel.AppendEvents(events...)
|
|
//for _, event := range events {
|
|
// switch e := event.(type) {
|
|
// case *iam.LabelPolicyAddedEvent:
|
|
// wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyAddedEvent)
|
|
// case *iam.LabelPolicyChangedEvent:
|
|
// wm.LabelPolicyWriteModel.AppendEvents(&e.LabelPolicyChangedEvent)
|
|
// }
|
|
//}
|
|
}
|
|
|
|
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).
|
|
AggregateIDs(wm.AggregateID)
|
|
}
|
|
|
|
//
|
|
//func (wm *IAMLabelPolicyWriteModel) HasChanged(primaryColor, secondaryColor string) bool {
|
|
// if primaryColor != "" && wm.PrimaryColor != primaryColor {
|
|
// return true
|
|
// }
|
|
// if secondaryColor != "" && wm.SecondaryColor != secondaryColor {
|
|
// return true
|
|
// }
|
|
// return false
|
|
//}
|
|
|
|
func IAMAggregateFromWriteModel(wm *eventstore.WriteModel) *iam.Aggregate {
|
|
return &iam.Aggregate{
|
|
Aggregate: *eventstore.AggregateFromWriteModel(wm, iam.AggregateType, iam.AggregateVersion),
|
|
}
|
|
}
|