Add logos to trust_centers and auto fill with organization logo
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
20
pkg/coredata/migrations/20260129T133000Z.sql
Normal file
20
pkg/coredata/migrations/20260129T133000Z.sql
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
ALTER TABLE
|
||||||
|
trust_centers
|
||||||
|
ADD
|
||||||
|
COLUMN logo_file_id TEXT REFERENCES files(id) ON UPDATE CASCADE ON DELETE
|
||||||
|
SET
|
||||||
|
NULL,
|
||||||
|
ADD
|
||||||
|
COLUMN dark_logo_file_id TEXT REFERENCES files(id) ON UPDATE CASCADE ON DELETE
|
||||||
|
SET
|
||||||
|
NULL;
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
trust_centers t
|
||||||
|
SET
|
||||||
|
logo_file_id = o.logo_file_id
|
||||||
|
FROM
|
||||||
|
organizations o
|
||||||
|
WHERE
|
||||||
|
t.organization_id = o.id
|
||||||
|
AND t.logo_file_id IS NULL;
|
||||||
@@ -35,6 +35,8 @@ type (
|
|||||||
TenantID gid.TenantID `db:"tenant_id"`
|
TenantID gid.TenantID `db:"tenant_id"`
|
||||||
Active bool `db:"active"`
|
Active bool `db:"active"`
|
||||||
Slug string `db:"slug"`
|
Slug string `db:"slug"`
|
||||||
|
LogoFileID *gid.GID `db:"logo_file_id"`
|
||||||
|
DarkLogoFileID *gid.GID `db:"dark_logo_file_id"`
|
||||||
NonDisclosureAgreementFileID *gid.GID `db:"non_disclosure_agreement_file_id"`
|
NonDisclosureAgreementFileID *gid.GID `db:"non_disclosure_agreement_file_id"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at"`
|
||||||
@@ -77,6 +79,8 @@ SELECT
|
|||||||
id,
|
id,
|
||||||
organization_id,
|
organization_id,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
|
logo_file_id,
|
||||||
|
dark_logo_file_id,
|
||||||
active,
|
active,
|
||||||
slug,
|
slug,
|
||||||
non_disclosure_agreement_file_id,
|
non_disclosure_agreement_file_id,
|
||||||
@@ -125,6 +129,8 @@ SELECT
|
|||||||
id,
|
id,
|
||||||
organization_id,
|
organization_id,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
|
logo_file_id,
|
||||||
|
dark_logo_file_id,
|
||||||
active,
|
active,
|
||||||
slug,
|
slug,
|
||||||
non_disclosure_agreement_file_id,
|
non_disclosure_agreement_file_id,
|
||||||
@@ -173,6 +179,8 @@ SELECT
|
|||||||
id,
|
id,
|
||||||
organization_id,
|
organization_id,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
|
logo_file_id,
|
||||||
|
dark_logo_file_id,
|
||||||
active,
|
active,
|
||||||
slug,
|
slug,
|
||||||
non_disclosure_agreement_file_id,
|
non_disclosure_agreement_file_id,
|
||||||
@@ -216,6 +224,8 @@ INSERT INTO trust_centers (
|
|||||||
id,
|
id,
|
||||||
organization_id,
|
organization_id,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
|
logo_file_id,
|
||||||
|
dark_logo_file_id,
|
||||||
active,
|
active,
|
||||||
slug,
|
slug,
|
||||||
non_disclosure_agreement_file_id,
|
non_disclosure_agreement_file_id,
|
||||||
@@ -225,6 +235,8 @@ INSERT INTO trust_centers (
|
|||||||
@id,
|
@id,
|
||||||
@organization_id,
|
@organization_id,
|
||||||
@tenant_id,
|
@tenant_id,
|
||||||
|
@logo_file_id,
|
||||||
|
@dark_logo_file_id,
|
||||||
@active,
|
@active,
|
||||||
@slug,
|
@slug,
|
||||||
@non_disclosure_agreement_file_id,
|
@non_disclosure_agreement_file_id,
|
||||||
@@ -237,6 +249,8 @@ INSERT INTO trust_centers (
|
|||||||
"id": tc.ID,
|
"id": tc.ID,
|
||||||
"organization_id": tc.OrganizationID,
|
"organization_id": tc.OrganizationID,
|
||||||
"tenant_id": tc.TenantID,
|
"tenant_id": tc.TenantID,
|
||||||
|
"logo_file_id": tc.LogoFileID,
|
||||||
|
"dark_logo_file_id": tc.DarkLogoFileID,
|
||||||
"active": tc.Active,
|
"active": tc.Active,
|
||||||
"slug": tc.Slug,
|
"slug": tc.Slug,
|
||||||
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
|
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
|
||||||
@@ -268,6 +282,8 @@ UPDATE trust_centers
|
|||||||
SET
|
SET
|
||||||
active = @active,
|
active = @active,
|
||||||
slug = @slug,
|
slug = @slug,
|
||||||
|
logo_file_id = @logo_file_id,
|
||||||
|
dark_logo_file_id = @dark_logo_file_id,
|
||||||
non_disclosure_agreement_file_id = @non_disclosure_agreement_file_id,
|
non_disclosure_agreement_file_id = @non_disclosure_agreement_file_id,
|
||||||
updated_at = @updated_at
|
updated_at = @updated_at
|
||||||
WHERE
|
WHERE
|
||||||
@@ -279,6 +295,8 @@ WHERE
|
|||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"id": tc.ID,
|
"id": tc.ID,
|
||||||
|
"logo_file_id": tc.LogoFileID,
|
||||||
|
"dark_logo_file_id": tc.DarkLogoFileID,
|
||||||
"active": tc.Active,
|
"active": tc.Active,
|
||||||
"slug": tc.Slug,
|
"slug": tc.Slug,
|
||||||
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
|
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
|
||||||
|
|||||||
@@ -655,6 +655,9 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot insert file: %w", err)
|
return fmt.Errorf("cannot insert file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
organization.LogoFileID = &logoFile.ID
|
||||||
|
trustCenter.LogoFileID = &logoFile.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if horizontalLogoFile != nil {
|
if horizontalLogoFile != nil {
|
||||||
@@ -662,6 +665,8 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot insert file: %w", err)
|
return fmt.Errorf("cannot insert file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
organization.HorizontalLogoFileID = &horizontalLogoFile.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
err = membership.Insert(ctx, tx, scope)
|
err = membership.Insert(ctx, tx, scope)
|
||||||
@@ -734,6 +739,7 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
|
|||||||
tenantID = organizationID.TenantID()
|
tenantID = organizationID.TenantID()
|
||||||
scope = coredata.NewScopeFromObjectID(organizationID)
|
scope = coredata.NewScopeFromObjectID(organizationID)
|
||||||
organization = &coredata.Organization{}
|
organization = &coredata.Organization{}
|
||||||
|
compliancePage = &coredata.TrustCenter{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: s3 upload happen before we validate the tenantID
|
// TODO: s3 upload happen before we validate the tenantID
|
||||||
@@ -851,12 +857,25 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
|
|||||||
}
|
}
|
||||||
|
|
||||||
if logoFile != nil {
|
if logoFile != nil {
|
||||||
err := logoFile.Insert(ctx, tx, scope)
|
if err := logoFile.Insert(ctx, tx, scope); err != nil {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot insert file: %w", err)
|
return fmt.Errorf("cannot insert file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
organization.LogoFileID = &logoFile.ID
|
organization.LogoFileID = &logoFile.ID
|
||||||
|
|
||||||
|
// Auto set the compliance page org logo in case it wasn't already specified
|
||||||
|
if err := compliancePage.LoadByOrganizationID(ctx, tx, scope, organizationID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load compliance page: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if compliancePage.LogoFileID == nil {
|
||||||
|
compliancePage.LogoFileID = &logoFile.ID
|
||||||
|
compliancePage.UpdatedAt = now
|
||||||
|
|
||||||
|
if err := compliancePage.Update(ctx, tx, scope); err != nil {
|
||||||
|
return fmt.Errorf("cannot update compliance page: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if horizontalLogoFile != nil {
|
if horizontalLogoFile != nil {
|
||||||
@@ -864,6 +883,7 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot insert file: %w", err)
|
return fmt.Errorf("cannot insert file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
organization.HorizontalLogoFileID = &horizontalLogoFile.ID
|
organization.HorizontalLogoFileID = &horizontalLogoFile.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user