2021-01-04 14:52:13 +01:00
|
|
|
package command
|
2020-12-11 15:49:19 +01:00
|
|
|
|
|
|
|
import (
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2020-12-11 15:49:19 +01:00
|
|
|
)
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
type LabelPolicyWriteModel struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
2021-03-25 14:41:07 +01:00
|
|
|
PrimaryColor string
|
|
|
|
SecondaryColor string
|
|
|
|
HideLoginNameSuffix bool
|
2021-01-07 16:06:45 +01:00
|
|
|
|
|
|
|
State domain.PolicyState
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
func (wm *LabelPolicyWriteModel) Reduce() error {
|
2020-12-11 15:49:19 +01:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.LabelPolicyAddedEvent:
|
2020-12-11 15:49:19 +01:00
|
|
|
wm.PrimaryColor = e.PrimaryColor
|
|
|
|
wm.SecondaryColor = e.SecondaryColor
|
2021-03-25 14:41:07 +01:00
|
|
|
wm.HideLoginNameSuffix = e.HideLoginNameSuffix
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateActive
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.LabelPolicyChangedEvent:
|
2021-01-06 11:12:56 +01:00
|
|
|
if e.PrimaryColor != nil {
|
|
|
|
wm.PrimaryColor = *e.PrimaryColor
|
|
|
|
}
|
|
|
|
if e.SecondaryColor != nil {
|
|
|
|
wm.SecondaryColor = *e.SecondaryColor
|
|
|
|
}
|
2021-03-25 14:41:07 +01:00
|
|
|
if e.HideLoginNameSuffix != nil {
|
|
|
|
wm.HideLoginNameSuffix = *e.HideLoginNameSuffix
|
|
|
|
}
|
2021-01-04 14:52:13 +01:00
|
|
|
case *policy.LabelPolicyRemovedEvent:
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateRemoved
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|