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:
Miguel Cabrerizo
2024-05-13 16:01:50 +02:00
committed by GitHub
parent 6942324741
commit 15d5338b91
61 changed files with 1000 additions and 286 deletions

View File

@@ -534,10 +534,13 @@ func (s *Server) getPrivacyPolicy(ctx context.Context, orgID string) (_ *managem
}
if !queriedPrivacy.IsDefault {
return &management_pb.AddCustomPrivacyPolicyRequest{
TosLink: queriedPrivacy.TOSLink,
PrivacyLink: queriedPrivacy.PrivacyLink,
HelpLink: queriedPrivacy.HelpLink,
SupportEmail: string(queriedPrivacy.SupportEmail),
TosLink: queriedPrivacy.TOSLink,
PrivacyLink: queriedPrivacy.PrivacyLink,
HelpLink: queriedPrivacy.HelpLink,
SupportEmail: string(queriedPrivacy.SupportEmail),
DocsLink: queriedPrivacy.DocsLink,
CustomLink: queriedPrivacy.CustomLink,
CustomLinkText: queriedPrivacy.CustomLinkText,
}, nil
}
return nil, nil

View File

@@ -7,9 +7,12 @@ import (
func UpdatePrivacyPolicyToDomain(req *admin_pb.UpdatePrivacyPolicyRequest) *domain.PrivacyPolicy {
return &domain.PrivacyPolicy{
TOSLink: req.TosLink,
PrivacyLink: req.PrivacyLink,
HelpLink: req.HelpLink,
SupportEmail: domain.EmailAddress(req.SupportEmail),
TOSLink: req.TosLink,
PrivacyLink: req.PrivacyLink,
HelpLink: req.HelpLink,
SupportEmail: domain.EmailAddress(req.SupportEmail),
DocsLink: req.DocsLink,
CustomLink: req.CustomLink,
CustomLinkText: req.CustomLinkText,
}
}

View File

@@ -7,18 +7,24 @@ import (
func AddPrivacyPolicyToDomain(req *mgmt_pb.AddCustomPrivacyPolicyRequest) *domain.PrivacyPolicy {
return &domain.PrivacyPolicy{
TOSLink: req.TosLink,
PrivacyLink: req.PrivacyLink,
HelpLink: req.HelpLink,
SupportEmail: domain.EmailAddress(req.SupportEmail),
TOSLink: req.TosLink,
PrivacyLink: req.PrivacyLink,
HelpLink: req.HelpLink,
SupportEmail: domain.EmailAddress(req.SupportEmail),
DocsLink: req.DocsLink,
CustomLink: req.CustomLink,
CustomLinkText: req.CustomLinkText,
}
}
func UpdatePrivacyPolicyToDomain(req *mgmt_pb.UpdateCustomPrivacyPolicyRequest) *domain.PrivacyPolicy {
return &domain.PrivacyPolicy{
TOSLink: req.TosLink,
PrivacyLink: req.PrivacyLink,
HelpLink: req.HelpLink,
SupportEmail: domain.EmailAddress(req.SupportEmail),
TOSLink: req.TosLink,
PrivacyLink: req.PrivacyLink,
HelpLink: req.HelpLink,
SupportEmail: domain.EmailAddress(req.SupportEmail),
DocsLink: req.DocsLink,
CustomLink: req.CustomLink,
CustomLinkText: req.CustomLinkText,
}
}

View File

@@ -19,5 +19,8 @@ func ModelPrivacyPolicyToPb(policy *query.PrivacyPolicy) *policy_pb.PrivacyPolic
policy.ChangeDate,
policy.ResourceOwner,
),
DocsLink: policy.DocsLink,
CustomLink: policy.CustomLink,
CustomLinkText: policy.CustomLinkText,
}
}

View File

@@ -154,6 +154,9 @@ func legalAndSupportSettingsToPb(current *query.PrivacyPolicy) *settings.LegalAn
HelpLink: current.HelpLink,
SupportEmail: string(current.SupportEmail),
ResourceOwnerType: isDefaultToResourceOwnerTypePb(current.IsDefault),
DocsLink: current.DocsLink,
CustomLink: current.CustomLink,
CustomLinkText: current.CustomLinkText,
}
}

View File

