diff --git a/packages/emails/emails.go b/packages/emails/emails.go index 3e10807c4..39024d830 100644 --- a/packages/emails/emails.go +++ b/packages/emails/emails.go @@ -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) { diff --git a/pkg/coredata/document.go b/pkg/coredata/document.go index 148f89e60..52d9453ce 100644 --- a/pkg/coredata/document.go +++ b/pkg/coredata/document.go @@ -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()) diff --git a/pkg/coredata/file.go b/pkg/coredata/file.go index e2d4ca282..22c439a82 100644 --- a/pkg/coredata/file.go +++ b/pkg/coredata/file.go @@ -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, diff --git a/pkg/coredata/report.go b/pkg/coredata/report.go index 553f9c6c7..02b2fe465 100644 --- a/pkg/coredata/report.go +++ b/pkg/coredata/report.go @@ -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()) diff --git a/pkg/coredata/trust_center_file.go b/pkg/coredata/trust_center_file.go index 74546a2f3..af9296ed4 100644 --- a/pkg/coredata/trust_center_file.go +++ b/pkg/coredata/trust_center_file.go @@ -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 diff --git a/pkg/server/api/trust/v1/slack_handler.go b/pkg/server/api/trust/v1/slack_handler.go index bd651a92d..2a6edecef 100644 --- a/pkg/server/api/trust/v1/slack_handler.go +++ b/pkg/server/api/trust/v1/slack_handler.go @@ -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. - 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"}) diff --git a/pkg/trust/trust_center_access_service.go b/pkg/trust/trust_center_access_service.go index df1ed2b38..74b321593 100644 --- a/pkg/trust/trust_center_access_service.go +++ b/pkg/trust/trust_center_access_service.go @@ -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) } }