mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 10:45:12 +00:00
feat: add Help/Support e-mail for instance/org (#5445)
feat: help and support email in privacy policy
This commit is contained in:
@@ -1093,6 +1093,10 @@ func (c *Commands) createFooterTextEvents(ctx context.Context, agg *eventstore.A
|
||||
if event != nil {
|
||||
events = append(events, event)
|
||||
}
|
||||
event = c.createCustomLoginTextEvent(ctx, agg, domain.LoginKeyFooterSupportEmail, existingText.FooterSupportEmail, text.Footer.SupportEmail, text.Language, defaultText)
|
||||
if event != nil {
|
||||
events = append(events, event)
|
||||
}
|
||||
return events
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ type CustomLoginTextReadModel struct {
|
||||
FooterTOS string
|
||||
FooterPrivacyPolicy string
|
||||
FooterHelp string
|
||||
FooterHelpLink string
|
||||
FooterSupportEmail string
|
||||
}
|
||||
|
||||
func (wm *CustomLoginTextReadModel) Reduce() error {
|
||||
@@ -2515,6 +2515,10 @@ func (wm *CustomLoginTextReadModel) handleFooterTextSetEvent(e *policy.CustomTex
|
||||
wm.FooterHelp = e.Text
|
||||
return
|
||||
}
|
||||
if e.Key == domain.LoginKeyFooterSupportEmail {
|
||||
wm.FooterSupportEmail = e.Text
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *CustomLoginTextReadModel) handleFooterTextRemoveEvent(e *policy.CustomTextRemovedEvent) {
|
||||
@@ -2530,4 +2534,8 @@ func (wm *CustomLoginTextReadModel) handleFooterTextRemoveEvent(e *policy.Custom
|
||||
wm.FooterHelp = ""
|
||||
return
|
||||
}
|
||||
if e.Key == domain.LoginKeyFooterSupportEmail {
|
||||
wm.FooterSupportEmail = ""
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +87,10 @@ type InstanceSetup struct {
|
||||
PasswordChange bool
|
||||
}
|
||||
PrivacyPolicy struct {
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
SupportEmail domain.EmailAddress
|
||||
}
|
||||
LabelPolicy struct {
|
||||
PrimaryColor string
|
||||
@@ -242,7 +243,7 @@ func (c *Commands) SetUpInstance(ctx context.Context, setup *InstanceSetup) (str
|
||||
prepareAddSecondFactorToDefaultLoginPolicy(instanceAgg, domain.SecondFactorTypeU2F),
|
||||
prepareAddMultiFactorToDefaultLoginPolicy(instanceAgg, domain.MultiFactorTypeU2FWithPIN),
|
||||
|
||||
prepareAddDefaultPrivacyPolicy(instanceAgg, setup.PrivacyPolicy.TOSLink, setup.PrivacyPolicy.PrivacyLink, setup.PrivacyPolicy.HelpLink),
|
||||
prepareAddDefaultPrivacyPolicy(instanceAgg, setup.PrivacyPolicy.TOSLink, setup.PrivacyPolicy.PrivacyLink, setup.PrivacyPolicy.HelpLink, setup.PrivacyPolicy.SupportEmail),
|
||||
prepareAddDefaultNotificationPolicy(instanceAgg, setup.NotificationPolicy.PasswordChange),
|
||||
prepareAddDefaultLockoutPolicy(instanceAgg, setup.LockoutPolicy.MaxAttempts, setup.LockoutPolicy.ShouldShowLockoutFailure),
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ func writeModelToPrivacyPolicy(wm *PrivacyPolicyWriteModel) *domain.PrivacyPolic
|
||||
TOSLink: wm.TOSLink,
|
||||
PrivacyLink: wm.PrivacyLink,
|
||||
HelpLink: wm.HelpLink,
|
||||
SupportEmail: wm.SupportEmail,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ func (c *Commands) setCustomInstanceLoginText(ctx context.Context, instanceAgg *
|
||||
if !text.IsValid() {
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "Instance-kd9fs", "Errors.CustomText.Invalid")
|
||||
}
|
||||
|
||||
existingLoginText, err := c.defaultLoginTextWriteModelByID(ctx, text.Language)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -1370,6 +1370,12 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -1664,6 +1670,7 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
TOS: "TOS",
|
||||
PrivacyPolicy: "PrivacyPolicy",
|
||||
Help: "Help",
|
||||
SupportEmail: "Support Email",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2993,6 +3000,12 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
@@ -4310,6 +4323,12 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, language.English,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -5681,6 +5700,12 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextRemovedEvent(context.Background(),
|
||||
@@ -6996,6 +7021,12 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextRemovedEvent(context.Background(),
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, language.English,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
@@ -8313,6 +8344,12 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusherWithInstanceID(
|
||||
"INSTANCE",
|
||||
instance.NewCustomTextSetEvent(context.Background(),
|
||||
&instance.NewAggregate("INSTANCE").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -8607,6 +8644,7 @@ func TestCommandSide_SetCustomIAMLoginText(t *testing.T) {
|
||||
TOS: "TOS",
|
||||
PrivacyPolicy: "PrivacyPolicy",
|
||||
Help: "Help",
|
||||
SupportEmail: "Support Email",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, tosLink, privacyLink, helpLink string) (*domain.ObjectDetails, error) {
|
||||
func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, tosLink, privacyLink, helpLink string, supportEmail domain.EmailAddress) (*domain.ObjectDetails, error) {
|
||||
instanceAgg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
|
||||
cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, prepareAddDefaultPrivacyPolicy(instanceAgg, tosLink, privacyLink, helpLink))
|
||||
cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, prepareAddDefaultPrivacyPolicy(instanceAgg, tosLink, privacyLink, helpLink, supportEmail))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -26,6 +26,13 @@ func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, tosLink, privacy
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultPrivacyPolicy(ctx context.Context, policy *domain.PrivacyPolicy) (*domain.PrivacyPolicy, error) {
|
||||
if policy.SupportEmail != "" {
|
||||
if err := policy.SupportEmail.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policy.SupportEmail = policy.SupportEmail.Normalize()
|
||||
}
|
||||
|
||||
existingPolicy, err := c.defaultPrivacyPolicyWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -35,7 +42,7 @@ func (c *Commands) ChangeDefaultPrivacyPolicy(ctx context.Context, policy *domai
|
||||
}
|
||||
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&existingPolicy.PrivacyPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink, policy.SupportEmail)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "INSTANCE-9jJfs", "Errors.IAM.PrivacyPolicy.NotChanged")
|
||||
}
|
||||
@@ -81,8 +88,15 @@ func prepareAddDefaultPrivacyPolicy(
|
||||
tosLink,
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
supportEmail domain.EmailAddress,
|
||||
) preparation.Validation {
|
||||
return func() (preparation.CreateCommands, error) {
|
||||
if supportEmail != "" {
|
||||
if err := supportEmail.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
supportEmail = supportEmail.Normalize()
|
||||
}
|
||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||
writeModel := NewInstancePrivacyPolicyWriteModel(ctx)
|
||||
events, err := filter(ctx, writeModel.Query())
|
||||
@@ -97,7 +111,7 @@ func prepareAddDefaultPrivacyPolicy(
|
||||
return nil, caos_errs.ThrowAlreadyExists(nil, "INSTANCE-M00rJ", "Errors.Instance.PrivacyPolicy.AlreadyExists")
|
||||
}
|
||||
return []eventstore.Command{
|
||||
instance.NewPrivacyPolicyAddedEvent(ctx, &a.Aggregate, tosLink, privacyLink, helpLink),
|
||||
instance.NewPrivacyPolicyAddedEvent(ctx, &a.Aggregate, tosLink, privacyLink, helpLink, supportEmail),
|
||||
}, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -57,6 +58,7 @@ func (wm *InstancePrivacyPolicyWriteModel) NewChangedEvent(
|
||||
tosLink,
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
supportEmail domain.EmailAddress,
|
||||
) (*instance.PrivacyPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.PrivacyPolicyChanges, 0)
|
||||
@@ -69,6 +71,9 @@ func (wm *InstancePrivacyPolicyWriteModel) NewChangedEvent(
|
||||
if wm.HelpLink != helpLink {
|
||||
changes = append(changes, policy.ChangeHelpLink(helpLink))
|
||||
}
|
||||
if wm.SupportEmail != supportEmail {
|
||||
changes = append(changes, policy.ChangeSupportEmail(supportEmail))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
eventstore *eventstore.Eventstore
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
tosLink string
|
||||
privacyLink string
|
||||
helpLink string
|
||||
ctx context.Context
|
||||
tosLink string
|
||||
privacyLink string
|
||||
helpLink string
|
||||
supportEmail domain.EmailAddress
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -49,16 +50,18 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
ctx: context.Background(),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "[email protected]",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorAlreadyExists,
|
||||
@@ -79,6 +82,7 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -86,10 +90,11 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "[email protected]",
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -97,6 +102,24 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wrong email, can't add policy",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "wrong email",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add empty policy,ok",
|
||||
fields: fields{
|
||||
@@ -112,6 +135,7 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -119,10 +143,11 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "",
|
||||
privacyLink: "",
|
||||
helpLink: "",
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "",
|
||||
privacyLink: "",
|
||||
helpLink: "",
|
||||
supportEmail: "",
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -136,7 +161,7 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
}
|
||||
got, err := r.AddDefaultPrivacyPolicy(tt.args.ctx, tt.args.tosLink, tt.args.privacyLink, tt.args.helpLink)
|
||||
got, err := r.AddDefaultPrivacyPolicy(tt.args.ctx, tt.args.tosLink, tt.args.privacyLink, tt.args.helpLink, tt.args.supportEmail)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -179,9 +204,10 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -200,6 +226,7 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -208,15 +235,36 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wrong email, can't change policy",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "wrong email",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "change, ok",
|
||||
fields: fields{
|
||||
@@ -229,6 +277,7 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -239,6 +288,7 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
"TOSLinkChanged",
|
||||
"PrivacyLinkChanged",
|
||||
"HelpLinkChanged",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -248,9 +298,10 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -259,9 +310,10 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "INSTANCE",
|
||||
ResourceOwner: "INSTANCE",
|
||||
},
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -285,13 +337,14 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLink, helpLink string) *instance.PrivacyPolicyChangedEvent {
|
||||
func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLink, helpLink, supportEmail string) *instance.PrivacyPolicyChangedEvent {
|
||||
event, _ := instance.NewPrivacyPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate("INSTANCE").Aggregate,
|
||||
[]policy.PrivacyPolicyChanges{
|
||||
policy.ChangeTOSLink(tosLink),
|
||||
policy.ChangePrivacyLink(privacyLink),
|
||||
policy.ChangeHelpLink(helpLink),
|
||||
policy.ChangeSupportEmail(domain.EmailAddress(supportEmail)),
|
||||
},
|
||||
)
|
||||
return event
|
||||
|
||||
@@ -50,5 +50,6 @@ func orgWriteModelToPrivacyPolicy(wm *OrgPrivacyPolicyWriteModel) *domain.Privac
|
||||
TOSLink: wm.TOSLink,
|
||||
PrivacyLink: wm.PrivacyLink,
|
||||
HelpLink: wm.HelpLink,
|
||||
SupportEmail: wm.SupportEmail,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1161,6 +1161,11 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextSetEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -1455,6 +1460,7 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
TOS: "TOS",
|
||||
PrivacyPolicy: "PrivacyPolicy",
|
||||
Help: "Help",
|
||||
SupportEmail: "Support Email",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2560,6 +2566,11 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextSetEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
@@ -3653,6 +3664,11 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, language.English,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -4800,6 +4816,11 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextSetEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeySelectAccountTitle, language.English,
|
||||
@@ -5890,6 +5911,11 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextRemovedEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, language.English,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
@@ -6983,6 +7009,11 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterHelp, "Help", language.English,
|
||||
),
|
||||
),
|
||||
eventFromEventPusher(
|
||||
org.NewCustomTextSetEvent(context.Background(),
|
||||
&org.NewAggregate("org1").Aggregate, domain.LoginCustomText, domain.LoginKeyFooterSupportEmail, "Support Email", language.English,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -7277,6 +7308,7 @@ func TestCommandSide_SetCustomOrgLoginText(t *testing.T) {
|
||||
TOS: "TOS",
|
||||
PrivacyPolicy: "PrivacyPolicy",
|
||||
Help: "Help",
|
||||
SupportEmail: "Support Email",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -29,6 +29,14 @@ func (c *Commands) orgPrivacyPolicyWriteModelByID(ctx context.Context, orgID str
|
||||
}
|
||||
|
||||
func (c *Commands) AddPrivacyPolicy(ctx context.Context, resourceOwner string, policy *domain.PrivacyPolicy) (*domain.PrivacyPolicy, error) {
|
||||
|
||||
if policy.SupportEmail != "" {
|
||||
if err := policy.SupportEmail.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policy.SupportEmail = policy.SupportEmail.Normalize()
|
||||
}
|
||||
|
||||
if resourceOwner == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "Org-MMk9fs", "Errors.ResourceOwnerMissing")
|
||||
}
|
||||
@@ -49,7 +57,8 @@ func (c *Commands) AddPrivacyPolicy(ctx context.Context, resourceOwner string, p
|
||||
orgAgg,
|
||||
policy.TOSLink,
|
||||
policy.PrivacyLink,
|
||||
policy.HelpLink))
|
||||
policy.HelpLink,
|
||||
policy.SupportEmail))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,12 +70,19 @@ func (c *Commands) AddPrivacyPolicy(ctx context.Context, resourceOwner string, p
|
||||
}
|
||||
|
||||
func (c *Commands) ChangePrivacyPolicy(ctx context.Context, resourceOwner string, policy *domain.PrivacyPolicy) (*domain.PrivacyPolicy, error) {
|
||||
|
||||
if policy.SupportEmail != "" {
|
||||
if err := policy.SupportEmail.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policy.SupportEmail = policy.SupportEmail.Normalize()
|
||||
}
|
||||
|
||||
if resourceOwner == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "Org-22N89f", "Errors.ResourceOwnerMissing")
|
||||
}
|
||||
|
||||
existingPolicy := NewOrgPrivacyPolicyWriteModel(resourceOwner)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, existingPolicy)
|
||||
existingPolicy, err := c.orgPrivacyPolicyWriteModelByID(ctx, resourceOwner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -75,7 +91,7 @@ func (c *Commands) ChangePrivacyPolicy(ctx context.Context, resourceOwner string
|
||||
}
|
||||
|
||||
orgAgg := OrgAggregateFromWriteModel(&existingPolicy.PrivacyPolicyWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, orgAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, orgAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink, policy.SupportEmail)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "Org-4N9fs", "Errors.Org.PrivacyPolicy.NotChanged")
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package command
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
)
|
||||
@@ -59,6 +59,7 @@ func (wm *OrgPrivacyPolicyWriteModel) NewChangedEvent(
|
||||
tosLink,
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
supportEmail domain.EmailAddress,
|
||||
) (*org.PrivacyPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.PrivacyPolicyChanges, 0)
|
||||
@@ -71,6 +72,9 @@ func (wm *OrgPrivacyPolicyWriteModel) NewChangedEvent(
|
||||
if wm.HelpLink != helpLink {
|
||||
changes = append(changes, policy.ChangeHelpLink(helpLink))
|
||||
}
|
||||
if wm.SupportEmail != supportEmail {
|
||||
changes = append(changes, policy.ChangeSupportEmail(supportEmail))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -44,9 +44,10 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -65,6 +66,7 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -74,9 +76,10 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -97,6 +100,7 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -107,9 +111,10 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -118,14 +123,36 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add policy empty links, ok",
|
||||
name: "wrong email, can't add policy",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "wrong email",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add policy empty links and empty support email, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
@@ -138,6 +165,7 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -148,9 +176,10 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -159,9 +188,10 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -214,9 +244,10 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -235,9 +266,10 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -256,6 +288,7 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -265,15 +298,32 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsPreconditionFailed,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wrong email, can't change policy",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "wrong email",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "change, ok",
|
||||
fields: fields{
|
||||
@@ -286,13 +336,14 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "TOSLinkChange", "PrivacyLinkChange", "HelpLinkChange"),
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "TOSLinkChange", "PrivacyLinkChange", "HelpLinkChange", "[email protected]"),
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -302,9 +353,10 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -313,9 +365,10 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "[email protected]",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -331,13 +384,14 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
[]*repository.Event{
|
||||
eventFromEventPusher(
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "", "", ""),
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "", "", "", ""),
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -347,9 +401,10 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -358,9 +413,10 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -444,6 +500,7 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
|
||||
"TOSLink",
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"[email protected]",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -487,13 +544,14 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, privacyLink, helpLink string) *org.PrivacyPolicyChangedEvent {
|
||||
func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, privacyLink, helpLink, supportEmail string) *org.PrivacyPolicyChangedEvent {
|
||||
event, _ := org.NewPrivacyPolicyChangedEvent(ctx,
|
||||
&org.NewAggregate(orgID).Aggregate,
|
||||
[]policy.PrivacyPolicyChanges{
|
||||
policy.ChangeTOSLink(tosLink),
|
||||
policy.ChangePrivacyLink(privacyLink),
|
||||
policy.ChangeHelpLink(helpLink),
|
||||
policy.ChangeSupportEmail(domain.EmailAddress(supportEmail)),
|
||||
},
|
||||
)
|
||||
return event
|
||||
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
type PrivacyPolicyWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
State domain.PolicyState
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
SupportEmail domain.EmailAddress
|
||||
State domain.PolicyState
|
||||
}
|
||||
|
||||
func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
||||
@@ -22,6 +23,7 @@ func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
||||
wm.TOSLink = e.TOSLink
|
||||
wm.PrivacyLink = e.PrivacyLink
|
||||
wm.HelpLink = e.HelpLink
|
||||
wm.SupportEmail = e.SupportEmail
|
||||
wm.State = domain.PolicyStateActive
|
||||
case *policy.PrivacyPolicyChangedEvent:
|
||||
if e.PrivacyLink != nil {
|
||||
@@ -33,6 +35,9 @@ func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
||||
if e.HelpLink != nil {
|
||||
wm.HelpLink = *e.HelpLink
|
||||
}
|
||||
if e.SupportEmail != nil {
|
||||
wm.SupportEmail = *e.SupportEmail
|
||||
}
|
||||
case *policy.PrivacyPolicyRemovedEvent:
|
||||
wm.State = domain.PolicyStateRemoved
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user