mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +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:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
@@ -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,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@@ -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,
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user