Fix partial update of logo model when updating
Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
51
pkg/coredata/migrations/20260608T135336Z.sql
Normal file
51
pkg/coredata/migrations/20260608T135336Z.sql
Normal 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
|
||||||
|
);
|
||||||
@@ -630,15 +630,16 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
)
|
)
|
||||||
|
|
||||||
logoFile = &coredata.File{
|
logoFile = &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.bucket,
|
OrganizationID: organization.ID,
|
||||||
MimeType: contentType,
|
BucketName: s.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
FileSize: req.LogoFile.Size,
|
FileKey: objectKey.String(),
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileSize: req.LogoFile.Size,
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err := s.fm.PutFile(
|
fileSize, err := s.fm.PutFile(
|
||||||
@@ -667,15 +668,16 @@ func (s *OrganizationService) CreateOrganization(
|
|||||||
)
|
)
|
||||||
|
|
||||||
horizontalLogoFile = &coredata.File{
|
horizontalLogoFile = &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.bucket,
|
OrganizationID: organization.ID,
|
||||||
MimeType: contentType,
|
BucketName: s.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
FileSize: req.HorizontalLogoFile.Size,
|
FileKey: objectKey.String(),
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileSize: req.HorizontalLogoFile.Size,
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err := s.fm.PutFile(
|
fileSize, err := s.fm.PutFile(
|
||||||
@@ -809,15 +811,16 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
|
|||||||
)
|
)
|
||||||
|
|
||||||
logoFile = &coredata.File{
|
logoFile = &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.bucket,
|
OrganizationID: organizationID,
|
||||||
MimeType: contentType,
|
BucketName: s.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
FileSize: (*req.LogoFile).Size,
|
FileKey: objectKey.String(),
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileSize: (*req.LogoFile).Size,
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err := s.fm.PutFile(
|
fileSize, err := s.fm.PutFile(
|
||||||
@@ -846,15 +849,16 @@ func (s *OrganizationService) UpdateOrganization(ctx context.Context, organizati
|
|||||||
)
|
)
|
||||||
|
|
||||||
horizontalLogoFile = &coredata.File{
|
horizontalLogoFile = &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.bucket,
|
OrganizationID: organizationID,
|
||||||
MimeType: contentType,
|
BucketName: s.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
FileSize: (*req.HorizontalLogoFile).Size,
|
FileKey: objectKey.String(),
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileSize: (*req.HorizontalLogoFile).Size,
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err := s.fm.PutFile(
|
fileSize, err := s.fm.PutFile(
|
||||||
|
|||||||
@@ -565,14 +565,15 @@ func (s FrameworkService) Import(
|
|||||||
contentType := "image/svg+xml"
|
contentType := "image/svg+xml"
|
||||||
|
|
||||||
fileRecord := &coredata.File{
|
fileRecord := &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.svc.bucket,
|
OrganizationID: organization.ID,
|
||||||
MimeType: contentType,
|
BucketName: s.svc.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileKey: objectKey.String(),
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err := s.svc.fileManager.PutFile(ctx, fileRecord, strings.NewReader(logo), map[string]string{
|
fileSize, err := s.svc.fileManager.PutFile(ctx, fileRecord, strings.NewReader(logo), map[string]string{
|
||||||
|
|||||||
@@ -305,14 +305,15 @@ func (s OrganizationService) Update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileRecord := &coredata.File{
|
fileRecord := &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.svc.bucket,
|
OrganizationID: organization.ID,
|
||||||
MimeType: contentType,
|
BucketName: s.svc.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileKey: objectKey.String(),
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err = s.svc.fileManager.PutFile(
|
fileSize, err = s.svc.fileManager.PutFile(
|
||||||
@@ -368,14 +369,15 @@ func (s OrganizationService) Update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileRecord := &coredata.File{
|
fileRecord := &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.svc.bucket,
|
OrganizationID: organization.ID,
|
||||||
MimeType: contentType,
|
BucketName: s.svc.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileKey: objectKey.String(),
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSize, err = s.svc.fileManager.PutFile(
|
fileSize, err = s.svc.fileManager.PutFile(
|
||||||
|
|||||||
@@ -391,15 +391,16 @@ func (s TrustCenterReferenceService) uploadLogoFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileRecord := &coredata.File{
|
fileRecord := &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.svc.bucket,
|
OrganizationID: trustCenter.OrganizationID,
|
||||||
MimeType: contentType,
|
BucketName: s.svc.bucket,
|
||||||
FileName: filename,
|
MimeType: contentType,
|
||||||
FileKey: objectKey.String(),
|
FileName: filename,
|
||||||
FileSize: fileSize,
|
FileKey: objectKey.String(),
|
||||||
Visibility: coredata.FileVisibilityPublic,
|
FileSize: fileSize,
|
||||||
CreatedAt: now,
|
Visibility: coredata.FileVisibilityPublic,
|
||||||
UpdatedAt: now,
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := fileRecord.Insert(ctx, tx, scope); err != nil {
|
if err := fileRecord.Insert(ctx, tx, scope); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user