2021-07-05 10:36:51 +02: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-07-05 10:36:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type PrivacyPolicyWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
2023-03-28 21:36:52 +02:00
|
|
|
TOSLink string
|
|
|
|
PrivacyLink string
|
|
|
|
HelpLink string
|
|
|
|
SupportEmail domain.EmailAddress
|
|
|
|
State domain.PolicyState
|
2021-07-05 10:36:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 14:00:24 +01:00
|
|
|
wm.HelpLink = e.HelpLink
|
2023-03-28 21:36:52 +02:00
|
|
|
wm.SupportEmail = e.SupportEmail
|
2021-07-05 10:36:51 +02: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 14:00:24 +01:00
|
|
|
if e.HelpLink != nil {
|
|
|
|
wm.HelpLink = *e.HelpLink
|
|
|
|
}
|
2023-03-28 21:36:52 +02:00
|
|
|
if e.SupportEmail != nil {
|
|
|
|
wm.SupportEmail = *e.SupportEmail
|
|
|
|
}
|
2021-07-05 10:36:51 +02:00
|
|
|
case *policy.PrivacyPolicyRemovedEvent:
|
|
|
|
wm.State = domain.PolicyStateRemoved
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|