2021-07-05 08:36:51 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PrivacyPolicyWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
|
|
|
TOSLink string
|
|
|
|
PrivacyLink string
|
2022-03-24 13:00:24 +00:00
|
|
|
HelpLink string
|
2021-07-05 08:36:51 +00:00
|
|
|
State domain.PolicyState
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
|
|
|
for _, event := range wm.Events {
|
|
|
|
switch e := event.(type) {
|
|
|
|
case *policy.PrivacyPolicyAddedEvent:
|
|
|
|
wm.TOSLink = e.TOSLink
|
|
|
|
wm.PrivacyLink = e.PrivacyLink
|
2022-03-24 13:00:24 +00:00
|
|
|
wm.HelpLink = e.HelpLink
|
2021-07-05 08:36:51 +00:00
|
|
|
wm.State = domain.PolicyStateActive
|
|
|
|
case *policy.PrivacyPolicyChangedEvent:
|
|
|
|
if e.PrivacyLink != nil {
|
|
|
|
wm.PrivacyLink = *e.PrivacyLink
|
|
|
|
}
|
|
|
|
if e.TOSLink != nil {
|
|
|
|
wm.TOSLink = *e.TOSLink
|
|
|
|
}
|
2022-03-24 13:00:24 +00:00
|
|
|
if e.HelpLink != nil {
|
|
|
|
wm.HelpLink = *e.HelpLink
|
|
|
|
}
|
2021-07-05 08:36:51 +00:00
|
|
|
case *policy.PrivacyPolicyRemovedEvent:
|
|
|
|
wm.State = domain.PolicyStateRemoved
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|