Fix partial update of logo model when updating

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
Ludovic Vielle
2026-06-08 15:36:20 +02:00
parent 086ac2df87
commit 2e799e73db
5 changed files with 128 additions and 69 deletions

View File

@@ -0,0 +1,51 @@
-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.
-- Backfill organization_id on logo files that were inserted with the nil GID.
-- Before the fix in CreateOrganization/UpdateOrganization, the OrganizationID
-- field was omitted from the File struct, causing the nil GID
-- (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) to be stored instead of the actual org ID.
UPDATE files
SET organization_id = o.id
FROM organizations o
WHERE files.organization_id = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
AND (
files.id = o.logo_file_id
OR files.id = o.horizontal_logo_file_id
);
UPDATE files
SET organization_id = tc.organization_id
FROM trust_centers tc
WHERE files.organization_id = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
AND (
files.id = tc.logo_file_id
OR files.id = tc.dark_logo_file_id
);
UPDATE files
SET organization_id = tcr.organization_id
FROM trust_center_references tcr
WHERE files.organization_id = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
AND files.id = tcr.logo_file_id;
UPDATE files
SET organization_id = f.organization_id
FROM frameworks f
WHERE files.organization_id = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
AND (
files.id = f.light_logo_file_id
OR files.id = f.dark_logo_file_id
);

View File

@@ -630,15 +630,16 @@ func (s *OrganizationService) CreateOrganization(
)
logoFile = &coredata.File{
ID: fileID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: req.LogoFile.Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organization.ID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: req.LogoFile.Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err := s.fm.PutFile(
@@ -667,15 +668,16 @@ func (s *OrganizationService) CreateOrganization(
)
horizontalLogoFile = &coredata.File{
ID: fileID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: req.HorizontalLogoFile.Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organization.ID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: req.HorizontalLogoFile.Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err := s.fm.PutFile(
@@ -809,15 +811,16 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
)
logoFile = &coredata.File{
ID: fileID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: (*req.LogoFile).Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organizationID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: (*req.LogoFile).Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err := s.fm.PutFile(
@@ -846,15 +849,16 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
)
horizontalLogoFile = &coredata.File{
ID: fileID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: (*req.HorizontalLogoFile).Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organizationID,
BucketName: s.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: (*req.HorizontalLogoFile).Size,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err := s.fm.PutFile(

View File

@@ -565,14 +565,15 @@ func (s FrameworkService) Import(
contentType := "image/svg+xml"
fileRecord := &coredata.File{
ID: fileID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organization.ID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err := s.svc.fileManager.PutFile(ctx, fileRecord, strings.NewReader(logo), map[string]string{

View File

@@ -305,14 +305,15 @@ func (s OrganizationService) Update(
}
fileRecord := &coredata.File{
ID: fileID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organization.ID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err = s.svc.fileManager.PutFile(
@@ -368,14 +369,15 @@ func (s OrganizationService) Update(
}
fileRecord := &coredata.File{
ID: fileID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: organization.ID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
fileSize, err = s.svc.fileManager.PutFile(

View File

@@ -391,15 +391,16 @@ func (s TrustCenterReferenceService) uploadLogoFile(
}
fileRecord := &coredata.File{
ID: fileID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: fileSize,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
ID: fileID,
OrganizationID: trustCenter.OrganizationID,
BucketName: s.svc.bucket,
MimeType: contentType,
FileName: filename,
FileKey: objectKey.String(),
FileSize: fileSize,
Visibility: coredata.FileVisibilityPublic,
CreatedAt: now,
UpdatedAt: now,
}
if err := fileRecord.Insert(ctx, tx, scope); err != nil {