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

@@ -30,13 +30,14 @@ var Templates embed.FS
const (
logoURLPath = "/logos/probo.png"
subjectConfirmEmail = "Confirm your email address"
subjectPasswordReset = "Reset your password"
subjectInvitation = "Invitation to join %s on Probo"
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"
subjectConfirmEmail = "Confirm your email address"
subjectPasswordReset = "Reset your password"
subjectInvitation = "Invitation to join %s on Probo"
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 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

@@ -186,22 +186,22 @@ func (p *Documents) LoadByIDs(
) error {
q := `
SELECT
id,
organization_id,
owner_id,
title,
document_type,
classification,
current_published_version,
trust_center_visibility,
created_at,
updated_at
id,
organization_id,
owner_id,
title,
document_type,
classification,
current_published_version,
trust_center_visibility,
created_at,
updated_at
FROM
documents
documents
WHERE
%s
AND deleted_at IS NULL
AND id = ANY(@document_ids)
%s
AND deleted_at IS NULL
AND id = ANY(@document_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())

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

@@ -50,19 +50,19 @@ func (r *Report) LoadByID(
) error {
q := `
SELECT
id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
FROM
reports
reports
WHERE
%s
AND id = @report_id
%s
AND id = @report_id
LIMIT 1;
`
@@ -98,20 +98,19 @@ func (r *Reports) LoadByIDs(
) error {
q := `
SELECT
id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
FROM
reports
reports
WHERE
%s
AND id = ANY(@report_ids)
LIMIT 1;
%s
AND id = ANY(@report_ids);
`
q = fmt.Sprintf(q, scope.SQLFragment())
@@ -141,25 +140,25 @@ func (r *Report) Insert(
) error {
q := `
INSERT INTO reports (
id,
tenant_id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
id,
tenant_id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
) VALUES (
@id,
@tenant_id,
@organization_id,
@object_key,
@mime_type,
@filename,
@size,
@created_at,
@updated_at
@id,
@tenant_id,
@organization_id,
@object_key,
@mime_type,
@filename,
@size,
@created_at,
@updated_at
)
`
@@ -191,14 +190,14 @@ func (r *Report) Update(
q := `
UPDATE reports
SET
object_key = @object_key,
mime_type = @mime_type,
filename = @filename,
size = @size,
updated_at = @updated_at
object_key = @object_key,
mime_type = @mime_type,
filename = @filename,
size = @size,
updated_at = @updated_at
WHERE
%s
AND id = @id
%s
AND id = @id
`
q = fmt.Sprintf(q, scope.SQLFragment())
@@ -229,8 +228,8 @@ func (r *Report) Delete(
q := `
DELETE FROM reports
WHERE
%s
AND id = @id
%s
AND id = @id
`
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)
}
}