2021-07-05 08:36:51 +00:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
2023-03-28 19:36:52 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-07-05 08:36:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
PrivacyPolicyAddedEventType = "policy.privacy.added"
|
|
|
|
PrivacyPolicyChangedEventType = "policy.privacy.changed"
|
|
|
|
PrivacyPolicyRemovedEventType = "policy.privacy.removed"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PrivacyPolicyAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-03-28 19:36:52 +00:00
|
|
|
TOSLink string `json:"tosLink,omitempty"`
|
|
|
|
PrivacyLink string `json:"privacyLink,omitempty"`
|
|
|
|
HelpLink string `json:"helpLink,omitempty"`
|
|
|
|
SupportEmail domain.EmailAddress `json:"supportEmail,omitempty"`
|
2021-07-05 08:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PrivacyPolicyAddedEvent) Payload() interface{} {
|
2021-07-05 08:36:51 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PrivacyPolicyAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-07-05 08:36:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrivacyPolicyAddedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
tosLink,
|
2022-03-24 13:00:24 +00:00
|
|
|
privacyLink,
|
|
|
|
helpLink string,
|
2023-03-28 19:36:52 +00:00
|
|
|
supportEmail domain.EmailAddress,
|
2021-07-05 08:36:51 +00:00
|
|
|
) *PrivacyPolicyAddedEvent {
|
|
|
|
return &PrivacyPolicyAddedEvent{
|
2023-03-28 19:36:52 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
TOSLink: tosLink,
|
|
|
|
PrivacyLink: privacyLink,
|
|
|
|
HelpLink: helpLink,
|
|
|
|
SupportEmail: supportEmail,
|
2021-07-05 08:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func PrivacyPolicyAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-07-05 08:36:51 +00:00
|
|
|
e := &PrivacyPolicyAddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2021-07-05 08:36:51 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "POLIC-2k0fs", "unable to unmarshal policy")
|
2021-07-05 08:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrivacyPolicyChangedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-03-28 19:36:52 +00:00
|
|
|
TOSLink *string `json:"tosLink,omitempty"`
|
|
|
|
PrivacyLink *string `json:"privacyLink,omitempty"`
|
|
|
|
HelpLink *string `json:"helpLink,omitempty"`
|
|
|
|
SupportEmail *domain.EmailAddress `json:"supportEmail,omitempty"`
|
2021-07-05 08:36:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PrivacyPolicyChangedEvent) Payload() interface{} {
|
2021-07-05 08:36:51 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PrivacyPolicyChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-07-05 08:36:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrivacyPolicyChangedEvent(
|
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
changes []PrivacyPolicyChanges,
|
|
|
|
) (*PrivacyPolicyChangedEvent, error) {
|
|
|
|
if len(changes) == 0 {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "POLICY-PPo0s", "Errors.NoChangesFound")
|
2021-07-05 08:36:51 +00:00
|
|
|
}
|
|
|
|
changeEvent := &PrivacyPolicyChangedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
for _, change := range changes {
|
|
|
|
change(changeEvent)
|
|
|
|
}
|
|
|
|
return changeEvent, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrivacyPolicyChanges func(*PrivacyPolicyChangedEvent)
|
|
|
|
|
|
|
|
func ChangeTOSLink(tosLink string) func(*PrivacyPolicyChangedEvent) {
|
|
|
|
return func(e *PrivacyPolicyChangedEvent) {
|
|
|
|
e.TOSLink = &tosLink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ChangePrivacyLink(privacyLink string) func(*PrivacyPolicyChangedEvent) {
|
|
|
|
return func(e *PrivacyPolicyChangedEvent) {
|
|
|
|
e.PrivacyLink = &privacyLink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 13:00:24 +00:00
|
|
|
func ChangeHelpLink(helpLink string) func(*PrivacyPolicyChangedEvent) {
|
|
|
|
return func(e *PrivacyPolicyChangedEvent) {
|
|
|
|
e.HelpLink = &helpLink
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-28 19:36:52 +00:00
|
|
|
func ChangeSupportEmail(supportEmail domain.EmailAddress) func(*PrivacyPolicyChangedEvent) {
|
|
|
|
return func(e *PrivacyPolicyChangedEvent) {
|
|
|
|
e.SupportEmail = &supportEmail
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func PrivacyPolicyChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-07-05 08:36:51 +00:00
|
|
|
e := &PrivacyPolicyChangedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(e)
|
2021-07-05 08:36:51 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "POLIC-22nf9", "unable to unmarshal policy")
|
2021-07-05 08:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrivacyPolicyRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PrivacyPolicyRemovedEvent) Payload() interface{} {
|
2021-07-05 08:36:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PrivacyPolicyRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2021-07-05 08:36:51 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrivacyPolicyRemovedEvent(base *eventstore.BaseEvent) *PrivacyPolicyRemovedEvent {
|
|
|
|
return &PrivacyPolicyRemovedEvent{
|
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func PrivacyPolicyRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2021-07-05 08:36:51 +00:00
|
|
|
return &PrivacyPolicyRemovedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|