@@ -316,17 +316,23 @@ func Test_domainSettingsToPb(t *testing.T) {
func Test_legalSettingsToPb(t *testing.T) {
arg := &query.PrivacyPolicy{
TOSLink: "http://example.com/tos",
PrivacyLink: "http://example.com/pricacy",
HelpLink: "http://example.com/help",
SupportEmail: "support@zitadel.com",
IsDefault: true,
TOSLink: "http://example.com/tos",
PrivacyLink: "http://example.com/pricacy",
HelpLink: "http://example.com/help",
SupportEmail: "support@zitadel.com",
IsDefault: true,
DocsLink: "http://example.com/docs",
CustomLink: "http://example.com/custom",
CustomLinkText: "Custom",
}
want := &settings.LegalAndSupportSettings{
TosLink: "http://example.com/tos",
PrivacyPolicyLink: "http://example.com/pricacy",
HelpLink: "http://example.com/help",
SupportEmail: "support@zitadel.com",
DocsLink: "http://example.com/docs",
CustomLink: "http://example.com/custom",
CustomLinkText: "Custom",
ResourceOwnerType: settings.ResourceOwnerType_RESOURCE_OWNER_TYPE_INSTANCE,
}
got := legalAndSupportSettingsToPb(arg)

View File

@@ -1286,12 +1286,15 @@ func privacyPolicyToDomain(p *query.PrivacyPolicy) *domain.PrivacyPolicy {
CreationDate: p.CreationDate,
ChangeDate: p.ChangeDate,
},
State: p.State,
Default: p.IsDefault,
TOSLink: p.TOSLink,
PrivacyLink: p.PrivacyLink,
HelpLink: p.HelpLink,
SupportEmail: p.SupportEmail,
State: p.State,
Default: p.IsDefault,
TOSLink: p.TOSLink,
PrivacyLink: p.PrivacyLink,
HelpLink: p.HelpLink,
SupportEmail: p.SupportEmail,
DocsLink: p.DocsLink,
CustomLink: p.CustomLink,
CustomLinkText: p.CustomLinkText,
}
}

View File

@@ -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),

View File

@@ -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,
}
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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,
}
}

View File

@@ -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")
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -10,8 +10,11 @@ type PrivacyPolicy struct {
State PolicyState
Default bool
TOSLink string
PrivacyLink string
HelpLink string
SupportEmail EmailAddress
TOSLink string
PrivacyLink string
HelpLink string
SupportEmail EmailAddress
DocsLink string
CustomLink string
CustomLinkText string
}

View File

