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 }) {
|
availableDocumentAccesses(first: 100, orderBy: { field: CREATED_AT, direction: DESC }) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
id
|
||||||
active
|
active
|
||||||
requested
|
requested
|
||||||
status
|
status
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<bf1055f4f2fe5eb7a428afdd30f4f672>>
|
* @generated SignedSource<<3d9ccb3632d0373c627c87f6e6585673>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -25,6 +25,7 @@ export type TrustCenterAccessGraphLoadDocumentAccessesQuery$data = {
|
|||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly title: string;
|
readonly title: string;
|
||||||
} | null | undefined;
|
} | null | undefined;
|
||||||
|
readonly id: string;
|
||||||
readonly report: {
|
readonly report: {
|
||||||
readonly audit: {
|
readonly audit: {
|
||||||
readonly framework: {
|
readonly framework: {
|
||||||
@@ -214,6 +215,7 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
|
(v2/*: any*/),
|
||||||
(v4/*: any*/),
|
(v4/*: any*/),
|
||||||
(v5/*: any*/),
|
(v5/*: any*/),
|
||||||
(v6/*: any*/),
|
(v6/*: any*/),
|
||||||
@@ -325,6 +327,7 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
|
(v2/*: any*/),
|
||||||
(v4/*: any*/),
|
(v4/*: any*/),
|
||||||
(v5/*: any*/),
|
(v5/*: any*/),
|
||||||
(v6/*: any*/),
|
(v6/*: any*/),
|
||||||
@@ -387,16 +390,16 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "a764b27e48509dfdf4a7a03c5f00ea59",
|
"cacheID": "a590c829b3c88e4fa4fe146771c723b9",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"name": "TrustCenterAccessGraphLoadDocumentAccessesQuery",
|
"name": "TrustCenterAccessGraphLoadDocumentAccessesQuery",
|
||||||
"operationKind": "query",
|
"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;
|
export default node;
|
||||||
|
|||||||
@@ -85,7 +85,9 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
|||||||
setDocumentAccesses((prev) => prev.map(element => ({...element, status: "GRANTED"})))
|
setDocumentAccesses((prev) => prev.map(element => ({...element, status: "GRANTED"})))
|
||||||
}, [])
|
}, [])
|
||||||
const handleRejectOrRevokeAllDocumentAccess = useCallback(() => {
|
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])
|
}, [initialStatusByID])
|
||||||
|
|
||||||
const editSchema = z.object({
|
const editSchema = z.object({
|
||||||
@@ -104,9 +106,10 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
|||||||
const handleSubmit = editForm.handleSubmit(async (data) => {
|
const handleSubmit = editForm.handleSubmit(async (data) => {
|
||||||
const documents: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
const documents: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||||
const reports: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
const reports: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||||
const trustCenterFiles: {id: string, status: TrustCenterDocumentAccessStatus}[] = [];
|
const trustCenterFiles: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||||
|
|
||||||
for (const docAccess of documentAccesses) {
|
for (const docAccess of documentAccesses) {
|
||||||
|
if (docAccess.persisted || docAccess.status !== "REQUESTED") {
|
||||||
switch (docAccess.type) {
|
switch (docAccess.type) {
|
||||||
case "document":
|
case "document":
|
||||||
documents.push({id: docAccess.id, status: docAccess.status});
|
documents.push({id: docAccess.id, status: docAccess.status});
|
||||||
@@ -119,6 +122,7 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await updateTrustCenterAccess({
|
await updateTrustCenterAccess({
|
||||||
variables: {
|
variables: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { TrustCenterDocumentAccessStatus } from "@probo/coredata";
|
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 { useTranslate } from "@probo/i18n";
|
||||||
import { Badge, Button, Table, Tbody, Td, Th, Thead, Tr } from "@probo/ui";
|
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">
|
<h4 className="font-medium text-txt-primary">
|
||||||
{__("Document Access Permissions")}
|
{__("Document Access Permissions")}
|
||||||
</h4>
|
</h4>
|
||||||
<div className="ml-auto flex items-center gap-4">
|
<div className="ml-auto flex items-center gap-2">
|
||||||
{showGrantCTA &&
|
{showGrantCTA &&
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -83,11 +83,13 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
|||||||
</div>
|
</div>
|
||||||
</Td>
|
</Td>
|
||||||
<Td>
|
<Td>
|
||||||
|
{(docAccess.persisted || docAccess.status !== "REQUESTED") &&
|
||||||
<Badge variant={getTrustCenterDocumentAccessStatusBadgeVariant(docAccess.status)}>
|
<Badge variant={getTrustCenterDocumentAccessStatusBadgeVariant(docAccess.status)}>
|
||||||
{docAccess.status}
|
{getTrustCenterDocumentAccessStatusLabel(docAccess.status, __)}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
}
|
||||||
</Td>
|
</Td>
|
||||||
<Td className="flex justify-end">
|
<Td className="flex justify-end gap-2">
|
||||||
{docAccess.status !== "GRANTED" &&
|
{docAccess.status !== "GRANTED" &&
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -102,10 +104,13 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="danger"
|
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"
|
className="text-xs h-7 min-h-7"
|
||||||
>
|
>
|
||||||
{initialStatusByID[docAccess.id] === "GRANTED" ? __("Revoke") : __("Reject")}
|
{docAccess.id && initialStatusByID[docAccess.id] === "GRANTED" ? __("Revoke") : __("Reject")}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
</Td>
|
</Td>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const trustCenterDocumentAccessStatus = {
|
|||||||
export type TrustCenterDocumentAccessStatus = (typeof trustCenterDocumentAccessStatus)[keyof typeof trustCenterDocumentAccessStatus];
|
export type TrustCenterDocumentAccessStatus = (typeof trustCenterDocumentAccessStatus)[keyof typeof trustCenterDocumentAccessStatus];
|
||||||
|
|
||||||
export type TrustCenterDocumentAccess = {
|
export type TrustCenterDocumentAccess = {
|
||||||
|
id: string;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
status: TrustCenterDocumentAccessStatus;
|
status: TrustCenterDocumentAccessStatus;
|
||||||
requested: boolean;
|
requested: boolean;
|
||||||
|
|||||||
@@ -69,5 +69,6 @@ export { Role, getAssignableRoles } from "./roles";
|
|||||||
export {
|
export {
|
||||||
getTrustCenterDocumentAccessInfo,
|
getTrustCenterDocumentAccessInfo,
|
||||||
getTrustCenterDocumentAccessStatusBadgeVariant,
|
getTrustCenterDocumentAccessStatusBadgeVariant,
|
||||||
|
getTrustCenterDocumentAccessStatusLabel,
|
||||||
type TrustCenterDocumentAccessInfo,
|
type TrustCenterDocumentAccessInfo,
|
||||||
} from "./trustCenterDocumentAccess";
|
} 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 = {
|
export type TrustCenterDocumentAccessInfo = {
|
||||||
|
persisted: boolean;
|
||||||
variant: "info",
|
variant: "info",
|
||||||
name: string,
|
name: string,
|
||||||
type: "document",
|
type: "document",
|
||||||
@@ -23,6 +37,7 @@ export type TrustCenterDocumentAccessInfo = {
|
|||||||
active: boolean;
|
active: boolean;
|
||||||
status: TrustCenterDocumentAccessStatus;
|
status: TrustCenterDocumentAccessStatus;
|
||||||
} | {
|
} | {
|
||||||
|
persisted: boolean;
|
||||||
variant: "success",
|
variant: "success",
|
||||||
name: string,
|
name: string,
|
||||||
type: "report",
|
type: "report",
|
||||||
@@ -33,6 +48,7 @@ export type TrustCenterDocumentAccessInfo = {
|
|||||||
active: boolean;
|
active: boolean;
|
||||||
status: TrustCenterDocumentAccessStatus;
|
status: TrustCenterDocumentAccessStatus;
|
||||||
} | {
|
} | {
|
||||||
|
persisted: boolean;
|
||||||
variant: "highlight",
|
variant: "highlight",
|
||||||
name: string,
|
name: string,
|
||||||
type: "file",
|
type: "file",
|
||||||
@@ -50,6 +66,7 @@ export function getTrustCenterDocumentAccessInfo(
|
|||||||
): TrustCenterDocumentAccessInfo {
|
): TrustCenterDocumentAccessInfo {
|
||||||
if (docAccess.document) {
|
if (docAccess.document) {
|
||||||
return {
|
return {
|
||||||
|
persisted: docAccess.id !== docAccess.document.id,
|
||||||
variant: "info" as const,
|
variant: "info" as const,
|
||||||
name: docAccess.document.title,
|
name: docAccess.document.title,
|
||||||
type: "document",
|
type: "document",
|
||||||
@@ -63,6 +80,7 @@ export function getTrustCenterDocumentAccessInfo(
|
|||||||
}
|
}
|
||||||
if (docAccess.report) {
|
if (docAccess.report) {
|
||||||
return {
|
return {
|
||||||
|
persisted: docAccess.id !== docAccess.report.id,
|
||||||
variant: "success" as const,
|
variant: "success" as const,
|
||||||
name: docAccess.report.filename,
|
name: docAccess.report.filename,
|
||||||
type: "report",
|
type: "report",
|
||||||
@@ -76,6 +94,7 @@ export function getTrustCenterDocumentAccessInfo(
|
|||||||
}
|
}
|
||||||
if (docAccess.trustCenterFile) {
|
if (docAccess.trustCenterFile) {
|
||||||
return {
|
return {
|
||||||
|
persisted: docAccess.id !== docAccess.trustCenterFile.id,
|
||||||
variant: "highlight" as const,
|
variant: "highlight" as const,
|
||||||
name: docAccess.trustCenterFile.name,
|
name: docAccess.trustCenterFile.name,
|
||||||
type: "file",
|
type: "file",
|
||||||
|
|||||||
@@ -766,8 +766,8 @@ WHERE
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MergeTrustCenterDocumentAccessesData struct {
|
type MergeTrustCenterDocumentAccessesData struct {
|
||||||
ID gid.GID
|
ID gid.GID `json:"id"`
|
||||||
Status TrustCenterDocumentAccessStatus
|
Status TrustCenterDocumentAccessStatus `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tcdas TrustCenterDocumentAccesses) MergeDocumentAccesses(
|
func (tcdas TrustCenterDocumentAccesses) MergeDocumentAccesses(
|
||||||
@@ -781,16 +781,20 @@ func (tcdas TrustCenterDocumentAccesses) MergeDocumentAccesses(
|
|||||||
q := `
|
q := `
|
||||||
WITH data AS (
|
WITH data AS (
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
t.*
|
||||||
status
|
FROM json_to_recordset(@data)
|
||||||
FROM
|
AS t(
|
||||||
json_to_recordset(@data) AS t(id text, status trust_center_document_access_status)
|
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
|
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
|
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
|
WHEN NOT MATCHED BY SOURCE
|
||||||
AND tcda.tenant_id = @tenant_id
|
AND tcda.tenant_id = @tenant_id
|
||||||
AND tcda.trust_center_access_id = @trust_center_access_id
|
AND tcda.trust_center_access_id = @trust_center_access_id
|
||||||
@@ -812,164 +816,18 @@ WHEN NOT MATCHED
|
|||||||
updated_at
|
updated_at
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type) AS id,
|
generate_gid(decode_base64_unpadded(@tenant_id), @trust_center_document_access_entity_type),
|
||||||
@tenant_id AS tenant_id,
|
@tenant_id,
|
||||||
@organization_id AS organization_id,
|
@organization_id,
|
||||||
@trust_center_access_id AS trust_center_access_id,
|
@trust_center_access_id,
|
||||||
data.id AS document_id,
|
data.id,
|
||||||
NULL AS report_id,
|
NULL,
|
||||||
NULL AS trust_center_file_id,
|
NULL,
|
||||||
false AS active,
|
false,
|
||||||
data.status AS status,
|
data.status,
|
||||||
false AS requested,
|
false,
|
||||||
@now AS created_at,
|
@now::timestamptz,
|
||||||
@now AS updated_at
|
@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) 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
|
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -1055,6 +913,83 @@ ON CONFLICT DO NOTHING
|
|||||||
return nil
|
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(
|
func (tcdas TrustCenterDocumentAccesses) BulkInsertReportAccesses(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
@@ -1238,6 +1173,83 @@ WHERE
|
|||||||
return nil
|
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(
|
func (tcdas TrustCenterDocumentAccesses) BulkInsertTrustCenterFileAccesses(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Conn,
|
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.ID, "id", validator.Required(), validator.GID(coredata.TrustCenterAccessEntityType))
|
||||||
v.Check(utcar.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
|
v.Check(utcar.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
|
||||||
for i, docAccess := range utcar.DocumentAccesses {
|
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 {
|
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 {
|
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()
|
return v.Error()
|
||||||
@@ -297,6 +297,7 @@ func (s TrustCenterAccessService) Update(
|
|||||||
|
|
||||||
var tcdas coredata.TrustCenterDocumentAccesses
|
var tcdas coredata.TrustCenterDocumentAccesses
|
||||||
|
|
||||||
|
if len(req.DocumentAccesses) > 0 {
|
||||||
var documentData []coredata.MergeTrustCenterDocumentAccessesData
|
var documentData []coredata.MergeTrustCenterDocumentAccessesData
|
||||||
for _, d := range req.DocumentAccesses {
|
for _, d := range req.DocumentAccesses {
|
||||||
documentData = append(documentData, coredata.MergeTrustCenterDocumentAccessesData{
|
documentData = append(documentData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||||
@@ -308,7 +309,9 @@ func (s TrustCenterAccessService) Update(
|
|||||||
if err := tcdas.MergeDocumentAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, documentData); err != nil {
|
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)
|
return fmt.Errorf("cannot merge document accesses: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.ReportAccesses) > 0 {
|
||||||
var reportData []coredata.MergeTrustCenterDocumentAccessesData
|
var reportData []coredata.MergeTrustCenterDocumentAccessesData
|
||||||
for _, d := range req.ReportAccesses {
|
for _, d := range req.ReportAccesses {
|
||||||
reportData = append(reportData, coredata.MergeTrustCenterDocumentAccessesData{
|
reportData = append(reportData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||||
@@ -320,7 +323,9 @@ func (s TrustCenterAccessService) Update(
|
|||||||
if err := tcdas.MergeReportAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, reportData); err != nil {
|
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)
|
return fmt.Errorf("cannot merge report accesses: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.TrustCenterFileAccesses) > 0 {
|
||||||
var fileData []coredata.MergeTrustCenterDocumentAccessesData
|
var fileData []coredata.MergeTrustCenterDocumentAccessesData
|
||||||
for _, d := range req.TrustCenterFileAccesses {
|
for _, d := range req.TrustCenterFileAccesses {
|
||||||
fileData = append(fileData, coredata.MergeTrustCenterDocumentAccessesData{
|
fileData = append(fileData, coredata.MergeTrustCenterDocumentAccessesData{
|
||||||
@@ -332,6 +337,7 @@ func (s TrustCenterAccessService) Update(
|
|||||||
if err := tcdas.MergeTrustCenterFileAccesses(ctx, tx, s.svc.scope, access.OrganizationID, access.ID, fileData); err != nil {
|
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)
|
return fmt.Errorf("cannot merge trust center file accesses: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if shouldSendEmail {
|
if shouldSendEmail {
|
||||||
if err := s.sendAccessEmail(ctx, tx, access); err != nil {
|
if err := s.sendAccessEmail(ctx, tx, access); err != nil {
|
||||||
|
|||||||
@@ -2363,6 +2363,7 @@ type TrustCenterDocumentAccess
|
|||||||
@goModel(
|
@goModel(
|
||||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.TrustCenterDocumentAccess"
|
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.TrustCenterDocumentAccess"
|
||||||
) {
|
) {
|
||||||
|
id: ID!
|
||||||
active: Boolean!
|
active: Boolean!
|
||||||
status: TrustCenterDocumentAccessStatus!
|
status: TrustCenterDocumentAccessStatus!
|
||||||
requested: Boolean!
|
requested: Boolean!
|
||||||
|
|||||||
@@ -1454,6 +1454,7 @@ type ComplexityRoot struct {
|
|||||||
TrustCenterDocumentAccess struct {
|
TrustCenterDocumentAccess struct {
|
||||||
Active func(childComplexity int) int
|
Active func(childComplexity int) int
|
||||||
Document func(childComplexity int) int
|
Document func(childComplexity int) int
|
||||||
|
ID func(childComplexity int) int
|
||||||
Report func(childComplexity int) int
|
Report func(childComplexity int) int
|
||||||
Requested func(childComplexity int) int
|
Requested func(childComplexity int) int
|
||||||
Status 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
|
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":
|
case "TrustCenterDocumentAccess.report":
|
||||||
if e.complexity.TrustCenterDocumentAccess.Report == nil {
|
if e.complexity.TrustCenterDocumentAccess.Report == nil {
|
||||||
break
|
break
|
||||||
@@ -11924,6 +11931,7 @@ type TrustCenterDocumentAccess
|
|||||||
@goModel(
|
@goModel(
|
||||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.TrustCenterDocumentAccess"
|
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.TrustCenterDocumentAccess"
|
||||||
) {
|
) {
|
||||||
|
id: ID!
|
||||||
active: Boolean!
|
active: Boolean!
|
||||||
status: TrustCenterDocumentAccessStatus!
|
status: TrustCenterDocumentAccessStatus!
|
||||||
requested: Boolean!
|
requested: Boolean!
|
||||||
@@ -47129,6 +47137,35 @@ func (ec *executionContext) fieldContext_TrustCenterConnection_pageInfo(_ contex
|
|||||||
return fc, nil
|
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) {
|
func (ec *executionContext) _TrustCenterDocumentAccess_active(ctx context.Context, field graphql.CollectedField, obj *types.TrustCenterDocumentAccess) (ret graphql.Marshaler) {
|
||||||
return graphql.ResolveField(
|
return graphql.ResolveField(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -47525,6 +47562,8 @@ func (ec *executionContext) fieldContext_TrustCenterDocumentAccessEdge_node(_ co
|
|||||||
IsResolver: false,
|
IsResolver: false,
|
||||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||||
switch field.Name {
|
switch field.Name {
|
||||||
|
case "id":
|
||||||
|
return ec.fieldContext_TrustCenterDocumentAccess_id(ctx, field)
|
||||||
case "active":
|
case "active":
|
||||||
return ec.fieldContext_TrustCenterDocumentAccess_active(ctx, field)
|
return ec.fieldContext_TrustCenterDocumentAccess_active(ctx, field)
|
||||||
case "status":
|
case "status":
|
||||||
@@ -78859,6 +78898,11 @@ func (ec *executionContext) _TrustCenterDocumentAccess(ctx context.Context, sel
|
|||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "__typename":
|
case "__typename":
|
||||||
out.Values[i] = graphql.MarshalString("TrustCenterDocumentAccess")
|
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":
|
case "active":
|
||||||
out.Values[i] = ec._TrustCenterDocumentAccess_active(ctx, field, obj)
|
out.Values[i] = ec._TrustCenterDocumentAccess_active(ctx, field, obj)
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
|
|||||||
Reference in New Issue
Block a user