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/policy"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
type PolicyDomainWriteModel struct {
|
2021-01-04 13:52:13 +00:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
UserLoginMustBeDomain bool
|
2021-01-07 15:06:45 +00:00
|
|
|
State domain.PolicyState
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 16:21:34 +00:00
|
|
|
func (wm *PolicyDomainWriteModel) Reduce() error {
|
2021-01-04 13:52:13 +00:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2022-03-24 16:21:34 +00:00
|
|
|
case *policy.DomainPolicyAddedEvent:
|
2021-01-04 13:52:13 +00:00
|
|
|
wm.UserLoginMustBeDomain = e.UserLoginMustBeDomain
|
2021-01-07 15:06:45 +00:00
|
|
|
wm.State = domain.PolicyStateActive
|
2022-03-24 16:21:34 +00:00
|
|
|
case *policy.DomainPolicyChangedEvent:
|
2021-01-06 10:12:56 +00:00
|
|
|
if e.UserLoginMustBeDomain != nil {
|
|
|
|
wm.UserLoginMustBeDomain = *e.UserLoginMustBeDomain
|
|
|
|
}
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|