Fix cubic review

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-11 13:47:18 +01:00
parent 421a4cebbd
commit 1ed291aa0e
7 changed files with 127 additions and 123 deletions

View File

@@ -36,7 +36,8 @@ const (
subjectDocumentSigning = "Action Required – Please review and sign %s compliance documents"
subjectDocumentExport = "Your document export is ready"
subjectFrameworkExport = "Your framework export is ready"
subjectTrustCenterAccess = "Trust Center Document Access Rejected - %s"
subjectTrustCenterAccess = "Trust Center Access Invitation - %s"
subjectTrustCenterDocumentAccessRejected = "Trust Center Document Access Rejected - %s"
)
var (
@@ -192,7 +193,7 @@ func RenderTrustCenterDocumentAccessRejected(
}
textBody, htmlBody, err = renderEmail(trustCenterDocumentAccessRejectedTextTemplate, trustCenterDocumentAccessRejectedHTMLTemplate, data)
return fmt.Sprintf(subjectTrustCenterAccess, organizationName), textBody, htmlBody, err
return fmt.Sprintf(subjectTrustCenterDocumentAccessRejected, organizationName), textBody, htmlBody, err
}
func renderEmail(textTemplate *texttemplate.Template, htmlTemplate *htmltemplate.Template, data any) (textBody string, htmlBody *string, err error) {

View File

@@ -111,53 +111,6 @@ LIMIT 1;
return nil
}
func (f *Files) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
fileIDs []gid.GID,
) error {
q := `
SELECT
id,
organization_id,
bucket_name,
mime_type,
file_name,
file_key,
file_size,
created_at,
updated_at,
deleted_at
FROM
files
WHERE
%s
AND id = ANY(@file_ids)
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"file_ids": fileIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query file: %w", err)
}
defer rows.Close()
files, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[File])
if err != nil {
return fmt.Errorf("cannot collect file: %w", err)
}
*f = files
return nil
}
func (f File) Insert(
ctx context.Context,
conn pg.Conn,

View File

@@ -110,8 +110,7 @@ FROM
reports
WHERE
%s
AND id = ANY(@report_ids)
LIMIT 1;
AND id = ANY(@report_ids);
`
q = fmt.Sprintf(q, scope.SQLFragment())

View File

@@ -96,6 +96,52 @@ LIMIT 1;
return nil
}
func (f *TrustCenterFiles) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
trustCenterFileIDs []gid.GID,
) error {
q := `
SELECT
id,
organization_id,
bucket_name,
mime_type,
file_name,
file_key,
file_size,
created_at,
updated_at,
deleted_at
FROM
files
WHERE
%s
AND id = ANY(@ids);
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"ids": trustCenterFileIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query file: %w", err)
}
defer rows.Close()
files, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TrustCenterFile])
if err != nil {
return fmt.Errorf("cannot collect file: %w", err)
}
*f = files
return nil
}
func (t TrustCenterFile) Insert(
ctx context.Context,
conn pg.Conn,
@@ -322,7 +368,7 @@ FROM
trust_center_files
WHERE
%s
%s
AND %s
AND organization_id = @organization_id
ORDER BY
created_at DESC

View File

@@ -187,8 +187,13 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
if strings.HasPrefix(action.ActionID, "handle_") {
// action value is the select option value. <accept|reject>-<ID>
params := strings.Split(action.SelectedOption.Value, "/")
statusAction = params[0]
if len(params) < 2 {
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: "invalid selected option format"})
return
}
statusAction = params[0]
gID, err = gid.ParseGID(params[1])
if err != nil {
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: "invalid ID"})

View File

@@ -667,13 +667,13 @@ func (s *TrustCenterAccessService) sendDocumentAccessRejectedEmail(
fileNames = append(fileNames, r.Filename)
}
}
var files coredata.Files
var files coredata.TrustCenterFiles
if len(fileIDs) > 0 {
if err := files.LoadByIDs(ctx, tx, s.svc.scope, fileIDs); err != nil {
return fmt.Errorf("cannot load files by IDs: %w", err)
}
for _, f := range files {
fileNames = append(fileNames, f.FileName)
fileNames = append(fileNames, f.Name)
}
}