Avoid loading trust center twice

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-30 19:15:53 +04:00
parent d9c07ecdef
commit a8a8c1103f
2 changed files with 6 additions and 23 deletions

View File

@@ -400,14 +400,8 @@ func (s TrustCenterAccessService) Delete(
} }
func (s TrustCenterAccessService) sendAccessEmail(ctx context.Context, tx pg.Conn, access *coredata.TrustCenterAccess) error { func (s TrustCenterAccessService) sendAccessEmail(ctx context.Context, tx pg.Conn, access *coredata.TrustCenterAccess) error {
trustCenter := &coredata.TrustCenter{}
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, access.TrustCenterID); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
organization := &coredata.Organization{} organization := &coredata.Organization{}
if err := organization.LoadByID(ctx, tx, s.svc.scope, trustCenter.OrganizationID); err != nil { if err := organization.LoadByID(ctx, tx, s.svc.scope, access.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization: %w", err) return fmt.Errorf("cannot load organization: %w", err)
} }
@@ -418,7 +412,7 @@ func (s TrustCenterAccessService) sendAccessEmail(ctx context.Context, tx pg.Con
return fmt.Errorf("cannot update trust center access with expiration: %w", err) return fmt.Errorf("cannot update trust center access with expiration: %w", err)
} }
emailPresenterCfg, err := s.svc.TrustCenters.EmailPresenterConfig(ctx, trustCenter.ID) emailPresenterCfg, err := s.svc.TrustCenters.EmailPresenterConfig(ctx, access.TrustCenterID)
if err != nil { if err != nil {
return fmt.Errorf("cannot get compliance page email presenter config: %w", err) return fmt.Errorf("cannot get compliance page email presenter config: %w", err)
} }

View File

@@ -466,14 +466,8 @@ func (s *TrustCenterAccessService) GrantByIDs(
} }
func (s *TrustCenterAccessService) sendAccessEmail(ctx context.Context, tx pg.Conn, access *coredata.TrustCenterAccess) error { func (s *TrustCenterAccessService) sendAccessEmail(ctx context.Context, tx pg.Conn, access *coredata.TrustCenterAccess) error {
trustCenter := &coredata.TrustCenter{}
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, access.TrustCenterID); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
organization := &coredata.Organization{} organization := &coredata.Organization{}
if err := organization.LoadByID(ctx, tx, s.svc.scope, trustCenter.OrganizationID); err != nil { if err := organization.LoadByID(ctx, tx, s.svc.scope, access.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization: %w", err) return fmt.Errorf("cannot load organization: %w", err)
} }
@@ -484,7 +478,7 @@ func (s *TrustCenterAccessService) sendAccessEmail(ctx context.Context, tx pg.Co
return fmt.Errorf("cannot update trust center access with expiration: %w", err) return fmt.Errorf("cannot update trust center access with expiration: %w", err)
} }
emailPresenterCfg, err := s.svc.TrustCenters.EmailPresenterConfig(ctx, trustCenter.ID) emailPresenterCfg, err := s.svc.TrustCenters.EmailPresenterConfig(ctx, access.TrustCenterID)
if err != nil { if err != nil {
return fmt.Errorf("cannot get compliance page email presenter config: %w", err) return fmt.Errorf("cannot get compliance page email presenter config: %w", err)
} }
@@ -569,13 +563,8 @@ func (s *TrustCenterAccessService) sendDocumentAccessRejectedEmail(
reportIDs []gid.GID, reportIDs []gid.GID,
fileIDs []gid.GID, fileIDs []gid.GID,
) error { ) error {
trustCenter := &coredata.TrustCenter{}
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, access.TrustCenterID); err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
organization := &coredata.Organization{} organization := &coredata.Organization{}
if err := organization.LoadByID(ctx, tx, s.svc.scope, trustCenter.OrganizationID); err != nil { if err := organization.LoadByID(ctx, tx, s.svc.scope, access.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization: %w", err) return fmt.Errorf("cannot load organization: %w", err)
} }
@@ -608,7 +597,7 @@ func (s *TrustCenterAccessService) sendDocumentAccessRejectedEmail(
} }
} }
emailPresenterCfg, err := s.svc.TrustCenters.EmailPresenterConfig(ctx, trustCenter.ID) emailPresenterCfg, err := s.svc.TrustCenters.EmailPresenterConfig(ctx, access.TrustCenterID)
if err != nil { if err != nil {
return fmt.Errorf("cannot get compliance page email presenter config: %w", err) return fmt.Errorf("cannot get compliance page email presenter config: %w", err)
} }