diff --git a/pkg/coredata/migrations/20260608T135336Z.sql b/pkg/coredata/migrations/20260608T135336Z.sql new file mode 100644 index 000000000..5d3aacb9e --- /dev/null +++ b/pkg/coredata/migrations/20260608T135336Z.sql @@ -0,0 +1,51 @@ +-- Copyright (c) 2026 Probo Inc . +-- +-- 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 + ); diff --git a/pkg/iam/organization_service.go b/pkg/iam/organization_service.go index 028b83fc4..f35fb194b 100644 --- a/pkg/iam/organization_service.go +++ b/pkg/iam/organization_service.go @@ -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( diff --git a/pkg/probo/framework_service.go b/pkg/probo/framework_service.go index f949d6f74..4ad2b5957 100644 --- a/pkg/probo/framework_service.go +++ b/pkg/probo/framework_service.go @@ -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{ diff --git a/pkg/probo/organization_service.go b/pkg/probo/organization_service.go index 1e58c3973..7f87f4c93 100644 --- a/pkg/probo/organization_service.go +++ b/pkg/probo/organization_service.go @@ -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( diff --git a/pkg/probo/trust_center_reference_service.go b/pkg/probo/trust_center_reference_service.go index bd46f871c..9f3641515 100644 --- a/pkg/probo/trust_center_reference_service.go +++ b/pkg/probo/trust_center_reference_service.go @@ -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 {