2021-07-05 08:36:51 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/policy"
|
2021-07-05 08:36:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PrivacyPolicyWriteModel struct {
|
|
|
|
eventstore.WriteModel
|
|
|
|
|
2024-05-13 14:01:50 +00:00
|
|
|
TOSLink string
|
|
|
|
PrivacyLink string
|
|
|
|
HelpLink string
|
|
|
|
SupportEmail domain.EmailAddress
|
|
|
|
State domain.PolicyState
|
|
|
|
DocsLink string
|
|
|
|
CustomLink string
|
|
|
|
CustomLinkText string
|
2021-07-05 08:36:51 +00: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 13:00:24 +00:00
|
|
|
wm.HelpLink = e.HelpLink
|
2023-03-28 19:36:52 +00:00
|
|
|
wm.SupportEmail = e.SupportEmail
|
2021-07-05 08:36:51 +00:00
|
|
|
wm.State = domain.PolicyStateActive
|
2024-05-13 14:01:50 +00:00
|
|
|
wm.DocsLink = e.DocsLink
|
|
|
|
wm.CustomLink = e.CustomLink
|
|
|
|
wm.CustomLinkText = e.CustomLinkText
|
2021-07-05 08:36:51 +00:00
|
|
|
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
|
|
|
|
}
|
2023-03-28 19:36:52 +00:00
|
|
|
if e.SupportEmail != nil {
|
|
|
|
wm.SupportEmail = *e.SupportEmail
|
|
|
|
}
|
2024-05-13 14:01:50 +00:00
|
|
|
if e.DocsLink != nil {
|
|
|
|
wm.DocsLink = *e.DocsLink
|
|
|
|
}
|
|
|
|
if e.CustomLink != nil {
|
|
|
|
wm.CustomLink = *e.CustomLink
|
|
|
|
}
|
|
|
|
if e.CustomLinkText != nil {
|
|
|
|
wm.CustomLinkText = *e.CustomLinkText
|
|
|
|
}
|
2021-07-05 08:36:51 +00:00
|
|
|
case *policy.PrivacyPolicyRemovedEvent:
|
|
|
|
wm.State = domain.PolicyStateRemoved
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wm.WriteModel.Reduce()
|
|
|
|
}
|