mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-01 15:53:42 +00:00
feat(cnsl): docs link can be customized and custom button is available (#7840)
* feat: customize doc link and additional custom link * feat: add e2e tests * fix: update docs * fix: add @peintnermax changes about cache * fix: golangci-lint complains preparation.PrepareCommands --------- Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
@@ -81,10 +81,13 @@ type InstanceSetup struct {
|
||||
PasswordChange bool
|
||||
}
|
||||
PrivacyPolicy struct {
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
SupportEmail domain.EmailAddress
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
SupportEmail domain.EmailAddress
|
||||
DocsLink string
|
||||
CustomLink string
|
||||
CustomLinkText string
|
||||
}
|
||||
LabelPolicy struct {
|
||||
PrimaryColor string
|
||||
@@ -270,7 +273,7 @@ func (c *Commands) SetUpInstance(ctx context.Context, setup *InstanceSetup) (str
|
||||
*/
|
||||
prepareAddMultiFactorToDefaultLoginPolicy(instanceAgg, domain.MultiFactorTypeU2FWithPIN),
|
||||
|
||||
prepareAddDefaultPrivacyPolicy(instanceAgg, setup.PrivacyPolicy.TOSLink, setup.PrivacyPolicy.PrivacyLink, setup.PrivacyPolicy.HelpLink, setup.PrivacyPolicy.SupportEmail),
|
||||
prepareAddDefaultPrivacyPolicy(instanceAgg, setup.PrivacyPolicy.TOSLink, setup.PrivacyPolicy.PrivacyLink, setup.PrivacyPolicy.HelpLink, setup.PrivacyPolicy.SupportEmail, setup.PrivacyPolicy.DocsLink, setup.PrivacyPolicy.CustomLink, setup.PrivacyPolicy.CustomLinkText),
|
||||
prepareAddDefaultNotificationPolicy(instanceAgg, setup.NotificationPolicy.PasswordChange),
|
||||
prepareAddDefaultLockoutPolicy(instanceAgg, setup.LockoutPolicy.MaxPasswordAttempts, setup.LockoutPolicy.MaxOTPAttempts, setup.LockoutPolicy.ShouldShowLockoutFailure),
|
||||
|
||||
|
||||
@@ -116,11 +116,14 @@ func writeModelToLockoutPolicy(wm *LockoutPolicyWriteModel) *domain.LockoutPolic
|
||||
|
||||
func writeModelToPrivacyPolicy(wm *PrivacyPolicyWriteModel) *domain.PrivacyPolicy {
|
||||
return &domain.PrivacyPolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
||||
TOSLink: wm.TOSLink,
|
||||
PrivacyLink: wm.PrivacyLink,
|
||||
HelpLink: wm.HelpLink,
|
||||
SupportEmail: wm.SupportEmail,
|
||||
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
||||
TOSLink: wm.TOSLink,
|
||||
PrivacyLink: wm.PrivacyLink,
|
||||
HelpLink: wm.HelpLink,
|
||||
SupportEmail: wm.SupportEmail,
|
||||
DocsLink: wm.DocsLink,
|
||||
CustomLink: wm.CustomLink,
|
||||
CustomLinkText: wm.CustomLinkText,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,37 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, tosLink, privacyLink, helpLink string, supportEmail domain.EmailAddress) (*domain.ObjectDetails, error) {
|
||||
func (c *Commands) AddDefaultPrivacyPolicy(ctx context.Context, tosLink, privacyLink, helpLink string, supportEmail domain.EmailAddress, docsLink, customLink, customLinkText string) (*domain.ObjectDetails, error) {
|
||||
instanceAgg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
|
||||
cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, prepareAddDefaultPrivacyPolicy(instanceAgg, tosLink, privacyLink, helpLink, supportEmail))
|
||||
|
||||
if supportEmail != "" {
|
||||
if err := supportEmail.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
supportEmail = supportEmail.Normalize()
|
||||
}
|
||||
|
||||
writeModel := NewInstancePrivacyPolicyWriteModel(ctx)
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pushedEvents, err := c.eventstore.Push(ctx, cmds...)
|
||||
if writeModel.State.Exists() {
|
||||
return nil, zerrors.ThrowAlreadyExists(nil, "INSTANCE-M00rJ", "Errors.Instance.PrivacyPolicy.AlreadyExists")
|
||||
}
|
||||
|
||||
event := instance.NewPrivacyPolicyAddedEvent(ctx, &instanceAgg.Aggregate, tosLink, privacyLink, helpLink, supportEmail, docsLink, customLink, customLinkText)
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pushedEventsToObjectDetails(pushedEvents), nil
|
||||
err = AppendAndReduce(writeModel, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return writeModelToObjectDetails(&writeModel.WriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultPrivacyPolicy(ctx context.Context, policy *domain.PrivacyPolicy) (*domain.PrivacyPolicy, error) {
|
||||
@@ -42,7 +62,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, policy.SupportEmail)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, instanceAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink, policy.SupportEmail, policy.DocsLink, policy.CustomLink, policy.CustomLinkText)
|
||||
if !hasChanged {
|
||||
return nil, zerrors.ThrowPreconditionFailed(nil, "INSTANCE-9jJfs", "Errors.IAM.PrivacyPolicy.NotChanged")
|
||||
}
|
||||
@@ -89,6 +109,7 @@ func prepareAddDefaultPrivacyPolicy(
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
supportEmail domain.EmailAddress,
|
||||
docsLink, customLink, customLinkText string,
|
||||
) preparation.Validation {
|
||||
return func() (preparation.CreateCommands, error) {
|
||||
if supportEmail != "" {
|
||||
@@ -111,7 +132,7 @@ func prepareAddDefaultPrivacyPolicy(
|
||||
return nil, zerrors.ThrowAlreadyExists(nil, "INSTANCE-M00rJ", "Errors.Instance.PrivacyPolicy.AlreadyExists")
|
||||
}
|
||||
return []eventstore.Command{
|
||||
instance.NewPrivacyPolicyAddedEvent(ctx, &a.Aggregate, tosLink, privacyLink, helpLink, supportEmail),
|
||||
instance.NewPrivacyPolicyAddedEvent(ctx, &a.Aggregate, tosLink, privacyLink, helpLink, supportEmail, docsLink, customLink, customLinkText),
|
||||
}, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ func (wm *InstancePrivacyPolicyWriteModel) NewChangedEvent(
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
supportEmail domain.EmailAddress,
|
||||
docsLink, customLink, customLinkText string,
|
||||
) (*instance.PrivacyPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.PrivacyPolicyChanges, 0)
|
||||
@@ -74,6 +75,15 @@ func (wm *InstancePrivacyPolicyWriteModel) NewChangedEvent(
|
||||
if wm.SupportEmail != supportEmail {
|
||||
changes = append(changes, policy.ChangeSupportEmail(supportEmail))
|
||||
}
|
||||
if wm.DocsLink != docsLink {
|
||||
changes = append(changes, policy.ChangeDocsLink(docsLink))
|
||||
}
|
||||
if wm.CustomLink != customLink {
|
||||
changes = append(changes, policy.ChangeCustomLink(customLink))
|
||||
}
|
||||
if wm.CustomLinkText != customLinkText {
|
||||
changes = append(changes, policy.ChangeCustomLinkText(customLinkText))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -20,11 +20,14 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
eventstore *eventstore.Eventstore
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
tosLink string
|
||||
privacyLink string
|
||||
helpLink string
|
||||
supportEmail domain.EmailAddress
|
||||
ctx context.Context
|
||||
tosLink string
|
||||
privacyLink string
|
||||
helpLink string
|
||||
supportEmail domain.EmailAddress
|
||||
docsLink string
|
||||
customLink string
|
||||
customLinkText string
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -49,17 +52,23 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"Custom",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "support@example.com",
|
||||
ctx: context.Background(),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "support@example.com",
|
||||
docsLink: "DocsLink",
|
||||
customLink: "CustomLink",
|
||||
customLinkText: "Custom",
|
||||
},
|
||||
res: res{
|
||||
err: zerrors.IsErrorAlreadyExists,
|
||||
@@ -78,16 +87,22 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"Custom",
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "support@example.com",
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "support@example.com",
|
||||
docsLink: "DocsLink",
|
||||
customLink: "CustomLink",
|
||||
customLinkText: "Custom",
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -103,11 +118,14 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "wrong email",
|
||||
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
|
||||
tosLink: "TOSLink",
|
||||
privacyLink: "PrivacyLink",
|
||||
helpLink: "HelpLink",
|
||||
supportEmail: "wrong email",
|
||||
docsLink: "DocsLink",
|
||||
customLink: "CustomLink",
|
||||
customLinkText: "Custom",
|
||||
},
|
||||
res: res{
|
||||
err: zerrors.IsErrorInvalidArgument,
|
||||
@@ -126,6 +144,9 @@ func TestCommandSide_AddDefaultPrivacyPolicy(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -149,7 +170,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, tt.args.supportEmail)
|
||||
got, err := r.AddDefaultPrivacyPolicy(tt.args.ctx, tt.args.tosLink, tt.args.privacyLink, tt.args.helpLink, tt.args.supportEmail, tt.args.docsLink, tt.args.customLink, tt.args.customLinkText)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -192,10 +213,13 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -215,6 +239,9 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -223,10 +250,13 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -243,10 +273,13 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "wrong email",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "wrong email",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -266,6 +299,9 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -275,6 +311,9 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLinkChanged",
|
||||
"HelpLinkChanged",
|
||||
"support2@example.com",
|
||||
"DocsLinkChanged",
|
||||
"CustomLinkChanged",
|
||||
"CustomLinkTextChanged",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -282,10 +321,13 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
SupportEmail: "support2@example.com",
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
SupportEmail: "support2@example.com",
|
||||
DocsLink: "DocsLinkChanged",
|
||||
CustomLink: "CustomLinkChanged",
|
||||
CustomLinkText: "CustomLinkTextChanged",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -295,10 +337,13 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
ResourceOwner: "INSTANCE",
|
||||
InstanceID: "INSTANCE",
|
||||
},
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
SupportEmail: "support2@example.com",
|
||||
TOSLink: "TOSLinkChanged",
|
||||
PrivacyLink: "PrivacyLinkChanged",
|
||||
HelpLink: "HelpLinkChanged",
|
||||
SupportEmail: "support2@example.com",
|
||||
DocsLink: "DocsLinkChanged",
|
||||
CustomLink: "CustomLinkChanged",
|
||||
CustomLinkText: "CustomLinkTextChanged",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -322,7 +367,7 @@ func TestCommandSide_ChangeDefaultPrivacyPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLink, helpLink, supportEmail string) *instance.PrivacyPolicyChangedEvent {
|
||||
func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLink, helpLink, supportEmail, docsLink, customLink, customLinkText string) *instance.PrivacyPolicyChangedEvent {
|
||||
event, _ := instance.NewPrivacyPolicyChangedEvent(ctx,
|
||||
&instance.NewAggregate("INSTANCE").Aggregate,
|
||||
[]policy.PrivacyPolicyChanges{
|
||||
@@ -330,6 +375,9 @@ func newDefaultPrivacyPolicyChangedEvent(ctx context.Context, tosLink, privacyLi
|
||||
policy.ChangePrivacyLink(privacyLink),
|
||||
policy.ChangeHelpLink(helpLink),
|
||||
policy.ChangeSupportEmail(domain.EmailAddress(supportEmail)),
|
||||
policy.ChangeDocsLink(docsLink),
|
||||
policy.ChangeCustomLink(customLink),
|
||||
policy.ChangeCustomLinkText(customLinkText),
|
||||
},
|
||||
)
|
||||
return event
|
||||
|
||||
@@ -46,10 +46,13 @@ func orgDomainWriteModelToOrgDomain(wm *OrgDomainWriteModel) *domain.OrgDomain {
|
||||
|
||||
func orgWriteModelToPrivacyPolicy(wm *OrgPrivacyPolicyWriteModel) *domain.PrivacyPolicy {
|
||||
return &domain.PrivacyPolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.PrivacyPolicyWriteModel.WriteModel),
|
||||
TOSLink: wm.TOSLink,
|
||||
PrivacyLink: wm.PrivacyLink,
|
||||
HelpLink: wm.HelpLink,
|
||||
SupportEmail: wm.SupportEmail,
|
||||
ObjectRoot: writeModelToObjectRoot(wm.PrivacyPolicyWriteModel.WriteModel),
|
||||
TOSLink: wm.TOSLink,
|
||||
PrivacyLink: wm.PrivacyLink,
|
||||
HelpLink: wm.HelpLink,
|
||||
SupportEmail: wm.SupportEmail,
|
||||
DocsLink: wm.DocsLink,
|
||||
CustomLink: wm.CustomLink,
|
||||
CustomLinkText: wm.CustomLinkText,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,10 @@ func (c *Commands) AddPrivacyPolicy(ctx context.Context, resourceOwner string, p
|
||||
policy.TOSLink,
|
||||
policy.PrivacyLink,
|
||||
policy.HelpLink,
|
||||
policy.SupportEmail))
|
||||
policy.SupportEmail,
|
||||
policy.DocsLink,
|
||||
policy.CustomLink,
|
||||
policy.CustomLinkText))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -91,7 +94,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, policy.SupportEmail)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, orgAgg, policy.TOSLink, policy.PrivacyLink, policy.HelpLink, policy.SupportEmail, policy.DocsLink, policy.CustomLink, policy.CustomLinkText)
|
||||
if !hasChanged {
|
||||
return nil, zerrors.ThrowPreconditionFailed(nil, "Org-4N9fs", "Errors.Org.PrivacyPolicy.NotChanged")
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ func (wm *OrgPrivacyPolicyWriteModel) NewChangedEvent(
|
||||
privacyLink,
|
||||
helpLink string,
|
||||
supportEmail domain.EmailAddress,
|
||||
docsLink, customLink, customLinkText string,
|
||||
) (*org.PrivacyPolicyChangedEvent, bool) {
|
||||
|
||||
changes := make([]policy.PrivacyPolicyChanges, 0)
|
||||
@@ -75,6 +76,15 @@ func (wm *OrgPrivacyPolicyWriteModel) NewChangedEvent(
|
||||
if wm.SupportEmail != supportEmail {
|
||||
changes = append(changes, policy.ChangeSupportEmail(supportEmail))
|
||||
}
|
||||
if wm.DocsLink != docsLink {
|
||||
changes = append(changes, policy.ChangeDocsLink(docsLink))
|
||||
}
|
||||
if wm.CustomLink != customLink {
|
||||
changes = append(changes, policy.ChangeCustomLink(customLink))
|
||||
}
|
||||
if wm.CustomLinkText != customLinkText {
|
||||
changes = append(changes, policy.ChangeCustomLinkText(customLinkText))
|
||||
}
|
||||
if len(changes) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -43,10 +43,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -66,7 +69,9 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
),
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText"),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -75,10 +80,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -98,6 +106,9 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -106,10 +117,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -118,10 +132,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -136,10 +153,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "wrong email",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "wrong email",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -159,6 +179,9 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -167,10 +190,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
DocsLink: "",
|
||||
CustomLink: "",
|
||||
CustomLinkText: "",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -179,10 +205,13 @@ func TestCommandSide_AddPrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
DocsLink: "",
|
||||
CustomLink: "",
|
||||
CustomLinkText: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -235,10 +264,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -257,10 +289,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -280,6 +315,9 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -289,10 +327,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
TOSLink: "TOSLink",
|
||||
PrivacyLink: "PrivacyLink",
|
||||
HelpLink: "HelpLink",
|
||||
SupportEmail: "support@example.com",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -305,10 +346,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "wrong email",
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "wrong email",
|
||||
DocsLink: "DocsLink",
|
||||
CustomLink: "CustomLink",
|
||||
CustomLinkText: "CustomLinkText",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -328,11 +372,14 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "TOSLinkChange", "PrivacyLinkChange", "HelpLinkChange", "support2@example.com"),
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "TOSLinkChange", "PrivacyLinkChange", "HelpLinkChange", "support2@example.com", "DocsLinkChange", "CustomLinkChange", "CustomLinkTextChange"),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -340,10 +387,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "support2@example.com",
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "support2@example.com",
|
||||
DocsLink: "DocsLinkChange",
|
||||
CustomLink: "CustomLinkChange",
|
||||
CustomLinkText: "CustomLinkTextChange",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -352,10 +402,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "support2@example.com",
|
||||
TOSLink: "TOSLinkChange",
|
||||
PrivacyLink: "PrivacyLinkChange",
|
||||
HelpLink: "HelpLinkChange",
|
||||
SupportEmail: "support2@example.com",
|
||||
DocsLink: "DocsLinkChange",
|
||||
CustomLink: "CustomLinkChange",
|
||||
CustomLinkText: "CustomLinkTextChange",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -372,11 +425,14 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "", "", "", ""),
|
||||
newPrivacyPolicyChangedEvent(context.Background(), "org1", "", "", "", "", "", "", ""),
|
||||
),
|
||||
),
|
||||
},
|
||||
@@ -384,10 +440,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
policy: &domain.PrivacyPolicy{
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
DocsLink: "",
|
||||
CustomLink: "",
|
||||
CustomLinkText: "",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -396,10 +455,13 @@ func TestCommandSide_ChangePrivacyPolicy(t *testing.T) {
|
||||
AggregateID: "org1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
TOSLink: "",
|
||||
PrivacyLink: "",
|
||||
HelpLink: "",
|
||||
SupportEmail: "",
|
||||
DocsLink: "",
|
||||
CustomLink: "",
|
||||
CustomLinkText: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -484,6 +546,9 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
|
||||
"PrivacyLink",
|
||||
"HelpLink",
|
||||
"support@example.com",
|
||||
"DocsLink",
|
||||
"CustomLink",
|
||||
"CustomLinkText",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -523,7 +588,7 @@ func TestCommandSide_RemovePrivacyPolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, privacyLink, helpLink, supportEmail string) *org.PrivacyPolicyChangedEvent {
|
||||
func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, privacyLink, helpLink, supportEmail, docsLink, customLink, customLinkText string) *org.PrivacyPolicyChangedEvent {
|
||||
event, _ := org.NewPrivacyPolicyChangedEvent(ctx,
|
||||
&org.NewAggregate(orgID).Aggregate,
|
||||
[]policy.PrivacyPolicyChanges{
|
||||
@@ -531,6 +596,9 @@ func newPrivacyPolicyChangedEvent(ctx context.Context, orgID string, tosLink, pr
|
||||
policy.ChangePrivacyLink(privacyLink),
|
||||
policy.ChangeHelpLink(helpLink),
|
||||
policy.ChangeSupportEmail(domain.EmailAddress(supportEmail)),
|
||||
policy.ChangeDocsLink(docsLink),
|
||||
policy.ChangeCustomLink(customLink),
|
||||
policy.ChangeCustomLinkText(customLinkText),
|
||||
},
|
||||
)
|
||||
return event
|
||||
|
||||
@@ -9,11 +9,14 @@ import (
|
||||
type PrivacyPolicyWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
SupportEmail domain.EmailAddress
|
||||
State domain.PolicyState
|
||||
TOSLink string
|
||||
PrivacyLink string
|
||||
HelpLink string
|
||||
SupportEmail domain.EmailAddress
|
||||
State domain.PolicyState
|
||||
DocsLink string
|
||||
CustomLink string
|
||||
CustomLinkText string
|
||||
}
|
||||
|
||||
func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
||||
@@ -25,6 +28,9 @@ func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
||||
wm.HelpLink = e.HelpLink
|
||||
wm.SupportEmail = e.SupportEmail
|
||||
wm.State = domain.PolicyStateActive
|
||||
wm.DocsLink = e.DocsLink
|
||||
wm.CustomLink = e.CustomLink
|
||||
wm.CustomLinkText = e.CustomLinkText
|
||||
case *policy.PrivacyPolicyChangedEvent:
|
||||
if e.PrivacyLink != nil {
|
||||
wm.PrivacyLink = *e.PrivacyLink
|
||||
@@ -38,6 +44,15 @@ func (wm *PrivacyPolicyWriteModel) Reduce() error {
|
||||
if e.SupportEmail != nil {
|
||||
wm.SupportEmail = *e.SupportEmail
|
||||
}
|
||||
if e.DocsLink != nil {
|
||||
wm.DocsLink = *e.DocsLink
|
||||
}
|
||||
if e.CustomLink != nil {
|
||||
wm.CustomLink = *e.CustomLink
|
||||
}
|
||||
if e.CustomLinkText != nil {
|
||||
wm.CustomLinkText = *e.CustomLinkText
|
||||
}
|
||||
case *policy.PrivacyPolicyRemovedEvent:
|
||||
wm.State = domain.PolicyStateRemoved
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user