From 504cdc8f963daf7b96ac4ed25c559b2d5d247885 Mon Sep 17 00:00:00 2001 From: Bryan Frimin Date: Fri, 3 Jul 2026 10:07:21 +0200 Subject: [PATCH] Ignore error when partial are ok Signed-off-by: Bryan Frimin --- pkg/cookiebanner/service.go | 4 +-- pkg/iam/organization_service.go | 2 +- pkg/probo/asset_service.go | 12 +++++++++ pkg/probo/compliance_framework_service.go | 5 ++++ pkg/probo/control_service.go | 3 ++- pkg/probo/datum_service.go | 12 +++++++++ pkg/probo/document_notification_worker.go | 7 ++--- pkg/probo/document_service.go | 22 ++++++++++++--- pkg/probo/file_service.go | 3 ++- pkg/probo/finding_service.go | 14 ++++++++++ pkg/probo/framework_service.go | 3 ++- pkg/probo/generated_document_service.go | 27 +++++++++++-------- pkg/probo/measure_service.go | 3 ++- pkg/probo/organization_service.go | 3 ++- pkg/probo/processing_activity_service.go | 26 ++++++++++++++++++ pkg/probo/risk_service.go | 3 ++- .../statement_of_applicability_service.go | 5 ++++ pkg/probo/task_service.go | 3 ++- pkg/probo/third_party_service.go | 2 +- pkg/probo/tracker_policy_document.go | 2 +- pkg/probo/trust_center_access_service.go | 21 +++++++++++++++ 21 files changed, 153 insertions(+), 29 deletions(-) diff --git a/pkg/cookiebanner/service.go b/pkg/cookiebanner/service.go index fba86eb1f..2a4263307 100644 --- a/pkg/cookiebanner/service.go +++ b/pkg/cookiebanner/service.go @@ -779,7 +779,7 @@ func (s *Service) GetCookieBannersByIDs( err := s.pg.WithConn( ctx, func(ctx context.Context, conn pg.Querier) error { - if err := banners.LoadByIDs(ctx, conn, scope, bannerIDs); err != nil { + if err := banners.LoadByIDs(ctx, conn, scope, bannerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load cookie banners by ids: %w", err) } @@ -1253,7 +1253,7 @@ func (s *Service) GetCookieCategoriesByIDs( err := s.pg.WithConn( ctx, func(ctx context.Context, conn pg.Querier) error { - if err := categories.LoadByIDs(ctx, conn, scope, categoryIDs); err != nil { + if err := categories.LoadByIDs(ctx, conn, scope, categoryIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load cookie categories by ids: %w", err) } diff --git a/pkg/iam/organization_service.go b/pkg/iam/organization_service.go index 4d6dede31..4dd01a17c 100644 --- a/pkg/iam/organization_service.go +++ b/pkg/iam/organization_service.go @@ -1238,7 +1238,7 @@ func (s *OrganizationService) GetProfilesByIDs( conn, scope, profileIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load profiles by ids: %w", err) } diff --git a/pkg/probo/asset_service.go b/pkg/probo/asset_service.go index c31df98e4..598a18ef8 100644 --- a/pkg/probo/asset_service.go +++ b/pkg/probo/asset_service.go @@ -220,6 +220,13 @@ func (s AssetService) Update( } if req.ThirdPartyIDs != nil { + if len(req.ThirdPartyIDs) > 0 { + thirdParties := &coredata.ThirdParties{} + if err := thirdParties.LoadByIDs(ctx, conn, scope, req.ThirdPartyIDs); err != nil { + return fmt.Errorf("cannot load thirdParties: %w", err) + } + } + if err := assetThirdParties.Merge(ctx, conn, scope, asset.ID, asset.OrganizationID, req.ThirdPartyIDs); err != nil { return fmt.Errorf("cannot update asset thirdParties: %w", err) } @@ -269,6 +276,11 @@ func (s AssetService) Create( } if len(req.ThirdPartyIDs) > 0 { + thirdParties := &coredata.ThirdParties{} + if err := thirdParties.LoadByIDs(ctx, conn, scope, req.ThirdPartyIDs); err != nil { + return fmt.Errorf("cannot load thirdParties: %w", err) + } + if err := assetThirdParties.Insert(ctx, conn, scope, asset.ID, asset.OrganizationID, req.ThirdPartyIDs); err != nil { return fmt.Errorf("cannot create asset thirdParties: %w", err) } diff --git a/pkg/probo/compliance_framework_service.go b/pkg/probo/compliance_framework_service.go index 6aa5e84bf..1aa3594d0 100644 --- a/pkg/probo/compliance_framework_service.go +++ b/pkg/probo/compliance_framework_service.go @@ -117,6 +117,11 @@ func (s ComplianceFrameworkService) Create( return fmt.Errorf("cannot load trust center: %w", err) } + framework := &coredata.Framework{} + if err := framework.LoadByID(ctx, tx, scope, req.FrameworkID); err != nil { + return fmt.Errorf("cannot load framework: %w", err) + } + cf = &coredata.ComplianceFramework{ ID: cfID, OrganizationID: trustCenter.OrganizationID, diff --git a/pkg/probo/control_service.go b/pkg/probo/control_service.go index f2aaae5b7..53d487930 100644 --- a/pkg/probo/control_service.go +++ b/pkg/probo/control_service.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "time" @@ -809,7 +810,7 @@ func (s ControlService) GetByIDs( conn, scope, controlIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load controls by ids: %w", err) } diff --git a/pkg/probo/datum_service.go b/pkg/probo/datum_service.go index fd2e33323..68b241231 100644 --- a/pkg/probo/datum_service.go +++ b/pkg/probo/datum_service.go @@ -207,6 +207,13 @@ func (s DatumService) Update( } if req.ThirdPartyIDs != nil { + if len(req.ThirdPartyIDs) > 0 { + thirdParties := &coredata.ThirdParties{} + if err := thirdParties.LoadByIDs(ctx, conn, scope, req.ThirdPartyIDs); err != nil { + return fmt.Errorf("cannot load thirdParties: %w", err) + } + } + if err := datumThirdParties.Merge(ctx, conn, scope, datum.ID, datum.OrganizationID, req.ThirdPartyIDs); err != nil { return fmt.Errorf("cannot update data thirdParties: %w", err) } @@ -256,6 +263,11 @@ func (s DatumService) Create( } if len(req.ThirdPartyIDs) > 0 { + thirdParties := &coredata.ThirdParties{} + if err := thirdParties.LoadByIDs(ctx, conn, scope, req.ThirdPartyIDs); err != nil { + return fmt.Errorf("cannot load thirdParties: %w", err) + } + if err := datumThirdParties.Insert(ctx, conn, scope, datum.ID, datum.OrganizationID, req.ThirdPartyIDs); err != nil { return fmt.Errorf("cannot create data thirdParties: %w", err) } diff --git a/pkg/probo/document_notification_worker.go b/pkg/probo/document_notification_worker.go index 33295f926..3cfd5ca6b 100644 --- a/pkg/probo/document_notification_worker.go +++ b/pkg/probo/document_notification_worker.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "net/url" "sort" @@ -296,7 +297,7 @@ func (h *documentNotificationHandler) claimNextApprovalGroup( scope := coredata.NewScopeFromObjectID(decisions[0].OrganizationID) var quorums coredata.DocumentVersionApprovalQuorums - if err := quorums.LoadByIDs(ctx, tx, scope, quorumIDs); err != nil { + if err := quorums.LoadByIDs(ctx, tx, scope, quorumIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load approval quorums: %w", err) } @@ -343,7 +344,7 @@ func (s *DocumentService) sendNotification( } var versions coredata.DocumentVersions - if err := versions.LoadByIDs(ctx, tx, scope, versionIDs); err != nil { + if err := versions.LoadByIDs(ctx, tx, scope, versionIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load document versions for notification: %w", err) } @@ -352,7 +353,7 @@ func (s *DocumentService) sendNotification( } var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, tx, scope, []gid.GID{recipientID}); err != nil { + if err := profiles.LoadByIDs(ctx, tx, scope, []gid.GID{recipientID}); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load notification recipient: %w", err) } diff --git a/pkg/probo/document_service.go b/pkg/probo/document_service.go index 20d94bbb4..22c97400e 100644 --- a/pkg/probo/document_service.go +++ b/pkg/probo/document_service.go @@ -360,7 +360,11 @@ func (s *DocumentService) GetDefaultApprovers( err = s.svc.pg.WithConn( ctx, func(ctx context.Context, conn pg.Querier) error { - return profiles.LoadByIDs(ctx, conn, scope, profileIDs) + if err := profiles.LoadByIDs(ctx, conn, scope, profileIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { + return err + } + + return nil }, ) if err != nil { @@ -384,7 +388,7 @@ func (s *DocumentService) GetByIDs( conn, scope, documentIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load documents by ids: %w", err) } @@ -784,6 +788,11 @@ func (s *DocumentService) Create( } if len(req.DefaultApproverIDs) > 0 { + profiles := &coredata.MembershipProfiles{} + if err := profiles.LoadByIDs(ctx, conn, scope, req.DefaultApproverIDs); err != nil { + return fmt.Errorf("cannot load approver profiles: %w", err) + } + approvers := &coredata.DocumentDefaultApprovers{} if err := approvers.MergeByDocumentID(ctx, conn, scope, documentID, organization.ID, req.DefaultApproverIDs); err != nil { return fmt.Errorf("cannot set default approvers: %w", err) @@ -2142,6 +2151,13 @@ func (s *DocumentService) Update( } if req.DefaultApproverIDs != nil { + if len(*req.DefaultApproverIDs) > 0 { + profiles := &coredata.MembershipProfiles{} + if err := profiles.LoadByIDs(ctx, tx, scope, *req.DefaultApproverIDs); err != nil { + return fmt.Errorf("cannot load approver profiles: %w", err) + } + } + defaultApprovers := &coredata.DocumentDefaultApprovers{} if err := defaultApprovers.MergeByDocumentID(ctx, tx, scope, req.DocumentID, document.OrganizationID, *req.DefaultApproverIDs); err != nil { return fmt.Errorf("cannot update default approvers: %w", err) @@ -2834,7 +2850,7 @@ func generateDocumentPDF( if len(approverProfileIDs) > 0 { approverProfiles := coredata.MembershipProfiles{} - if err := approverProfiles.LoadByIDs(ctx, conn, scope, approverProfileIDs); err != nil { + if err := approverProfiles.LoadByIDs(ctx, conn, scope, approverProfileIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return nil, fmt.Errorf("cannot load approver profiles: %w", err) } diff --git a/pkg/probo/file_service.go b/pkg/probo/file_service.go index 143294e99..cf7fc3c34 100644 --- a/pkg/probo/file_service.go +++ b/pkg/probo/file_service.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "io" "time" @@ -85,7 +86,7 @@ func (s FileService) GetByIDs( conn, scope, fileIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load files by ids: %w", err) } diff --git a/pkg/probo/finding_service.go b/pkg/probo/finding_service.go index bf587553f..d00e41d99 100644 --- a/pkg/probo/finding_service.go +++ b/pkg/probo/finding_service.go @@ -173,6 +173,13 @@ func (s *FindingService) Create( } } + if req.RiskID != nil { + risk := &coredata.Risk{} + if err := risk.LoadByID(ctx, conn, scope, *req.RiskID); err != nil { + return fmt.Errorf("cannot load risk: %w", err) + } + } + if err := finding.Insert(ctx, conn, scope); err != nil { return fmt.Errorf("cannot insert finding: %w", err) } @@ -246,6 +253,13 @@ func (s *FindingService) Update( } if req.RiskID != nil { + if *req.RiskID != nil { + risk := &coredata.Risk{} + if err := risk.LoadByID(ctx, conn, scope, **req.RiskID); err != nil { + return fmt.Errorf("cannot load risk: %w", err) + } + } + finding.RiskID = *req.RiskID } diff --git a/pkg/probo/framework_service.go b/pkg/probo/framework_service.go index faea5c8f7..8844ea0d7 100644 --- a/pkg/probo/framework_service.go +++ b/pkg/probo/framework_service.go @@ -18,6 +18,7 @@ import ( "archive/zip" "context" "encoding/json" + "errors" "fmt" "io" "os" @@ -467,7 +468,7 @@ func (s FrameworkService) GetByIDs( conn, scope, frameworkIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load frameworks by ids: %w", err) } diff --git a/pkg/probo/generated_document_service.go b/pkg/probo/generated_document_service.go index 109dbbdb5..08af2681b 100644 --- a/pkg/probo/generated_document_service.go +++ b/pkg/probo/generated_document_service.go @@ -183,7 +183,7 @@ func (s *GeneratedDocumentService) buildStatementOfApplicabilityDocumentData( } var controls coredata.Controls - if err := controls.LoadByIDs(ctx, conn, scope, controlIDs); err != nil { + if err := controls.LoadByIDs(ctx, conn, scope, controlIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.StatementOfApplicabilityData{}, fmt.Errorf("cannot load controls: %w", err) } @@ -201,7 +201,7 @@ func (s *GeneratedDocumentService) buildStatementOfApplicabilityDocumentData( } var frameworks coredata.Frameworks - if err := frameworks.LoadByIDs(ctx, conn, scope, frameworkIDs); err != nil { + if err := frameworks.LoadByIDs(ctx, conn, scope, frameworkIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.StatementOfApplicabilityData{}, fmt.Errorf("cannot load frameworks: %w", err) } @@ -475,7 +475,7 @@ func (s *GeneratedDocumentService) buildDataListDocumentData( } var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.DataListData{}, fmt.Errorf("cannot load profiles: %w", err) } @@ -747,7 +747,7 @@ func (s *GeneratedDocumentService) buildAssetListDocumentData( } var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.AssetListData{}, fmt.Errorf("cannot load profiles: %w", err) } @@ -1047,7 +1047,7 @@ func (s *GeneratedDocumentService) buildFindingListDocumentData( if len(ownerIDs) > 0 { var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.FindingListData{}, fmt.Errorf("cannot load profiles: %w", err) } @@ -1375,7 +1375,7 @@ func (s *GeneratedDocumentService) buildObligationListDocumentData( if len(ownerIDs) > 0 { var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.ObligationListData{}, fmt.Errorf("cannot load profiles: %w", err) } @@ -1674,7 +1674,7 @@ func (s *GeneratedDocumentService) buildProcessingActivityListDocumentData( if len(dpoIDs) > 0 { var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, dpoIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, dpoIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.ProcessingActivityListData{}, fmt.Errorf("cannot load DPO profiles: %w", err) } @@ -2057,7 +2057,7 @@ func (s *GeneratedDocumentService) buildDataProtectionImpactAssessmentListDocume } var processingActivities coredata.ProcessingActivities - if err := processingActivities.LoadByIDs(ctx, conn, scope, processingActivityIDs); err != nil { + if err := processingActivities.LoadByIDs(ctx, conn, scope, processingActivityIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.DataProtectionImpactAssessmentListData{}, fmt.Errorf("cannot load processing activities: %w", err) } @@ -2289,7 +2289,7 @@ func (s *GeneratedDocumentService) buildTransferImpactAssessmentListDocumentData } var processingActivities coredata.ProcessingActivities - if err := processingActivities.LoadByIDs(ctx, conn, scope, processingActivityIDs); err != nil { + if err := processingActivities.LoadByIDs(ctx, conn, scope, processingActivityIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.TransferImpactAssessmentListData{}, fmt.Errorf("cannot load processing activities: %w", err) } @@ -2551,7 +2551,7 @@ func (s *GeneratedDocumentService) buildThirdPartyListDocumentData( if len(ownerIDs) > 0 { var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.ThirdPartyListData{}, fmt.Errorf("cannot load owner profiles: %w", err) } @@ -3093,7 +3093,7 @@ func (s *GeneratedDocumentService) buildRiskListDocumentData( if len(ownerIDs) > 0 { var profiles coredata.MembershipProfiles - if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil { + if err := profiles.LoadByIDs(ctx, conn, scope, ownerIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return docgen.RiskListData{}, fmt.Errorf("cannot load profiles: %w", err) } @@ -3274,6 +3274,11 @@ func (s *GeneratedDocumentService) publishOrRequestApproval( } if len(approverIDs) > 0 { + profiles := &coredata.MembershipProfiles{} + if err := profiles.LoadByIDs(ctx, tx, scope, approverIDs); err != nil { + return fmt.Errorf("cannot load approver profiles: %w", err) + } + defaultApprovers := &coredata.DocumentDefaultApprovers{} if err := defaultApprovers.MergeByDocumentID(ctx, tx, scope, document.ID, organizationID, approverIDs); err != nil { return fmt.Errorf("cannot save default approvers: %w", err) diff --git a/pkg/probo/measure_service.go b/pkg/probo/measure_service.go index 767606671..2e7e0a3f9 100644 --- a/pkg/probo/measure_service.go +++ b/pkg/probo/measure_service.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "time" @@ -348,7 +349,7 @@ func (s MeasureService) GetByIDs( conn, scope, measureIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load measures by ids: %w", err) } diff --git a/pkg/probo/organization_service.go b/pkg/probo/organization_service.go index 6c89f516f..0219615a4 100644 --- a/pkg/probo/organization_service.go +++ b/pkg/probo/organization_service.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "mime" "net/mail" @@ -124,7 +125,7 @@ func (s OrganizationService) GetByIDs( conn, scope, organizationIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load organizations by ids: %w", err) } diff --git a/pkg/probo/processing_activity_service.go b/pkg/probo/processing_activity_service.go index b90c98866..043503281 100644 --- a/pkg/probo/processing_activity_service.go +++ b/pkg/probo/processing_activity_service.go @@ -195,11 +195,23 @@ func (s *ProcessingActivityService) Create( return fmt.Errorf("cannot load organization: %w", err) } + if req.DataProtectionOfficerID != nil { + dpo := &coredata.MembershipProfile{} + if err := dpo.LoadByID(ctx, conn, scope, *req.DataProtectionOfficerID); err != nil { + return fmt.Errorf("cannot load data protection officer profile: %w", err) + } + } + if err := processingActivity.Insert(ctx, conn, scope); err != nil { return fmt.Errorf("cannot insert processing activity: %w", err) } if len(req.ThirdPartyIDs) > 0 { + thirdParties := &coredata.ThirdParties{} + if err := thirdParties.LoadByIDs(ctx, conn, scope, req.ThirdPartyIDs); err != nil { + return fmt.Errorf("cannot load thirdParties: %w", err) + } + if err := processingActivityThirdParties.Insert(ctx, conn, scope, processingActivity.ID, req.OrganizationID, req.ThirdPartyIDs); err != nil { return fmt.Errorf("cannot create processing activity thirdParties: %w", err) } @@ -302,6 +314,13 @@ func (s *ProcessingActivityService) Update( } if req.DataProtectionOfficerID != nil { + if *req.DataProtectionOfficerID != nil { + dpo := &coredata.MembershipProfile{} + if err := dpo.LoadByID(ctx, conn, scope, **req.DataProtectionOfficerID); err != nil { + return fmt.Errorf("cannot load data protection officer profile: %w", err) + } + } + processingActivity.DataProtectionOfficerID = *req.DataProtectionOfficerID } @@ -312,6 +331,13 @@ func (s *ProcessingActivityService) Update( } if req.ThirdPartyIDs != nil { + if len(*req.ThirdPartyIDs) > 0 { + thirdParties := &coredata.ThirdParties{} + if err := thirdParties.LoadByIDs(ctx, conn, scope, *req.ThirdPartyIDs); err != nil { + return fmt.Errorf("cannot load thirdParties: %w", err) + } + } + if err := processingActivityThirdParties.Merge(ctx, conn, scope, processingActivity.ID, processingActivity.OrganizationID, *req.ThirdPartyIDs); err != nil { return fmt.Errorf("cannot update processing activity thirdParties: %w", err) } diff --git a/pkg/probo/risk_service.go b/pkg/probo/risk_service.go index 2aae75b84..bf9d877df 100644 --- a/pkg/probo/risk_service.go +++ b/pkg/probo/risk_service.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "time" @@ -502,7 +503,7 @@ func (s RiskService) GetByIDs( conn, scope, riskIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load risks by ids: %w", err) } diff --git a/pkg/probo/statement_of_applicability_service.go b/pkg/probo/statement_of_applicability_service.go index f52657b3f..9c6ce2c6a 100644 --- a/pkg/probo/statement_of_applicability_service.go +++ b/pkg/probo/statement_of_applicability_service.go @@ -342,6 +342,11 @@ func (s StatementOfApplicabilityService) CreateApplicabilityStatement( return fmt.Errorf("cannot load statement of applicability: %w", err) } + control := &coredata.Control{} + if err := control.LoadByID(ctx, conn, scope, controlID); err != nil { + return fmt.Errorf("cannot load control: %w", err) + } + applicabilityStatement = &coredata.ApplicabilityStatement{ ID: gid.New(scope.GetTenantID(), coredata.ApplicabilityStatementEntityType), StatementOfApplicabilityID: statementOfApplicabilityID, diff --git a/pkg/probo/task_service.go b/pkg/probo/task_service.go index c9ebad4f5..711848a20 100644 --- a/pkg/probo/task_service.go +++ b/pkg/probo/task_service.go @@ -16,6 +16,7 @@ package probo import ( "context" + "errors" "fmt" "time" @@ -183,7 +184,7 @@ func (s TaskService) GetByIDs( conn, scope, taskIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load tasks by ids: %w", err) } diff --git a/pkg/probo/third_party_service.go b/pkg/probo/third_party_service.go index 396219e02..dd7583e94 100644 --- a/pkg/probo/third_party_service.go +++ b/pkg/probo/third_party_service.go @@ -526,7 +526,7 @@ func (s ThirdPartyService) GetByIDs( conn, scope, thirdPartyIDs, - ); err != nil { + ); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return fmt.Errorf("cannot load thirdParties by ids: %w", err) } diff --git a/pkg/probo/tracker_policy_document.go b/pkg/probo/tracker_policy_document.go index 2458db344..23a2a5a73 100644 --- a/pkg/probo/tracker_policy_document.go +++ b/pkg/probo/tracker_policy_document.go @@ -271,7 +271,7 @@ func (s *GeneratedDocumentService) buildTrackerPolicyThirdParties( var thirdParties coredata.ThirdParties if len(thirdPartyIDs) > 0 { - if err := thirdParties.LoadByIDs(ctx, conn, scope, thirdPartyIDs); err != nil { + if err := thirdParties.LoadByIDs(ctx, conn, scope, thirdPartyIDs); err != nil && !errors.Is(err, coredata.ErrResourceNotFound) { return nil, fmt.Errorf("cannot load third parties: %w", err) } } diff --git a/pkg/probo/trust_center_access_service.go b/pkg/probo/trust_center_access_service.go index 72d5ed354..642c4959f 100644 --- a/pkg/probo/trust_center_access_service.go +++ b/pkg/probo/trust_center_access_service.go @@ -242,11 +242,18 @@ func (s TrustCenterAccessService) Update( if len(req.DocumentAccesses) > 0 { var documentData []coredata.MergeTrustCenterDocumentAccessesData + documentIDs := make([]gid.GID, 0, len(req.DocumentAccesses)) for _, d := range req.DocumentAccesses { documentData = append(documentData, coredata.MergeTrustCenterDocumentAccessesData{ ID: d.ID, Status: d.Status, }) + documentIDs = append(documentIDs, d.ID) + } + + documents := &coredata.Documents{} + if err := documents.LoadByIDs(ctx, tx, scope, documentIDs); err != nil { + return fmt.Errorf("cannot load documents: %w", err) } if err := tcdas.MergeDocumentAccesses(ctx, tx, scope, access.OrganizationID, access.ID, documentData); err != nil { @@ -256,11 +263,18 @@ func (s TrustCenterAccessService) Update( if len(req.ReportAccesses) > 0 { var reportData []coredata.MergeTrustCenterDocumentAccessesData + reportIDs := make([]gid.GID, 0, len(req.ReportAccesses)) for _, d := range req.ReportAccesses { reportData = append(reportData, coredata.MergeTrustCenterDocumentAccessesData{ ID: d.ID, Status: d.Status, }) + reportIDs = append(reportIDs, d.ID) + } + + files := &coredata.Files{} + if err := files.LoadByIDs(ctx, tx, scope, reportIDs); err != nil { + return fmt.Errorf("cannot load report files: %w", err) } if err := tcdas.MergeReportFileAccesses(ctx, tx, scope, access.OrganizationID, access.ID, reportData); err != nil { @@ -270,11 +284,18 @@ func (s TrustCenterAccessService) Update( if len(req.TrustCenterFileAccesses) > 0 { var fileData []coredata.MergeTrustCenterDocumentAccessesData + trustCenterFileIDs := make([]gid.GID, 0, len(req.TrustCenterFileAccesses)) for _, d := range req.TrustCenterFileAccesses { fileData = append(fileData, coredata.MergeTrustCenterDocumentAccessesData{ ID: d.ID, Status: d.Status, }) + trustCenterFileIDs = append(trustCenterFileIDs, d.ID) + } + + trustCenterFiles := &coredata.TrustCenterFiles{} + if err := trustCenterFiles.LoadByIDs(ctx, tx, scope, trustCenterFileIDs); err != nil { + return fmt.Errorf("cannot load trust center files: %w", err) } if err := tcdas.MergeTrustCenterFileAccesses(ctx, tx, scope, access.OrganizationID, access.ID, fileData); err != nil {