Avoid loading trust center twice
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user