2021-01-04 13:52:13 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
2021-01-07 15:06:45 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
2021-01-04 13:52:13 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/repository/policy"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PolicyOrgIAMWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
UserLoginMustBeDomain bool
|
2021-01-07 15:06:45 +00:00
|
|
|
State domain.PolicyState
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *PolicyOrgIAMWriteModel) Reduce() error {
|
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *policy.OrgIAMPolicyAddedEvent:
|
|
|
|
wm.UserLoginMustBeDomain = e.UserLoginMustBeDomain
|
2021-01-07 15:06:45 +00:00
|
|
|
wm.State = domain.PolicyStateActive
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.OrgIAMPolicyChangedEvent:
|
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()
|
|
|
|
}
|