@@ -26,10 +26,13 @@ type PrivacyPolicy struct {
ResourceOwner string
State domain.PolicyState
TOSLink string
PrivacyLink string
HelpLink string
SupportEmail domain.EmailAddress
TOSLink string
PrivacyLink string
HelpLink string
SupportEmail domain.EmailAddress
DocsLink string
CustomLink string
CustomLinkText string
IsDefault bool
}
@@ -91,6 +94,18 @@ var (
name: projection.PrivacyPolicyOwnerRemovedCol,
table: privacyTable,
}
PrivacyColDocsLink = Column{
name: projection.PrivacyPolicyDocsLinkCol,
table: privacyTable,
}
PrivacyColCustomLink = Column{
name: projection.PrivacyPolicyCustomLinkCol,
table: privacyTable,
}
PrivacyColCustomLinkText = Column{
name: projection.PrivacyPolicyCustomLinkTextCol,
table: privacyTable,
}
)
func (q *Queries) PrivacyPolicyByOrg(ctx context.Context, shouldTriggerBulk bool, orgID string, withOwnerRemoved bool) (policy *PrivacyPolicy, err error) {
@@ -168,6 +183,9 @@ func preparePrivacyPolicyQuery(ctx context.Context, db prepareDatabase) (sq.Sele
PrivacyColTOSLink.identifier(),
PrivacyColHelpLink.identifier(),
PrivacyColSupportEmail.identifier(),
PrivacyColDocsLink.identifier(),
PrivacyColCustomLink.identifier(),
PrivacyColCustomLinkText.identifier(),
PrivacyColIsDefault.identifier(),
PrivacyColState.identifier(),
).
@@ -185,6 +203,9 @@ func preparePrivacyPolicyQuery(ctx context.Context, db prepareDatabase) (sq.Sele
&policy.TOSLink,
&policy.HelpLink,
&policy.SupportEmail,
&policy.DocsLink,
&policy.CustomLink,
&policy.CustomLinkText,
&policy.IsDefault,
&policy.State,
)
@@ -200,10 +221,13 @@ func preparePrivacyPolicyQuery(ctx context.Context, db prepareDatabase) (sq.Sele
func (p *PrivacyPolicy) ToDomain() *domain.PrivacyPolicy {
return &domain.PrivacyPolicy{
TOSLink: p.TOSLink,
PrivacyLink: p.PrivacyLink,
HelpLink: p.HelpLink,
SupportEmail: p.SupportEmail,
Default: p.IsDefault,
TOSLink: p.TOSLink,
PrivacyLink: p.PrivacyLink,
HelpLink: p.HelpLink,
SupportEmail: p.SupportEmail,
Default: p.IsDefault,
DocsLink: p.DocsLink,
CustomLink: p.CustomLink,
CustomLinkText: p.CustomLinkText,
}
}

View File

@@ -13,18 +13,21 @@ import (
)
var (
preparePrivacyPolicyStmt = `SELECT projections.privacy_policies3.id,` +
` projections.privacy_policies3.sequence,` +
` projections.privacy_policies3.creation_date,` +
` projections.privacy_policies3.change_date,` +
` projections.privacy_policies3.resource_owner,` +
` projections.privacy_policies3.privacy_link,` +
` projections.privacy_policies3.tos_link,` +
` projections.privacy_policies3.help_link,` +
` projections.privacy_policies3.support_email,` +
` projections.privacy_policies3.is_default,` +
` projections.privacy_policies3.state` +
` FROM projections.privacy_policies3` +
preparePrivacyPolicyStmt = `SELECT projections.privacy_policies4.id,` +
` projections.privacy_policies4.sequence,` +
` projections.privacy_policies4.creation_date,` +
` projections.privacy_policies4.change_date,` +
` projections.privacy_policies4.resource_owner,` +
` projections.privacy_policies4.privacy_link,` +
` projections.privacy_policies4.tos_link,` +
` projections.privacy_policies4.help_link,` +
` projections.privacy_policies4.support_email,` +
` projections.privacy_policies4.docs_link,` +
` projections.privacy_policies4.custom_link,` +
` projections.privacy_policies4.custom_link_text,` +
` projections.privacy_policies4.is_default,` +
` projections.privacy_policies4.state` +
` FROM projections.privacy_policies4` +
` AS OF SYSTEM TIME '-1 ms'`
preparePrivacyPolicyCols = []string{
"id",
@@ -36,6 +39,9 @@ var (
"tos_link",
"help_link",
"support_email",
"docs_link",
"custom_link",
"custom_link_text",
"is_default",
"state",
}
@@ -87,23 +93,29 @@ func Test_PrivacyPolicyPrepares(t *testing.T) {
"tos.ch",
"help.ch",
"support@example.com",
"zitadel.com/docs",
"zitadel.com",
"Zitadel",
true,
domain.PolicyStateActive,
},
),
},
object: &PrivacyPolicy{
ID: "pol-id",
CreationDate: testNow,
ChangeDate: testNow,
Sequence: 20211109,
ResourceOwner: "ro",
State: domain.PolicyStateActive,
PrivacyLink: "privacy.ch",
TOSLink: "tos.ch",
HelpLink: "help.ch",
SupportEmail: "support@example.com",
IsDefault: true,
ID: "pol-id",
CreationDate: testNow,
ChangeDate: testNow,
Sequence: 20211109,
ResourceOwner: "ro",
State: domain.PolicyStateActive,
PrivacyLink: "privacy.ch",
TOSLink: "tos.ch",
HelpLink: "help.ch",
SupportEmail: "support@example.com",
DocsLink: "zitadel.com/docs",
CustomLink: "zitadel.com",
CustomLinkText: "Zitadel",
IsDefault: true,
},
},
{

View File

@@ -14,21 +14,24 @@ import (
)
const (
PrivacyPolicyTable = "projections.privacy_policies3"
PrivacyPolicyTable = "projections.privacy_policies4"
PrivacyPolicyIDCol = "id"
PrivacyPolicyCreationDateCol = "creation_date"
PrivacyPolicyChangeDateCol = "change_date"
PrivacyPolicySequenceCol = "sequence"
PrivacyPolicyStateCol = "state"
PrivacyPolicyIsDefaultCol = "is_default"
PrivacyPolicyResourceOwnerCol = "resource_owner"
PrivacyPolicyInstanceIDCol = "instance_id"
PrivacyPolicyPrivacyLinkCol = "privacy_link"
PrivacyPolicyTOSLinkCol = "tos_link"
PrivacyPolicyHelpLinkCol = "help_link"
PrivacyPolicySupportEmailCol = "support_email"
PrivacyPolicyOwnerRemovedCol = "owner_removed"
PrivacyPolicyIDCol = "id"
PrivacyPolicyCreationDateCol = "creation_date"
PrivacyPolicyChangeDateCol = "change_date"
PrivacyPolicySequenceCol = "sequence"
PrivacyPolicyStateCol = "state"
PrivacyPolicyIsDefaultCol = "is_default"
PrivacyPolicyResourceOwnerCol = "resource_owner"
PrivacyPolicyInstanceIDCol = "instance_id"
PrivacyPolicyPrivacyLinkCol = "privacy_link"
PrivacyPolicyTOSLinkCol = "tos_link"
PrivacyPolicyHelpLinkCol = "help_link"
PrivacyPolicySupportEmailCol = "support_email"
PrivacyPolicyDocsLinkCol = "docs_link"
PrivacyPolicyCustomLinkCol = "custom_link"
PrivacyPolicyCustomLinkTextCol = "custom_link_text"
PrivacyPolicyOwnerRemovedCol = "owner_removed"
)
type privacyPolicyProjection struct{}
@@ -56,6 +59,9 @@ func (*privacyPolicyProjection) Init() *old_handler.Check {
handler.NewColumn(PrivacyPolicyTOSLinkCol, handler.ColumnTypeText),
handler.NewColumn(PrivacyPolicyHelpLinkCol, handler.ColumnTypeText),
handler.NewColumn(PrivacyPolicySupportEmailCol, handler.ColumnTypeText),
handler.NewColumn(PrivacyPolicyDocsLinkCol, handler.ColumnTypeText, handler.Default("https://zitadel.com/docs")),
handler.NewColumn(PrivacyPolicyCustomLinkCol, handler.ColumnTypeText),
handler.NewColumn(PrivacyPolicyCustomLinkTextCol, handler.ColumnTypeText),
handler.NewColumn(PrivacyPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
},
handler.NewPrimaryKey(PrivacyPolicyInstanceIDCol, PrivacyPolicyIDCol),
@@ -132,6 +138,9 @@ func (p *privacyPolicyProjection) reduceAdded(event eventstore.Event) (*handler.
handler.NewCol(PrivacyPolicyTOSLinkCol, policyEvent.TOSLink),
handler.NewCol(PrivacyPolicyHelpLinkCol, policyEvent.HelpLink),
handler.NewCol(PrivacyPolicySupportEmailCol, policyEvent.SupportEmail),
handler.NewCol(PrivacyPolicyDocsLinkCol, policyEvent.DocsLink),
handler.NewCol(PrivacyPolicyCustomLinkCol, policyEvent.CustomLink),
handler.NewCol(PrivacyPolicyCustomLinkTextCol, policyEvent.CustomLinkText),
handler.NewCol(PrivacyPolicyIsDefaultCol, isDefault),
handler.NewCol(PrivacyPolicyResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
handler.NewCol(PrivacyPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID),
@@ -164,6 +173,15 @@ func (p *privacyPolicyProjection) reduceChanged(event eventstore.Event) (*handle
if policyEvent.SupportEmail != nil {
cols = append(cols, handler.NewCol(PrivacyPolicySupportEmailCol, *policyEvent.SupportEmail))
}
if policyEvent.DocsLink != nil {
cols = append(cols, handler.NewCol(PrivacyPolicyDocsLinkCol, *policyEvent.DocsLink))
}
if policyEvent.CustomLink != nil {
cols = append(cols, handler.NewCol(PrivacyPolicyCustomLinkCol, *policyEvent.CustomLink))
}
if policyEvent.CustomLinkText != nil {
cols = append(cols, handler.NewCol(PrivacyPolicyCustomLinkTextCol, *policyEvent.CustomLinkText))
}
return handler.NewUpdateStatement(
&policyEvent,
cols,

View File

@@ -32,6 +32,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"tosLink": "http://tos.link",
"privacyLink": "http://privacy.link",
"helpLink": "http://help.link",
"docsLink": "http://docs.link",
"customLink": "http://custom.link",
"customLinkText": "Custom Link",
"supportEmail": "support@example.com"}`),
), org.PrivacyPolicyAddedEventMapper),
},
@@ -42,7 +45,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO projections.privacy_policies3 (creation_date, change_date, sequence, id, state, privacy_link, tos_link, help_link, support_email, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
expectedStmt: "INSERT INTO projections.privacy_policies4 (creation_date, change_date, sequence, id, state, privacy_link, tos_link, help_link, support_email, docs_link, custom_link, custom_link_text, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
expectedArgs: []interface{}{
anyArg{},
anyArg{},
@@ -53,6 +56,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"http://tos.link",
"http://help.link",
domain.EmailAddress("support@example.com"),
"http://docs.link",
"http://custom.link",
"Custom Link",
false,
"ro-id",
"instance-id",
@@ -74,6 +80,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"tosLink": "http://tos.link",
"privacyLink": "http://privacy.link",
"helpLink": "http://help.link",
"docsLink": "http://docs.link",
"customLink": "http://custom.link",
"customLinkText": "Custom Link",
"supportEmail": "support@example.com"}`),
), org.PrivacyPolicyChangedEventMapper),
},
@@ -83,7 +92,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.privacy_policies3 SET (change_date, sequence, privacy_link, tos_link, help_link, support_email) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
expectedStmt: "UPDATE projections.privacy_policies4 SET (change_date, sequence, privacy_link, tos_link, help_link, support_email, docs_link, custom_link, custom_link_text) = ($1, $2, $3, $4, $5, $6, $7, $8, $9) WHERE (id = $10) AND (instance_id = $11)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -91,6 +100,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"http://tos.link",
"http://help.link",
domain.EmailAddress("support@example.com"),
"http://docs.link",
"http://custom.link",
"Custom Link",
"agg-id",
"instance-id",
},
@@ -116,7 +128,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.privacy_policies3 WHERE (id = $1) AND (instance_id = $2)",
expectedStmt: "DELETE FROM projections.privacy_policies4 WHERE (id = $1) AND (instance_id = $2)",
expectedArgs: []interface{}{
"agg-id",
"instance-id",
@@ -142,7 +154,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.privacy_policies3 WHERE (instance_id = $1)",
expectedStmt: "DELETE FROM projections.privacy_policies4 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
@@ -163,6 +175,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"tosLink": "http://tos.link",
"privacyLink": "http://privacy.link",
"helpLink": "http://help.link",
"docsLink": "http://docs.link",
"customLink": "http://custom.link",
"customLinkText": "Custom Link",
"supportEmail": "support@example.com"}`),
), instance.PrivacyPolicyAddedEventMapper),
},
@@ -172,7 +187,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO projections.privacy_policies3 (creation_date, change_date, sequence, id, state, privacy_link, tos_link, help_link, support_email, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
expectedStmt: "INSERT INTO projections.privacy_policies4 (creation_date, change_date, sequence, id, state, privacy_link, tos_link, help_link, support_email, docs_link, custom_link, custom_link_text, is_default, resource_owner, instance_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
expectedArgs: []interface{}{
anyArg{},
anyArg{},
@@ -183,6 +198,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"http://tos.link",
"http://help.link",
domain.EmailAddress("support@example.com"),
"http://docs.link",
"http://custom.link",
"Custom Link",
true,
"ro-id",
"instance-id",
@@ -204,6 +222,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"tosLink": "http://tos.link",
"privacyLink": "http://privacy.link",
"helpLink": "http://help.link",
"docsLink": "http://docs.link",
"customLink": "http://custom.link",
"customLinkText": "Custom Link",
"supportEmail": "support@example.com"}`),
), instance.PrivacyPolicyChangedEventMapper),
},
@@ -213,7 +234,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.privacy_policies3 SET (change_date, sequence, privacy_link, tos_link, help_link, support_email) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
expectedStmt: "UPDATE projections.privacy_policies4 SET (change_date, sequence, privacy_link, tos_link, help_link, support_email, docs_link, custom_link, custom_link_text) = ($1, $2, $3, $4, $5, $6, $7, $8, $9) WHERE (id = $10) AND (instance_id = $11)",
expectedArgs: []interface{}{
anyArg{},
uint64(15),
@@ -221,6 +242,9 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
"http://tos.link",
"http://help.link",
domain.EmailAddress("support@example.com"),
"http://docs.link",
"http://custom.link",
"Custom Link",
"agg-id",
"instance-id",
},
@@ -246,7 +270,7 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.privacy_policies3 WHERE (instance_id = $1) AND (resource_owner = $2)",
expectedStmt: "DELETE FROM projections.privacy_policies4 WHERE (instance_id = $1) AND (resource_owner = $2)",
expectedArgs: []interface{}{
"instance-id",
"agg-id",

View File

@@ -24,6 +24,7 @@ func NewPrivacyPolicyAddedEvent(
privacyLink,
helpLink string,
supportEmail domain.EmailAddress,
docsLink, customLink, customLinkText string,
) *PrivacyPolicyAddedEvent {
return &PrivacyPolicyAddedEvent{
PrivacyPolicyAddedEvent: *policy.NewPrivacyPolicyAddedEvent(
@@ -34,7 +35,10 @@ func NewPrivacyPolicyAddedEvent(
tosLink,
privacyLink,
helpLink,
supportEmail),
supportEmail,
docsLink,
customLink,
customLinkText),
}
}

View File

@@ -25,6 +25,7 @@ func NewPrivacyPolicyAddedEvent(
privacyLink,
helpLink string,
supportEmail domain.EmailAddress,
docsLink, customLink, customLinkText string,
) *PrivacyPolicyAddedEvent {
return &PrivacyPolicyAddedEvent{
PrivacyPolicyAddedEvent: *policy.NewPrivacyPolicyAddedEvent(
@@ -35,7 +36,10 @@ func NewPrivacyPolicyAddedEvent(
tosLink,
privacyLink,
helpLink,
supportEmail),
supportEmail,
docsLink,
customLink,
customLinkText),
}
}

View File

@@ -15,10 +15,13 @@ const (
type PrivacyPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
TOSLink string `json:"tosLink,omitempty"`
PrivacyLink string `json:"privacyLink,omitempty"`
HelpLink string `json:"helpLink,omitempty"`
SupportEmail domain.EmailAddress `json:"supportEmail,omitempty"`
TOSLink string `json:"tosLink,omitempty"`
PrivacyLink string `json:"privacyLink,omitempty"`
HelpLink string `json:"helpLink,omitempty"`
SupportEmail domain.EmailAddress `json:"supportEmail,omitempty"`
DocsLink string `json:"docsLink,omitempty"`
CustomLink string `json:"customLink,omitempty"`
CustomLinkText string `json:"customLinkText,omitempty"`
}
func (e *PrivacyPolicyAddedEvent) Payload() interface{} {
@@ -35,13 +38,17 @@ func NewPrivacyPolicyAddedEvent(
privacyLink,
helpLink string,
supportEmail domain.EmailAddress,
docsLink, customLink, customLinkText string,
) *PrivacyPolicyAddedEvent {
return &PrivacyPolicyAddedEvent{
BaseEvent: *base,
TOSLink: tosLink,
PrivacyLink: privacyLink,
HelpLink: helpLink,
SupportEmail: supportEmail,
BaseEvent: *base,
TOSLink: tosLink,
PrivacyLink: privacyLink,
HelpLink: helpLink,
SupportEmail: supportEmail,
DocsLink: docsLink,
CustomLink: customLink,
CustomLinkText: customLinkText,
}
}
@@ -60,10 +67,13 @@ func PrivacyPolicyAddedEventMapper(event eventstore.Event) (eventstore.Event, er
type PrivacyPolicyChangedEvent struct {
eventstore.BaseEvent `json:"-"`
TOSLink *string `json:"tosLink,omitempty"`
PrivacyLink *string `json:"privacyLink,omitempty"`
HelpLink *string `json:"helpLink,omitempty"`
SupportEmail *domain.EmailAddress `json:"supportEmail,omitempty"`
TOSLink *string `json:"tosLink,omitempty"`
PrivacyLink *string `json:"privacyLink,omitempty"`
HelpLink *string `json:"helpLink,omitempty"`
SupportEmail *domain.EmailAddress `json:"supportEmail,omitempty"`
DocsLink *string `json:"docsLink,omitempty"`
CustomLink *string `json:"customLink,omitempty"`
CustomLinkText *string `json:"customLinkText,omitempty"`
}
func (e *PrivacyPolicyChangedEvent) Payload() interface{} {
@@ -116,6 +126,24 @@ func ChangeSupportEmail(supportEmail domain.EmailAddress) func(*PrivacyPolicyCha
}
}
func ChangeDocsLink(docsLink string) func(*PrivacyPolicyChangedEvent) {
return func(e *PrivacyPolicyChangedEvent) {
e.DocsLink = &docsLink
}
}
func ChangeCustomLink(customLink string) func(*PrivacyPolicyChangedEvent) {
return func(e *PrivacyPolicyChangedEvent) {
e.CustomLink = &customLink
}
}
func ChangeCustomLinkText(customLinkText string) func(*PrivacyPolicyChangedEvent) {
return func(e *PrivacyPolicyChangedEvent) {
e.CustomLinkText = &customLinkText
}
}
func PrivacyPolicyChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &PrivacyPolicyChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),