Add logos to trust_centers and auto fill with organization logo

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-29 14:58:38 +04:00
parent 88ca5f6968
commit d381c5fc88
3 changed files with 60 additions and 2 deletions

View 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;

View File

@@ -35,6 +35,8 @@ type (
TenantID gid.TenantID `db:"tenant_id"`
Active bool `db:"active"`
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"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
@@ -77,6 +79,8 @@ SELECT
id,
organization_id,
tenant_id,
logo_file_id,
dark_logo_file_id,
active,
slug,
non_disclosure_agreement_file_id,
@@ -125,6 +129,8 @@ SELECT
id,
organization_id,
tenant_id,
logo_file_id,
dark_logo_file_id,
active,
slug,
non_disclosure_agreement_file_id,
@@ -173,6 +179,8 @@ SELECT
id,
organization_id,
tenant_id,
logo_file_id,
dark_logo_file_id,
active,
slug,
non_disclosure_agreement_file_id,
@@ -216,6 +224,8 @@ INSERT INTO trust_centers (
id,
organization_id,
tenant_id,
logo_file_id,
dark_logo_file_id,
active,
slug,
non_disclosure_agreement_file_id,
@@ -225,6 +235,8 @@ INSERT INTO trust_centers (
@id,
@organization_id,
@tenant_id,
@logo_file_id,
@dark_logo_file_id,
@active,
@slug,
@non_disclosure_agreement_file_id,
@@ -237,6 +249,8 @@ INSERT INTO trust_centers (
"id": tc.ID,
"organization_id": tc.OrganizationID,
"tenant_id": tc.TenantID,
"logo_file_id": tc.LogoFileID,
"dark_logo_file_id": tc.DarkLogoFileID,
"active": tc.Active,
"slug": tc.Slug,
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
@@ -268,6 +282,8 @@ UPDATE trust_centers
SET
active = @active,
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,
updated_at = @updated_at
WHERE
@@ -279,6 +295,8 @@ WHERE
args := pgx.StrictNamedArgs{
"id": tc.ID,
"logo_file_id": tc.LogoFileID,
"dark_logo_file_id": tc.DarkLogoFileID,
"active": tc.Active,
"slug": tc.Slug,
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,

View File

@@ -655,6 +655,9 @@ func (s *OrganizationService) CreateOrganization(
if err != nil {
return fmt.Errorf("cannot insert file: %w", err)
}
organization.LogoFileID = &logoFile.ID
trustCenter.LogoFileID = &logoFile.ID
}
if horizontalLogoFile != nil {
@@ -662,6 +665,8 @@ func (s *OrganizationService) CreateOrganization(
if err != nil {
return fmt.Errorf("cannot insert file: %w", err)
}
organization.HorizontalLogoFileID = &horizontalLogoFile.ID
}
err = membership.Insert(ctx, tx, scope)
@@ -734,6 +739,7 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
tenantID = organizationID.TenantID()
scope = coredata.NewScopeFromObjectID(organizationID)
organization = &coredata.Organization{}
compliancePage = &coredata.TrustCenter{}
)
// TODO: s3 upload happen before we validate the tenantID
@@ -851,12 +857,25 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
}
if logoFile != nil {
err := logoFile.Insert(ctx, tx, scope)
if err != nil {
if err := logoFile.Insert(ctx, tx, scope); err != nil {
return fmt.Errorf("cannot insert file: %w", err)
}
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 {
@@ -864,6 +883,7 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
if err != nil {
return fmt.Errorf("cannot insert file: %w", err)
}
organization.HorizontalLogoFileID = &horizontalLogoFile.ID
}