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 ( const (
logoURLPath = "/logos/probo.png" logoURLPath = "/logos/probo.png"
subjectConfirmEmail = "Confirm your email address" subjectConfirmEmail = "Confirm your email address"
subjectPasswordReset = "Reset your password" subjectPasswordReset = "Reset your password"
subjectInvitation = "Invitation to join %s on Probo" subjectInvitation = "Invitation to join %s on Probo"
subjectDocumentSigning = "Action Required – Please review and sign %s compliance documents" subjectDocumentSigning = "Action Required – Please review and sign %s compliance documents"
subjectDocumentExport = "Your document export is ready" subjectDocumentExport = "Your document export is ready"
subjectFrameworkExport = "Your framework 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 ( var (
@@ -192,7 +193,7 @@ func RenderTrustCenterDocumentAccessRejected(
} }
textBody, htmlBody, err = renderEmail(trustCenterDocumentAccessRejectedTextTemplate, trustCenterDocumentAccessRejectedHTMLTemplate, data) 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) { 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 { ) error {
q := ` q := `
SELECT SELECT
id, id,
organization_id, organization_id,
owner_id, owner_id,
title, title,
document_type, document_type,
classification, classification,
current_published_version, current_published_version,
trust_center_visibility, trust_center_visibility,
created_at, created_at,
updated_at updated_at
FROM FROM
documents documents
WHERE WHERE
%s %s
AND deleted_at IS NULL AND deleted_at IS NULL
AND id = ANY(@document_ids) AND id = ANY(@document_ids)
` `
q = fmt.Sprintf(q, scope.SQLFragment()) q = fmt.Sprintf(q, scope.SQLFragment())

View File

@@ -111,53 +111,6 @@ LIMIT 1;
return nil 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( func (f File) Insert(
ctx context.Context, ctx context.Context,
conn pg.Conn, conn pg.Conn,

View File

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

View File

@@ -96,6 +96,52 @@ LIMIT 1;
return nil 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( func (t TrustCenterFile) Insert(
ctx context.Context, ctx context.Context,
conn pg.Conn, conn pg.Conn,
@@ -322,7 +368,7 @@ FROM
trust_center_files trust_center_files
WHERE WHERE
%s %s
%s AND %s
AND organization_id = @organization_id AND organization_id = @organization_id
ORDER BY ORDER BY
created_at DESC created_at DESC

View File

@@ -187,8 +187,13 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
if strings.HasPrefix(action.ActionID, "handle_") { if strings.HasPrefix(action.ActionID, "handle_") {
// action value is the select option value. <accept|reject>-<ID> // action value is the select option value. <accept|reject>-<ID>
params := strings.Split(action.SelectedOption.Value, "/") 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]) gID, err = gid.ParseGID(params[1])
if err != nil { if err != nil {
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: "invalid ID"}) 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) fileNames = append(fileNames, r.Filename)
} }
} }
var files coredata.Files var files coredata.TrustCenterFiles
if len(fileIDs) > 0 { if len(fileIDs) > 0 {
if err := files.LoadByIDs(ctx, tx, s.svc.scope, fileIDs); err != nil { if err := files.LoadByIDs(ctx, tx, s.svc.scope, fileIDs); err != nil {
return fmt.Errorf("cannot load files by IDs: %w", err) return fmt.Errorf("cannot load files by IDs: %w", err)
} }
for _, f := range files { for _, f := range files {
fileNames = append(fileNames, f.FileName) fileNames = append(fileNames, f.Name)
} }
} }