Add reject button + email on trust center access request

Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-05 20:40:42 +04:00
parent 306675cd07
commit c8471cd48d
14 changed files with 3963 additions and 58 deletions

View File

@@ -132,23 +132,23 @@ func (p *Document) LoadByIDWithFilter(
filter *DocumentFilter,
) error {
q := `
SELECT
id,
organization_id,
owner_id,
title,
document_type,
classification,
current_published_version,
trust_center_visibility,
created_at,
updated_at
FROM
documents
WHERE
%s
AND deleted_at IS NULL
AND id = @document_id
SELECT
id,
organization_id,
owner_id,
title,
document_type,
classification,
current_published_version,
trust_center_visibility,
created_at,
updated_at
FROM
documents
WHERE
%s
AND deleted_at IS NULL
AND id = @document_id
AND %s
LIMIT 1;
`
@@ -178,6 +178,52 @@ LIMIT 1;
return nil
}
func (p *Documents) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
documentIDs []gid.GID,
) error {
q := `
SELECT
id,
organization_id,
owner_id,
title,
document_type,
classification,
current_published_version,
trust_center_visibility,
created_at,
updated_at
FROM
documents
WHERE
%s
AND deleted_at IS NULL
AND id IN (SELECT id FROM UNNEST(@document_ids::text[]) AS t(id));;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"document_ids": documentIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query documents: %w", err)
}
documents, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Document])
if err != nil {
return fmt.Errorf("cannot collect documents: %w", err)
}
*p = documents
return nil
}
func (p *Documents) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,

View File

@@ -111,6 +111,53 @@ 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 (SELECT id FROM UNNEST(@file_ids::text[]) AS t(id))
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

@@ -16,6 +16,7 @@ package coredata
import (
"context"
"errors"
"fmt"
"maps"
"time"
@@ -77,6 +78,10 @@ LIMIT 1;
report, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Report])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return &ErrDocumentNotFound{Identifier: reportID.String()}
}
return fmt.Errorf("cannot collect report: %w", err)
}
@@ -85,6 +90,50 @@ LIMIT 1;
return nil
}
func (r *Reports) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
reportIDs []gid.GID,
) error {
q := `
SELECT
id,
organization_id,
object_key,
mime_type,
filename,
size,
created_at,
updated_at
FROM
reports
WHERE
%s
AND id IN (SELECT id FROM UNNEST(@report_ids::text[]) AS t(id))
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"report_ids": reportIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query report: %w", err)
}
reports, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Report])
if err != nil {
return fmt.Errorf("cannot collect reports: %w", err)
}
*r = reports
return nil
}
func (r *Report) Insert(
ctx context.Context,
conn pg.Conn,

View File

@@ -688,6 +688,37 @@ WHERE
return nil
}
func DeleteByDocumentIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
trustCenterAccessID gid.GID,
documentIDs []gid.GID,
) error {
q := `
DELETE FROM trust_center_document_accesses
WHERE
%s
AND trust_center_access_id = @trust_center_access_id
AND document_id = ANY(@document_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"trust_center_access_id": trustCenterAccessID,
"document_ids": documentIDs,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot delete trust center document accesses by document IDs: %w", err)
}
return nil
}
func ActivateByReportIDs(
ctx context.Context,
conn pg.Conn,
@@ -722,6 +753,37 @@ WHERE
return nil
}
func DeleteByReportIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
trustCenterAccessID gid.GID,
reportIDs []gid.GID,
) error {
q := `
DELETE FROM trust_center_document_accesses
WHERE
%s
AND trust_center_access_id = @trust_center_access_id
AND report_id = ANY(@report_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"trust_center_access_id": trustCenterAccessID,
"report_ids": reportIDs,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot delete trust center document accesses by report IDs: %w", err)
}
return nil
}
func (tcdas TrustCenterDocumentAccesses) BulkInsertDocumentAccesses(
ctx context.Context,
conn pg.Conn,
@@ -914,6 +976,37 @@ WHERE
return nil
}
func DeleteByTrustCenterFileIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
trustCenterAccessID gid.GID,
trustCenterFileIDs []gid.GID,
) error {
q := `
DELETE FROM trust_center_document_accesses
WHERE
%s
AND trust_center_access_id = @trust_center_access_id
AND trust_center_file_id = ANY(@trust_center_file_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"trust_center_access_id": trustCenterAccessID,
"trust_center_file_ids": trustCenterFileIDs,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot delete trust center document accesses by trust center file IDs: %w", err)
}
return nil
}
func (tcdas TrustCenterDocumentAccesses) BulkInsertTrustCenterFileAccesses(
ctx context.Context,
conn pg.Conn,