Fix merge and handle display of unpersisted trusct center document access status
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -110,6 +110,7 @@ export const loadTrustCenterAccessDocumentAccessesQuery = graphql`
|
||||
availableDocumentAccesses(first: 100, orderBy: { field: CREATED_AT, direction: DESC }) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
active
|
||||
requested
|
||||
status
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<bf1055f4f2fe5eb7a428afdd30f4f672>>
|
||||
* @generated SignedSource<<3d9ccb3632d0373c627c87f6e6585673>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -25,6 +25,7 @@ export type TrustCenterAccessGraphLoadDocumentAccessesQuery$data = {
|
||||
readonly id: string;
|
||||
readonly title: string;
|
||||
} | null | undefined;
|
||||
readonly id: string;
|
||||
readonly report: {
|
||||
readonly audit: {
|
||||
readonly framework: {
|
||||
@@ -214,6 +215,7 @@ return {
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v4/*: any*/),
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/),
|
||||
@@ -325,6 +327,7 @@ return {
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v4/*: any*/),
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/),
|
||||
@@ -387,16 +390,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "a764b27e48509dfdf4a7a03c5f00ea59",
|
||||
"cacheID": "a590c829b3c88e4fa4fe146771c723b9",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterAccessGraphLoadDocumentAccessesQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustCenterAccessGraphLoadDocumentAccessesQuery(\n $accessId: ID!\n) {\n node(id: $accessId) {\n __typename\n ... on TrustCenterAccess {\n id\n availableDocumentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n active\n requested\n status\n document {\n id\n title\n documentType\n }\n report {\n id\n filename\n audit {\n id\n framework {\n name\n id\n }\n }\n }\n trustCenterFile {\n id\n name\n category\n }\n }\n }\n }\n }\n id\n }\n}\n"
|
||||
"text": "query TrustCenterAccessGraphLoadDocumentAccessesQuery(\n $accessId: ID!\n) {\n node(id: $accessId) {\n __typename\n ... on TrustCenterAccess {\n id\n availableDocumentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n requested\n status\n document {\n id\n title\n documentType\n }\n report {\n id\n filename\n audit {\n id\n framework {\n name\n id\n }\n }\n }\n trustCenterFile {\n id\n name\n category\n }\n }\n }\n }\n }\n id\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "f40dbb607d0bd5adb85b0a8377b96b32";
|
||||
(node as any).hash = "1145528ffc9c1576b8e5dd6d58e64a9c";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -85,7 +85,9 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
||||
setDocumentAccesses((prev) => prev.map(element => ({...element, status: "GRANTED"})))
|
||||
}, [])
|
||||
const handleRejectOrRevokeAllDocumentAccess = useCallback(() => {
|
||||
setDocumentAccesses((prev) => prev.map(element => ({...element, status: initialStatusByID[element.id] === "GRANTED" ? "REVOKED" : "REJECTED"})))
|
||||
setDocumentAccesses((prev) => prev
|
||||
.map(element => ({...element, status: initialStatusByID[element.id] === "GRANTED" ? "REVOKED" : "REJECTED"}))
|
||||
)
|
||||
}, [initialStatusByID])
|
||||
|
||||
const editSchema = z.object({
|
||||
@@ -102,21 +104,23 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
||||
});
|
||||
|
||||
const handleSubmit = editForm.handleSubmit(async (data) => {
|
||||
const documents: {id: string, status: TrustCenterDocumentAccessStatus}[] = []
|
||||
const reports: {id: string, status: TrustCenterDocumentAccessStatus}[] = []
|
||||
const trustCenterFiles: {id: string, status: TrustCenterDocumentAccessStatus}[] = [];
|
||||
const documents: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||
const reports: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||
const trustCenterFiles: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||
|
||||
for (const docAccess of documentAccesses) {
|
||||
switch (docAccess.type) {
|
||||
case "document":
|
||||
documents.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "report":
|
||||
reports.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "file":
|
||||
trustCenterFiles.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
if (docAccess.persisted || docAccess.status !== "REQUESTED") {
|
||||
switch (docAccess.type) {
|
||||
case "document":
|
||||
documents.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "report":
|
||||
reports.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "file":
|
||||
trustCenterFiles.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { TrustCenterDocumentAccessStatus } from "@probo/coredata";
|
||||
import { getTrustCenterDocumentAccessStatusBadgeVariant, type TrustCenterDocumentAccessInfo } from "@probo/helpers";
|
||||
import { getTrustCenterDocumentAccessStatusBadgeVariant, getTrustCenterDocumentAccessStatusLabel, type TrustCenterDocumentAccessInfo } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Badge, Button, Table, Tbody, Td, Th, Thead, Tr } from "@probo/ui";
|
||||
|
||||
@@ -25,7 +25,7 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
||||
<h4 className="font-medium text-txt-primary">
|
||||
{__("Document Access Permissions")}
|
||||
</h4>
|
||||
<div className="ml-auto flex items-center gap-4">
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
{showGrantCTA &&
|
||||
<Button
|
||||
type="button"
|
||||
@@ -83,11 +83,13 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
||||
</div>
|
||||
</Td>
|
||||
<Td>
|
||||
<Badge variant={getTrustCenterDocumentAccessStatusBadgeVariant(docAccess.status)}>
|
||||
{docAccess.status}
|
||||
</Badge>
|
||||
{(docAccess.persisted || docAccess.status !== "REQUESTED") &&
|
||||
<Badge variant={getTrustCenterDocumentAccessStatusBadgeVariant(docAccess.status)}>
|
||||
{getTrustCenterDocumentAccessStatusLabel(docAccess.status, __)}
|
||||
</Badge>
|
||||
}
|
||||
</Td>
|
||||
<Td className="flex justify-end">
|
||||
<Td className="flex justify-end gap-2">
|
||||
{docAccess.status !== "GRANTED" &&
|
||||
<Button
|
||||
type="button"
|
||||
@@ -102,10 +104,13 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
||||
<Button
|
||||
type="button"
|
||||
variant="danger"
|
||||
onClick={() => onUpdateStatus(docAccess, initialStatusByID[docAccess.id] === "GRANTED" ? "REVOKED" : "REJECTED")}
|
||||
onClick={() => onUpdateStatus(
|
||||
docAccess,
|
||||
docAccess.id && initialStatusByID[docAccess.id] === "GRANTED" ? "REVOKED" : "REJECTED"
|
||||
)}
|
||||
className="text-xs h-7 min-h-7"
|
||||
>
|
||||
{initialStatusByID[docAccess.id] === "GRANTED" ? __("Revoke") : __("Reject")}
|
||||
{docAccess.id && initialStatusByID[docAccess.id] === "GRANTED" ? __("Revoke") : __("Reject")}
|
||||
</Button>
|
||||
}
|
||||
</Td>
|
||||
|
||||
@@ -8,6 +8,7 @@ export const trustCenterDocumentAccessStatus = {
|
||||
export type TrustCenterDocumentAccessStatus = (typeof trustCenterDocumentAccessStatus)[keyof typeof trustCenterDocumentAccessStatus];
|
||||
|
||||
export type TrustCenterDocumentAccess = {
|
||||
id: string;
|
||||
active: boolean;
|
||||
status: TrustCenterDocumentAccessStatus;
|
||||
requested: boolean;
|
||||
|
||||
@@ -69,5 +69,6 @@ export { Role, getAssignableRoles } from "./roles";
|
||||
export {
|
||||
getTrustCenterDocumentAccessInfo,
|
||||
getTrustCenterDocumentAccessStatusBadgeVariant,
|
||||
getTrustCenterDocumentAccessStatusLabel,
|
||||
type TrustCenterDocumentAccessInfo,
|
||||
} from "./trustCenterDocumentAccess";
|
||||
|
||||
@@ -12,7 +12,21 @@ export function getTrustCenterDocumentAccessStatusBadgeVariant(status: TrustCent
|
||||
}
|
||||
}
|
||||
|
||||
export function getTrustCenterDocumentAccessStatusLabel(status: TrustCenterDocumentAccessStatus, __: (key: string) => string) {
|
||||
switch (status) {
|
||||
case "REQUESTED":
|
||||
return __("requested");
|
||||
case "GRANTED":
|
||||
return __("granted");
|
||||
case "REJECTED":
|
||||
return __("rejected");
|
||||
case "REVOKED":
|
||||
return __("revoked");
|
||||
}
|
||||
}
|
||||
|
||||
export type TrustCenterDocumentAccessInfo = {
|
||||
persisted: boolean;
|
||||
variant: "info",
|
||||
name: string,
|
||||
type: "document",
|
||||
@@ -23,6 +37,7 @@ export type TrustCenterDocumentAccessInfo = {
|
||||
active: boolean;
|
||||
status: TrustCenterDocumentAccessStatus;
|
||||
} | {
|
||||
persisted: boolean;
|
||||
variant: "success",
|
||||
name: string,
|
||||
type: "report",
|
||||
@@ -33,6 +48,7 @@ export type TrustCenterDocumentAccessInfo = {
|
||||
active: boolean;
|
||||
status: TrustCenterDocumentAccessStatus;
|
||||
} | {
|
||||
persisted: boolean;
|
||||
variant: "highlight",
|
||||
name: string,
|
||||
type: "file",
|
||||
@@ -50,6 +66,7 @@ export function getTrustCenterDocumentAccessInfo(
|
||||
): TrustCenterDocumentAccessInfo {
|
||||
if (docAccess.document) {
|
||||
return {
|
||||
persisted: docAccess.id !== docAccess.document.id,
|
||||
variant: "info" as const,
|
||||
name: docAccess.document.title,
|
||||
type: "document",
|
||||
@@ -63,6 +80,7 @@ export function getTrustCenterDocumentAccessInfo(
|
||||
}
|
||||
if (docAccess.report) {
|
||||
return {
|
||||
persisted: docAccess.id !== docAccess.report.id,
|
||||
variant: "success" as const,
|
||||
name: docAccess.report.filename,
|
||||
type: "report",
|
||||
@@ -76,6 +94,7 @@ export function getTrustCenterDocumentAccessInfo(
|
||||
}
|
||||
if (docAccess.trustCenterFile) {
|
||||
return {
|
||||
persisted: docAccess.id !== docAccess.trustCenterFile.id,
|
||||
variant: "highlight" as const,
|
||||
name: docAccess.trustCenterFile.name,
|
||||
type: "file",
|
||||
|
||||
@@ -766,8 +766,8 @@ WHERE
|
||||
}
|
||||
|
||||
type MergeTrustCenterDocumentAccessesData struct {
|
||||
ID gid.GID
|
||||
Status TrustCenterDocumentAccessStatus
|
||||
ID gid.GID `json:"id"`
|
||||
Status TrustCenterDocumentAccessStatus `json:"status"`
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) MergeDocumentAccesses(
|
||||
@@ -781,16 +781,20 @@ func (tcdas TrustCenterDocumentAccesses) MergeDocumentAccesses(
|
||||
q := `
|
||||
WITH data AS (
|
||||
SELECT
|
||||
id,
|
||||
status
|
||||
FROM
|
||||
json_to_recordset(@data) AS t(id text, status trust_center_document_access_status)
|
||||
t.*
|
||||
FROM json_to_recordset(@data)
|
||||
AS t(
|
||||
id text,
|
||||
status trust_center_document_access_status
|
||||
)
|
||||
)
|
||||
MERGE INTO trust_center_document_accesses tcda
|
||||
MERGE INTO trust_center_document_accesses AS tcda
|
||||
USING data
|
||||
ON data.id = tcda.document_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 tcda.status = data.status, tcda.updated_at = @now
|
||||
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
|
||||
@@ -812,164 +816,18 @@ WHEN NOT MATCHED
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
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,
|
||||
data.id AS document_id,
|
||||
NULL AS report_id,
|
||||
NULL AS trust_center_file_id,
|
||||
false AS active,
|
||||
data.status AS status,
|
||||
false AS requested,
|
||||
@now AS created_at,
|
||||
@now AS updated_at
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"trust_center_document_access_entity_type": TrustCenterDocumentAccessEntityType,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"organization_id": organizationID,
|
||||
"now": time.Now(),
|
||||
"data": data,
|
||||
}
|
||||
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) MergeReportAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
trustCenterAccessID gid.GID,
|
||||
data []MergeTrustCenterDocumentAccessesData,
|
||||
) error {
|
||||
q := `
|
||||
WITH data AS (
|
||||
SELECT
|
||||
id,
|
||||
status
|
||||
FROM
|
||||
json_to_recordset(@data) AS t(id text, status trust_center_document_access_status)
|
||||
)
|
||||
MERGE INTO trust_center_document_accesses tcda
|
||||
USING data
|
||||
ON data.id = tcda.report_id
|
||||
WHEN MATCHED
|
||||
THEN UPDATE SET tcda.status = data.status, tcda.updated_at = @now
|
||||
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
|
||||
WHEN NOT MATCHED
|
||||
THEN INSERT (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
status,
|
||||
requested,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
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 AS document_id,
|
||||
data.id AS report_id,
|
||||
NULL AS trust_center_file_id,
|
||||
false AS active,
|
||||
data.status AS status,
|
||||
false AS requested,
|
||||
@now AS created_at,
|
||||
@now AS updated_at
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"trust_center_document_access_entity_type": TrustCenterDocumentAccessEntityType,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"organization_id": organizationID,
|
||||
"now": time.Now(),
|
||||
"data": data,
|
||||
}
|
||||
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) MergeTrustCenterFileAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
trustCenterAccessID gid.GID,
|
||||
data []MergeTrustCenterDocumentAccessesData,
|
||||
) error {
|
||||
q := `
|
||||
WITH data AS (
|
||||
SELECT
|
||||
id,
|
||||
status
|
||||
FROM
|
||||
json_to_recordset(@data) AS t(id text, status trust_center_document_access_status)
|
||||
)
|
||||
MERGE INTO trust_center_document_accesses tcda
|
||||
USING data
|
||||
ON data.id = tcda.trust_center_file_id
|
||||
WHEN MATCHED
|
||||
THEN UPDATE SET tcda.status = data.status, tcda.updated_at = @now
|
||||
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
|
||||
WHEN NOT MATCHED
|
||||
THEN INSERT (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
status,
|
||||
requested,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
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 AS document_id,
|
||||
NULL AS report_id,
|
||||
data.id AS trust_center_file_id,
|
||||
false AS active,
|
||||
data.status AS status,
|
||||
false AS requested,
|
||||
@now AS created_at,
|
||||
@now AS updated_at
|
||||
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,
|
||||
false,
|
||||
data.status,
|
||||
false,
|
||||
@now::timestamptz,
|
||||
@now::timestamptz
|
||||
)
|
||||
`
|
||||
|
||||
@@ -1055,6 +913,83 @@ ON CONFLICT DO NOTHING
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) MergeReportAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
trustCenterAccessID gid.GID,
|
||||
data []MergeTrustCenterDocumentAccessesData,
|
||||
) error {
|
||||
q := `
|
||||
WITH data AS (
|
||||
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
|
||||
WHEN MATCHED
|
||||
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
|
||||
WHEN NOT MATCHED
|
||||
THEN INSERT (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
status,
|
||||
requested,
|
||||
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,
|
||||
false,
|
||||
data.status,
|
||||
false,
|
||||
@now::timestamptz,
|
||||
@now::timestamptz
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"trust_center_document_access_entity_type": TrustCenterDocumentAccessEntityType,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"organization_id": organizationID,
|
||||
"now": time.Now(),
|
||||
"data": data,
|
||||
}
|
||||
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) BulkInsertReportAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
@@ -1238,6 +1173,83 @@ WHERE
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) MergeTrustCenterFileAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
trustCenterAccessID gid.GID,
|
||||
data []MergeTrustCenterDocumentAccessesData,
|
||||
) error {
|
||||
q := `
|
||||
WITH data AS (
|
||||
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
|
||||
WHEN MATCHED
|
||||
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
|
||||
WHEN NOT MATCHED
|
||||
THEN INSERT (
|
||||
id,
|
||||
tenant_id,
|
||||
organization_id,
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
status,
|
||||
requested,
|
||||
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,
|
||||
false,
|
||||
data.status,
|
||||
false,
|
||||
@now::timestamptz,
|
||||
@now::timestamptz
|
||||
)
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"trust_center_document_access_entity_type": TrustCenterDocumentAccessEntityType,
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"organization_id": organizationID,
|
||||
"now": time.Now(),
|
||||
"data": data,
|
||||
}
|
||||
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) BulkInsertTrustCenterFileAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
|
||||
@@ -76,13 +76,13 @@ func (utcar *UpdateTrustCenterAccessRequest) Validate() error {
|
||||
v.Check(utcar.ID, "id", validator.Required(), validator.GID(coredata.TrustCenterAccessEntityType))
|
||||
v.Check(utcar.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
|
||||
for i, docAccess := range utcar.DocumentAccesses {
|
||||
v.Check(docAccess, fmt.Sprintf("documentAccesses[%d].ID", i), validator.Required(), validator.GID(coredata.DocumentEntityType))
|
||||
v.Check(docAccess.ID, fmt.Sprintf("documentAccesses[%d].ID", i), validator.Required(), validator.GID(coredata.DocumentEntityType))
|
||||
}
|
||||
for i, reportAccess := range utcar.ReportAccesses {
|
||||
v.Check(reportAccess, fmt.Sprintf("reportAccesses[%d].ID", i), validator.Required(), validator.GID(coredata.ReportEntityType))
|
||||
v.Check(reportAccess.ID, fmt.Sprintf("reportAccesses[%d].ID", i), validator.Required(), validator.GID(coredata.ReportEntityType))
|
||||
}
|
||||
for i, reportAccess := range utcar.TrustCenterFileAccesses {
|
||||
v.Check(reportAccess, fmt.Sprintf("trustCenterFileAccesses[%d].ID", i), validator.Required(), validator.GID(coredata.TrustCenterFileEntityType))
|
||||
v.Check(reportAccess.ID, fmt.Sprintf("trustCenterFileAccesses[%d].ID", i), validator.Required(), validator.GID(coredata.TrustCenterFileEntityType))
|
||||
}
|
||||
|
||||
return v.Error()
|
||||
@@ -297,40 +297,46 @@ func (s TrustCenterAccessService) Update(
|
||||
|
||||
var tcdas coredata.TrustCenterDocumentAccesses
|
||||
|
||||
var documentData []coredata.MergeTrustCenterDocumentAccessesData
|
||||
for _, d := range req.DocumentAccesses {
|
||||
documentData = append(documentData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||
ID: d.ID,
|
||||
Status: d.Status,
|
||||
})
|
||||
if len(req.DocumentAccesses) > 0 {
|
||||
var documentData []coredata.MergeTrustCenterDocumentAccessesData
|
||||
for _, d := range req.DocumentAccesses {
|
||||
documentData = append(documentData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||
ID: d.ID,
|
||||
Status: d.Status,
|
||||
})
|
||||
}
|
||||
|
||||
if err := tcdas.MergeDocumentAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, documentData); err != nil {
|
||||
return fmt.Errorf("cannot merge document accesses: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := tcdas.MergeDocumentAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, documentData); err != nil {
|
||||
return fmt.Errorf("cannot merge document accesses: %w", err)
|
||||
if len(req.ReportAccesses) > 0 {
|
||||
var reportData []coredata.MergeTrustCenterDocumentAccessesData
|
||||
for _, d := range req.ReportAccesses {
|
||||
reportData = append(reportData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||
ID: d.ID,
|
||||
Status: d.Status,
|
||||
})
|
||||
}
|
||||
|
||||
if err := tcdas.MergeReportAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, reportData); err != nil {
|
||||
return fmt.Errorf("cannot merge report accesses: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
var reportData []coredata.MergeTrustCenterDocumentAccessesData
|
||||
for _, d := range req.ReportAccesses {
|
||||
reportData = append(reportData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||
ID: d.ID,
|
||||
Status: d.Status,
|
||||
})
|
||||
}
|
||||
if len(req.TrustCenterFileAccesses) > 0 {
|
||||
var fileData []coredata.MergeTrustCenterDocumentAccessesData
|
||||
for _, d := range req.TrustCenterFileAccesses {
|
||||
fileData = append(fileData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||
ID: d.ID,
|
||||
Status: d.Status,
|
||||
})
|
||||
}
|
||||
|
||||
if err := tcdas.MergeReportAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, reportData); err != nil {
|
||||
return fmt.Errorf("cannot merge report accesses: %w", err)
|
||||
}
|
||||
|
||||
var fileData []coredata.MergeTrustCenterDocumentAccessesData
|
||||
for _, d := range req.TrustCenterFileAccesses {
|
||||
fileData = append(fileData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||
ID: d.ID,
|
||||
Status: d.Status,
|
||||
})
|
||||
}
|
||||
|
||||
if err := tcdas.MergeTrustCenterFileAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, fileData); err != nil {
|
||||
return fmt.Errorf("cannot merge trust center file accesses: %w", err)
|
||||
if err := tcdas.MergeTrustCenterFileAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, fileData); err != nil {
|
||||
return fmt.Errorf("cannot merge trust center file accesses: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if shouldSendEmail {
|
||||
|
||||
@@ -2363,6 +2363,7 @@ type TrustCenterDocumentAccess
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.TrustCenterDocumentAccess"
|
||||
) {
|
||||
id: ID!
|
||||
active: Boolean!
|
||||
status: TrustCenterDocumentAccessStatus!
|
||||
requested: Boolean!
|
||||
|
||||
@@ -1454,6 +1454,7 @@ type ComplexityRoot struct {
|
||||
TrustCenterDocumentAccess struct {
|
||||
Active func(childComplexity int) int
|
||||
Document func(childComplexity int) int
|
||||
ID func(childComplexity int) int
|
||||
Report func(childComplexity int) int
|
||||
Requested func(childComplexity int) int
|
||||
Status func(childComplexity int) int
|
||||
@@ -8022,6 +8023,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
|
||||
}
|
||||
|
||||
return e.complexity.TrustCenterDocumentAccess.Document(childComplexity), true
|
||||
case "TrustCenterDocumentAccess.id":
|
||||
if e.complexity.TrustCenterDocumentAccess.ID == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.TrustCenterDocumentAccess.ID(childComplexity), true
|
||||
case "TrustCenterDocumentAccess.report":
|
||||
if e.complexity.TrustCenterDocumentAccess.Report == nil {
|
||||
break
|
||||
@@ -11924,6 +11931,7 @@ type TrustCenterDocumentAccess
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.TrustCenterDocumentAccess"
|
||||
) {
|
||||
id: ID!
|
||||
active: Boolean!
|
||||
status: TrustCenterDocumentAccessStatus!
|
||||
requested: Boolean!
|
||||
@@ -47129,6 +47137,35 @@ func (ec *executionContext) fieldContext_TrustCenterConnection_pageInfo(_ contex
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _TrustCenterDocumentAccess_id(ctx context.Context, field graphql.CollectedField, obj *types.TrustCenterDocumentAccess) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
ec.OperationContext,
|
||||
field,
|
||||
ec.fieldContext_TrustCenterDocumentAccess_id,
|
||||
func(ctx context.Context) (any, error) {
|
||||
return obj.ID, nil
|
||||
},
|
||||
nil,
|
||||
ec.marshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID,
|
||||
true,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_TrustCenterDocumentAccess_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "TrustCenterDocumentAccess",
|
||||
Field: field,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type ID does not have child fields")
|
||||
},
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _TrustCenterDocumentAccess_active(ctx context.Context, field graphql.CollectedField, obj *types.TrustCenterDocumentAccess) (ret graphql.Marshaler) {
|
||||
return graphql.ResolveField(
|
||||
ctx,
|
||||
@@ -47525,6 +47562,8 @@ func (ec *executionContext) fieldContext_TrustCenterDocumentAccessEdge_node(_ co
|
||||
IsResolver: false,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
switch field.Name {
|
||||
case "id":
|
||||
return ec.fieldContext_TrustCenterDocumentAccess_id(ctx, field)
|
||||
case "active":
|
||||
return ec.fieldContext_TrustCenterDocumentAccess_active(ctx, field)
|
||||
case "status":
|
||||
@@ -78859,6 +78898,11 @@ func (ec *executionContext) _TrustCenterDocumentAccess(ctx context.Context, sel
|
||||
switch field.Name {
|
||||
case "__typename":
|
||||
out.Values[i] = graphql.MarshalString("TrustCenterDocumentAccess")
|
||||
case "id":
|
||||
out.Values[i] = ec._TrustCenterDocumentAccess_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
atomic.AddUint32(&out.Invalids, 1)
|
||||
}
|
||||
case "active":
|
||||
out.Values[i] = ec._TrustCenterDocumentAccess_active(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
|
||||
Reference in New Issue
Block a user