2021-01-04 14:52:13 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2021-01-04 14:52:13 +01:00
|
|
|
)
|
|
|
|
|
2022-03-24 17:21:34 +01:00
|
|
|
type PolicyDomainWriteModel struct {
|
2021-01-04 14:52:13 +01:00
|
|
|
eventstore.WriteModel
|
|
|
|
|
2022-05-16 16:08:47 +02:00
|
|
|
UserLoginMustBeDomain bool
|
|
|
|
ValidateOrgDomains bool
|
|
|
|
SMTPSenderAddressMatchesInstanceDomain bool
|
|
|
|
State domain.PolicyState
|
2021-01-04 14:52:13 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 17:21:34 +01:00
|
|
|
func (wm *PolicyDomainWriteModel) Reduce() error {
|
2021-01-04 14:52:13 +01:00
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
2022-03-24 17:21:34 +01:00
|
|
|
case *policy.DomainPolicyAddedEvent:
|
2021-01-04 14:52:13 +01:00
|
|
|
wm.UserLoginMustBeDomain = e.UserLoginMustBeDomain
|
2022-04-13 11:24:03 +02:00
|
|
|
wm.ValidateOrgDomains = e.ValidateOrgDomains
|
2022-05-16 16:08:47 +02:00
|
|
|
wm.SMTPSenderAddressMatchesInstanceDomain = e.SMTPSenderAddressMatchesInstanceDomain
|
2021-01-07 16:06:45 +01:00
|
|
|
wm.State = domain.PolicyStateActive
|
2022-03-24 17:21:34 +01:00
|
|
|
case *policy.DomainPolicyChangedEvent:
|
2021-01-06 11:12:56 +01:00
|
|
|
if e.UserLoginMustBeDomain != nil {
|
|
|
|
wm.UserLoginMustBeDomain = *e.UserLoginMustBeDomain
|
|
|
|
}
|
2022-04-13 11:24:03 +02:00
|
|
|
if e.ValidateOrgDomains != nil {
|
|
|
|
wm.ValidateOrgDomains = *e.ValidateOrgDomains
|
|
|
|
}
|
2022-05-16 16:08:47 +02:00
|
|
|
if e.SMTPSenderAddressMatchesInstanceDomain != nil {
|
|
|
|
wm.SMTPSenderAddressMatchesInstanceDomain = *e.SMTPSenderAddressMatchesInstanceDomain
|
|
|
|
}
|
2022-07-21 13:46:59 +02:00
|
|
|
case *policy.DomainPolicyRemovedEvent:
|
|
|
|
wm.State = domain.PolicyStateRemoved
|
2021-01-04 14:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|