|
|
|
|
@@ -77,20 +77,20 @@ func (tcda *TrustCenterDocumentAccess) LoadByID(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND id = @access_id
|
|
|
|
|
%s
|
|
|
|
|
AND id = @access_id
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
@@ -126,21 +126,21 @@ func (tcda *TrustCenterDocumentAccess) LoadByTrustCenterAccessIDAndDocumentID(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND document_id = @document_id
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND document_id = @document_id
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
@@ -176,21 +176,21 @@ func (tcda *TrustCenterDocumentAccess) LoadByTrustCenterAccessIDAndReportID(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND report_id = @report_id
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND report_id = @report_id
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
@@ -224,27 +224,27 @@ func (tcda *TrustCenterDocumentAccess) Insert(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
INSERT INTO trust_center_document_accesses (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
) VALUES (
|
|
|
|
|
@id,
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
@document_id,
|
|
|
|
|
@report_id,
|
|
|
|
|
@trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status,
|
|
|
|
|
@created_at,
|
|
|
|
|
@updated_at
|
|
|
|
|
@id,
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
@document_id,
|
|
|
|
|
@report_id,
|
|
|
|
|
@trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status,
|
|
|
|
|
@created_at,
|
|
|
|
|
@updated_at
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
@@ -295,11 +295,11 @@ func (tcda *TrustCenterDocumentAccess) Update(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
UPDATE trust_center_document_accesses SET
|
|
|
|
|
status = @status::trust_center_document_access_status,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
status = @status::trust_center_document_access_status,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND id = @id
|
|
|
|
|
%s
|
|
|
|
|
AND id = @id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -327,8 +327,8 @@ func (tcda *TrustCenterDocumentAccess) Delete(
|
|
|
|
|
q := `
|
|
|
|
|
DELETE FROM trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND id = @id
|
|
|
|
|
%s
|
|
|
|
|
AND id = @id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -354,12 +354,12 @@ func (tcdas *TrustCenterDocumentAccesses) CountByTrustCenterAccessID(
|
|
|
|
|
) (int, error) {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
COUNT(id)
|
|
|
|
|
COUNT(id)
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -387,14 +387,14 @@ func (tcdas *TrustCenterDocumentAccesses) CountPendingRequestByTrustCenterAccess
|
|
|
|
|
) (int, error) {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
COUNT(id)
|
|
|
|
|
COUNT(id)
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND requested = true
|
|
|
|
|
AND status = 'REQUESTED'::trust_center_document_access_status
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND requested = true
|
|
|
|
|
AND status = 'REQUESTED'::trust_center_document_access_status
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -422,13 +422,13 @@ func (tcdas *TrustCenterDocumentAccesses) CountActiveByTrustCenterAccessID(
|
|
|
|
|
) (int, error) {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
COUNT(id)
|
|
|
|
|
COUNT(id)
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND status = 'GRANTED'::trust_center_document_access_status
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND status = 'GRANTED'::trust_center_document_access_status
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -457,92 +457,92 @@ func (tcdas *TrustCenterDocumentAccesses) LoadAvailableByTrustCenterAccessID(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
WITH organization AS (
|
|
|
|
|
SELECT tc.organization_id
|
|
|
|
|
FROM trust_center_accesses tca
|
|
|
|
|
INNER JOIN trust_centers tc ON tca.trust_center_id = tc.id
|
|
|
|
|
WHERE tca.tenant_id = @tenant_id
|
|
|
|
|
AND tca.id = @trust_center_access_id
|
|
|
|
|
SELECT tc.organization_id
|
|
|
|
|
FROM trust_center_accesses tca
|
|
|
|
|
INNER JOIN trust_centers tc ON tca.trust_center_id = tc.id
|
|
|
|
|
WHERE tca.tenant_id = @tenant_id
|
|
|
|
|
AND tca.id = @trust_center_access_id
|
|
|
|
|
),
|
|
|
|
|
tenant_organization AS (
|
|
|
|
|
SELECT o.id AS organization_id
|
|
|
|
|
FROM organizations o
|
|
|
|
|
WHERE %s
|
|
|
|
|
SELECT o.id AS organization_id
|
|
|
|
|
FROM organizations o
|
|
|
|
|
WHERE %s
|
|
|
|
|
),
|
|
|
|
|
all_items AS (
|
|
|
|
|
SELECT
|
|
|
|
|
d.id AS item_id,
|
|
|
|
|
d.id AS document_id,
|
|
|
|
|
NULL::text AS report_id,
|
|
|
|
|
NULL::text AS trust_center_file_id,
|
|
|
|
|
d.created_at AS item_created_at,
|
|
|
|
|
d.updated_at AS item_updated_at
|
|
|
|
|
FROM documents d, tenant_organization o
|
|
|
|
|
WHERE d.organization_id = o.organization_id
|
|
|
|
|
AND d.deleted_at IS NULL
|
|
|
|
|
AND d.trust_center_visibility = 'PRIVATE'::trust_center_visibility
|
|
|
|
|
SELECT
|
|
|
|
|
d.id AS item_id,
|
|
|
|
|
d.id AS document_id,
|
|
|
|
|
NULL::text AS report_id,
|
|
|
|
|
NULL::text AS trust_center_file_id,
|
|
|
|
|
d.created_at AS item_created_at,
|
|
|
|
|
d.updated_at AS item_updated_at
|
|
|
|
|
FROM documents d, tenant_organization o
|
|
|
|
|
WHERE d.organization_id = o.organization_id
|
|
|
|
|
AND d.deleted_at IS NULL
|
|
|
|
|
AND d.trust_center_visibility = 'PRIVATE'::trust_center_visibility
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
|
r.report_id AS item_id,
|
|
|
|
|
NULL::text AS document_id,
|
|
|
|
|
r.report_id AS report_id,
|
|
|
|
|
NULL::text AS trust_center_file_id,
|
|
|
|
|
r.created_at AS item_created_at,
|
|
|
|
|
r.updated_at AS item_updated_at
|
|
|
|
|
FROM audits r, tenant_organization o
|
|
|
|
|
WHERE r.organization_id = o.organization_id
|
|
|
|
|
AND r.trust_center_visibility = 'PRIVATE'::trust_center_visibility
|
|
|
|
|
AND r.report_id IS NOT NULL
|
|
|
|
|
SELECT
|
|
|
|
|
r.report_id AS item_id,
|
|
|
|
|
NULL::text AS document_id,
|
|
|
|
|
r.report_id AS report_id,
|
|
|
|
|
NULL::text AS trust_center_file_id,
|
|
|
|
|
r.created_at AS item_created_at,
|
|
|
|
|
r.updated_at AS item_updated_at
|
|
|
|
|
FROM audits r, tenant_organization o
|
|
|
|
|
WHERE r.organization_id = o.organization_id
|
|
|
|
|
AND r.trust_center_visibility = 'PRIVATE'::trust_center_visibility
|
|
|
|
|
AND r.report_id IS NOT NULL
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
|
tcf.id AS item_id,
|
|
|
|
|
NULL::text AS document_id,
|
|
|
|
|
NULL::text AS report_id,
|
|
|
|
|
tcf.id AS trust_center_file_id,
|
|
|
|
|
tcf.created_at AS item_created_at,
|
|
|
|
|
tcf.updated_at AS item_updated_at
|
|
|
|
|
FROM trust_center_files tcf, tenant_organization o
|
|
|
|
|
WHERE tcf.organization_id = o.organization_id
|
|
|
|
|
AND (
|
|
|
|
|
tcf.trust_center_visibility = 'PRIVATE'::trust_center_visibility
|
|
|
|
|
OR tcf.trust_center_visibility = 'NONE'::trust_center_visibility
|
|
|
|
|
)
|
|
|
|
|
SELECT
|
|
|
|
|
tcf.id AS item_id,
|
|
|
|
|
NULL::text AS document_id,
|
|
|
|
|
NULL::text AS report_id,
|
|
|
|
|
tcf.id AS trust_center_file_id,
|
|
|
|
|
tcf.created_at AS item_created_at,
|
|
|
|
|
tcf.updated_at AS item_updated_at
|
|
|
|
|
FROM trust_center_files tcf, tenant_organization o
|
|
|
|
|
WHERE tcf.organization_id = o.organization_id
|
|
|
|
|
AND (
|
|
|
|
|
tcf.trust_center_visibility = 'PRIVATE'::trust_center_visibility
|
|
|
|
|
OR tcf.trust_center_visibility = 'NONE'::trust_center_visibility
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
final_items AS (
|
|
|
|
|
SELECT
|
|
|
|
|
COALESCE(tcda.id, ai.item_id) AS id,
|
|
|
|
|
tcda.tenant_id,
|
|
|
|
|
(SELECT organization_id FROM organization) AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
ai.document_id,
|
|
|
|
|
ai.report_id,
|
|
|
|
|
ai.trust_center_file_id,
|
|
|
|
|
COALESCE(tcda.status, 'REQUESTED'::trust_center_document_access_status) AS status,
|
|
|
|
|
COALESCE(tcda.created_at, ai.item_created_at) AS created_at,
|
|
|
|
|
COALESCE(tcda.updated_at, ai.item_updated_at) AS updated_at
|
|
|
|
|
COALESCE(tcda.id, ai.item_id) AS id,
|
|
|
|
|
tcda.tenant_id,
|
|
|
|
|
(SELECT organization_id FROM organization) AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
ai.document_id,
|
|
|
|
|
ai.report_id,
|
|
|
|
|
ai.trust_center_file_id,
|
|
|
|
|
COALESCE(tcda.status, 'REQUESTED'::trust_center_document_access_status) AS status,
|
|
|
|
|
COALESCE(tcda.created_at, ai.item_created_at) AS created_at,
|
|
|
|
|
COALESCE(tcda.updated_at, ai.item_updated_at) AS updated_at
|
|
|
|
|
FROM all_items ai
|
|
|
|
|
LEFT JOIN trust_center_document_accesses tcda ON (
|
|
|
|
|
tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND (
|
|
|
|
|
(tcda.document_id = ai.document_id AND ai.document_id IS NOT NULL)
|
|
|
|
|
OR (tcda.report_id = ai.report_id AND ai.report_id IS NOT NULL)
|
|
|
|
|
OR (tcda.trust_center_file_id = ai.trust_center_file_id AND ai.trust_center_file_id IS NOT NULL)
|
|
|
|
|
)
|
|
|
|
|
tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND (
|
|
|
|
|
(tcda.document_id = ai.document_id AND ai.document_id IS NOT NULL)
|
|
|
|
|
OR (tcda.report_id = ai.report_id AND ai.report_id IS NOT NULL)
|
|
|
|
|
OR (tcda.trust_center_file_id = ai.trust_center_file_id AND ai.trust_center_file_id IS NOT NULL)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM final_items
|
|
|
|
|
WHERE %s
|
|
|
|
|
`
|
|
|
|
|
@@ -578,20 +578,20 @@ func (tcdas *TrustCenterDocumentAccesses) LoadAllByTrustCenterAccessID(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
ORDER BY id ASC
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
@@ -629,9 +629,9 @@ func GrantByDocumentIDs(
|
|
|
|
|
UPDATE trust_center_document_accesses
|
|
|
|
|
SET status = 'GRANTED'::trust_center_document_access_status, updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND document_id = ANY(@document_ids)
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND document_id = ANY(@document_ids)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -662,15 +662,15 @@ func RejectOrRevokeByDocumentIDs(
|
|
|
|
|
q := `
|
|
|
|
|
UPDATE trust_center_document_accesses
|
|
|
|
|
SET
|
|
|
|
|
status = CASE
|
|
|
|
|
WHEN status = 'GRANTED'::trust_center_document_access_status THEN 'REVOKED'::trust_center_document_access_status
|
|
|
|
|
ELSE 'REJECTED'::trust_center_document_access_status
|
|
|
|
|
END,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
status = CASE
|
|
|
|
|
WHEN status = 'GRANTED'::trust_center_document_access_status THEN 'REVOKED'::trust_center_document_access_status
|
|
|
|
|
ELSE 'REJECTED'::trust_center_document_access_status
|
|
|
|
|
END,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND document_id = ANY(@document_ids)
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND document_id = ANY(@document_ids)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -702,9 +702,9 @@ func GrantByReportIDs(
|
|
|
|
|
UPDATE trust_center_document_accesses
|
|
|
|
|
SET status = 'GRANTED'::trust_center_document_access_status, updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND report_id = ANY(@report_ids)
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND report_id = ANY(@report_ids)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -735,15 +735,15 @@ func RejectOrRevokeByReportIDs(
|
|
|
|
|
q := `
|
|
|
|
|
UPDATE trust_center_document_accesses
|
|
|
|
|
SET
|
|
|
|
|
status = CASE
|
|
|
|
|
WHEN status = 'GRANTED'::trust_center_document_access_status THEN 'REVOKED'::trust_center_document_access_status
|
|
|
|
|
ELSE 'REJECTED'::trust_center_document_access_status
|
|
|
|
|
END,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
status = CASE
|
|
|
|
|
WHEN status = 'GRANTED'::trust_center_document_access_status THEN 'REVOKED'::trust_center_document_access_status
|
|
|
|
|
ELSE 'REJECTED'::trust_center_document_access_status
|
|
|
|
|
END,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND report_id = ANY(@report_ids)
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND report_id = ANY(@report_ids)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
|
|
|
@@ -778,51 +778,51 @@ func (tcdas TrustCenterDocumentAccesses) MergeDocumentAccesses(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
WITH data AS (
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM json_to_recordset(@data)
|
|
|
|
|
AS t(
|
|
|
|
|
id text,
|
|
|
|
|
status trust_center_document_access_status
|
|
|
|
|
)
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM json_to_recordset(@data)
|
|
|
|
|
AS t(
|
|
|
|
|
id text,
|
|
|
|
|
status trust_center_document_access_status
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
MERGE INTO trust_center_document_accesses AS tcda
|
|
|
|
|
USING data
|
|
|
|
|
ON data.id = tcda.document_id
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
ON data.id = tcda.document_id
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
WHEN MATCHED
|
|
|
|
|
THEN UPDATE SET status = data.status, updated_at = @now::timestamptz
|
|
|
|
|
THEN UPDATE SET status = data.status, updated_at = @now::timestamptz
|
|
|
|
|
WHEN NOT MATCHED BY SOURCE
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND tcda.document_id IS NOT NULL
|
|
|
|
|
THEN DELETE
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND tcda.document_id IS NOT NULL
|
|
|
|
|
THEN DELETE
|
|
|
|
|
WHEN NOT MATCHED
|
|
|
|
|
THEN INSERT (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
data.id,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
data.status,
|
|
|
|
|
@now::timestamptz,
|
|
|
|
|
@now::timestamptz
|
|
|
|
|
)
|
|
|
|
|
THEN INSERT (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
data.id,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
data.status,
|
|
|
|
|
@now::timestamptz,
|
|
|
|
|
@now::timestamptz
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
args := pgx.StrictNamedArgs{
|
|
|
|
|
@@ -857,29 +857,29 @@ func (tcdas TrustCenterDocumentAccesses) BulkInsertDocumentAccesses(
|
|
|
|
|
|
|
|
|
|
q := `
|
|
|
|
|
WITH document_access_data AS (
|
|
|
|
|
SELECT
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
|
|
|
|
@tenant_id AS tenant_id,
|
|
|
|
|
@organization_id AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
unnest(@document_ids::text[]) AS document_id,
|
|
|
|
|
null::text AS report_id,
|
|
|
|
|
null::text AS trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status AS status,
|
|
|
|
|
@created_at::timestamptz AS created_at,
|
|
|
|
|
@updated_at::timestamptz AS updated_at
|
|
|
|
|
SELECT
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
|
|
|
|
@tenant_id AS tenant_id,
|
|
|
|
|
@organization_id AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
unnest(@document_ids::text[]) AS document_id,
|
|
|
|
|
null::text AS report_id,
|
|
|
|
|
null::text AS trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status AS status,
|
|
|
|
|
@created_at::timestamptz AS created_at,
|
|
|
|
|
@updated_at::timestamptz AS updated_at
|
|
|
|
|
)
|
|
|
|
|
INSERT INTO trust_center_document_accesses (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
SELECT * FROM document_access_data
|
|
|
|
|
ON CONFLICT DO NOTHING
|
|
|
|
|
@@ -913,51 +913,51 @@ func (tcdas TrustCenterDocumentAccesses) MergeReportAccesses(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
WITH data AS (
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM json_to_recordset(@data)
|
|
|
|
|
AS t(
|
|
|
|
|
id text,
|
|
|
|
|
status trust_center_document_access_status
|
|
|
|
|
)
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM json_to_recordset(@data)
|
|
|
|
|
AS t(
|
|
|
|
|
id text,
|
|
|
|
|
status trust_center_document_access_status
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
MERGE INTO trust_center_document_accesses AS tcda
|
|
|
|
|
USING data
|
|
|
|
|
ON data.id = tcda.report_id
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
ON data.id = tcda.report_id
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
WHEN MATCHED
|
|
|
|
|
THEN UPDATE SET status = data.status, updated_at = @now::timestamptz
|
|
|
|
|
THEN UPDATE SET status = data.status, updated_at = @now::timestamptz
|
|
|
|
|
WHEN NOT MATCHED BY SOURCE
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND tcda.report_id IS NOT NULL
|
|
|
|
|
THEN DELETE
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND tcda.report_id IS NOT NULL
|
|
|
|
|
THEN DELETE
|
|
|
|
|
WHEN NOT MATCHED
|
|
|
|
|
THEN INSERT (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
NULL,
|
|
|
|
|
data.id,
|
|
|
|
|
NULL,
|
|
|
|
|
data.status,
|
|
|
|
|
@now::timestamptz,
|
|
|
|
|
@now::timestamptz
|
|
|
|
|
)
|
|
|
|
|
THEN INSERT (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
NULL,
|
|
|
|
|
data.id,
|
|
|
|
|
NULL,
|
|
|
|
|
data.status,
|
|
|
|
|
@now::timestamptz,
|
|
|
|
|
@now::timestamptz
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
args := pgx.StrictNamedArgs{
|
|
|
|
|
@@ -992,29 +992,29 @@ func (tcdas TrustCenterDocumentAccesses) BulkInsertReportAccesses(
|
|
|
|
|
|
|
|
|
|
q := `
|
|
|
|
|
WITH report_access_data AS (
|
|
|
|
|
SELECT
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
|
|
|
|
@tenant_id AS tenant_id,
|
|
|
|
|
@organization_id AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
null::text AS document_id,
|
|
|
|
|
unnest(@report_ids::text[]) AS report_id,
|
|
|
|
|
null::text AS trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status AS status,
|
|
|
|
|
@created_at::timestamptz AS created_at,
|
|
|
|
|
@updated_at::timestamptz AS updated_at
|
|
|
|
|
SELECT
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
|
|
|
|
@tenant_id AS tenant_id,
|
|
|
|
|
@organization_id AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
null::text AS document_id,
|
|
|
|
|
unnest(@report_ids::text[]) AS report_id,
|
|
|
|
|
null::text AS trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status AS status,
|
|
|
|
|
@created_at::timestamptz AS created_at,
|
|
|
|
|
@updated_at::timestamptz AS updated_at
|
|
|
|
|
)
|
|
|
|
|
INSERT INTO trust_center_document_accesses (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
SELECT * FROM report_access_data
|
|
|
|
|
ON CONFLICT DO NOTHING
|
|
|
|
|
@@ -1047,20 +1047,20 @@ func (tcda *TrustCenterDocumentAccess) LoadByTrustCenterAccessIDAndTrustCenterFi
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
SELECT
|
|
|
|
|
id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
trust_center_document_accesses
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND trust_center_file_id = @trust_center_file_id
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND trust_center_file_id = @trust_center_file_id
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
@@ -1099,9 +1099,9 @@ func GrantByTrustCenterFileIDs(
|
|
|
|
|
UPDATE trust_center_document_accesses
|
|
|
|
|
SET status = 'GRANTED'::trust_center_document_access_status, updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND trust_center_file_id = ANY(@trust_center_file_ids)
|
|
|
|
|
%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())
|
|
|
|
|
@@ -1132,15 +1132,15 @@ func RejectOrRevokeByTrustCenterFileIDs(
|
|
|
|
|
q := `
|
|
|
|
|
UPDATE trust_center_document_accesses
|
|
|
|
|
SET
|
|
|
|
|
status = CASE
|
|
|
|
|
WHEN status = 'GRANTED'::trust_center_document_access_status THEN 'REVOKED'::trust_center_document_access_status
|
|
|
|
|
ELSE 'REJECTED'::trust_center_document_access_status
|
|
|
|
|
END,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
status = CASE
|
|
|
|
|
WHEN status = 'GRANTED'::trust_center_document_access_status THEN 'REVOKED'::trust_center_document_access_status
|
|
|
|
|
ELSE 'REJECTED'::trust_center_document_access_status
|
|
|
|
|
END,
|
|
|
|
|
updated_at = @updated_at
|
|
|
|
|
WHERE
|
|
|
|
|
%s
|
|
|
|
|
AND trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND trust_center_file_id = ANY(@trust_center_file_ids)
|
|
|
|
|
%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())
|
|
|
|
|
@@ -1170,51 +1170,51 @@ func (tcdas TrustCenterDocumentAccesses) MergeTrustCenterFileAccesses(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
WITH data AS (
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM json_to_recordset(@data)
|
|
|
|
|
AS t(
|
|
|
|
|
id text,
|
|
|
|
|
status trust_center_document_access_status
|
|
|
|
|
)
|
|
|
|
|
SELECT
|
|
|
|
|
t.*
|
|
|
|
|
FROM json_to_recordset(@data)
|
|
|
|
|
AS t(
|
|
|
|
|
id text,
|
|
|
|
|
status trust_center_document_access_status
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
MERGE INTO trust_center_document_accesses AS tcda
|
|
|
|
|
USING data
|
|
|
|
|
ON data.id = tcda.trust_center_file_id
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
ON data.id = tcda.trust_center_file_id
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
WHEN MATCHED
|
|
|
|
|
THEN UPDATE SET status = data.status, updated_at = @now::timestamptz
|
|
|
|
|
THEN UPDATE SET status = data.status, updated_at = @now::timestamptz
|
|
|
|
|
WHEN NOT MATCHED BY SOURCE
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND tcda.trust_center_file_id IS NOT NULL
|
|
|
|
|
THEN DELETE
|
|
|
|
|
AND tcda.tenant_id = @tenant_id
|
|
|
|
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
|
|
|
|
AND tcda.trust_center_file_id IS NOT NULL
|
|
|
|
|
THEN DELETE
|
|
|
|
|
WHEN NOT MATCHED
|
|
|
|
|
THEN INSERT (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
data.id,
|
|
|
|
|
data.status,
|
|
|
|
|
@now::timestamptz,
|
|
|
|
|
@now::timestamptz
|
|
|
|
|
)
|
|
|
|
|
THEN INSERT (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
VALUES (
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
|
|
|
|
@tenant_id,
|
|
|
|
|
@organization_id,
|
|
|
|
|
@trust_center_access_id,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
data.id,
|
|
|
|
|
data.status,
|
|
|
|
|
@now::timestamptz,
|
|
|
|
|
@now::timestamptz
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
args := pgx.StrictNamedArgs{
|
|
|
|
|
@@ -1245,29 +1245,29 @@ func (tcdas TrustCenterDocumentAccesses) BulkInsertTrustCenterFileAccesses(
|
|
|
|
|
) error {
|
|
|
|
|
q := `
|
|
|
|
|
WITH trust_center_file_access_data AS (
|
|
|
|
|
SELECT
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
|
|
|
|
@tenant_id AS tenant_id,
|
|
|
|
|
@organization_id AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
null::text AS document_id,
|
|
|
|
|
null::text AS report_id,
|
|
|
|
|
unnest(@trust_center_file_ids::text[]) AS trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status AS status,
|
|
|
|
|
@created_at::timestamptz AS created_at,
|
|
|
|
|
@updated_at::timestamptz AS updated_at
|
|
|
|
|
SELECT
|
|
|
|
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
|
|
|
|
@tenant_id AS tenant_id,
|
|
|
|
|
@organization_id AS organization_id,
|
|
|
|
|
@trust_center_access_id AS trust_center_access_id,
|
|
|
|
|
null::text AS document_id,
|
|
|
|
|
null::text AS report_id,
|
|
|
|
|
unnest(@trust_center_file_ids::text[]) AS trust_center_file_id,
|
|
|
|
|
@status::trust_center_document_access_status AS status,
|
|
|
|
|
@created_at::timestamptz AS created_at,
|
|
|
|
|
@updated_at::timestamptz AS updated_at
|
|
|
|
|
)
|
|
|
|
|
INSERT INTO trust_center_document_accesses (
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
id,
|
|
|
|
|
tenant_id,
|
|
|
|
|
organization_id,
|
|
|
|
|
trust_center_access_id,
|
|
|
|
|
document_id,
|
|
|
|
|
report_id,
|
|
|
|
|
trust_center_file_id,
|
|
|
|
|
status,
|
|
|
|
|
created_at,
|
|
|
|
|
updated_at
|
|
|
|
|
)
|
|
|
|
|
SELECT * FROM trust_center_file_access_data
|
|
|
|
|
ON CONFLICT DO NOTHING
|
|
|
|
|
|