Add trust center files
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
228
apps/console/src/components/trustCenter/TrustCenterFilesCard.tsx
Normal file
228
apps/console/src/components/trustCenter/TrustCenterFilesCard.tsx
Normal file
@@ -0,0 +1,228 @@
|
||||
import { graphql } from "relay-runtime";
|
||||
import {
|
||||
Card,
|
||||
Button,
|
||||
Tr,
|
||||
Td,
|
||||
Table,
|
||||
Thead,
|
||||
Tbody,
|
||||
Th,
|
||||
IconChevronDown,
|
||||
Field,
|
||||
Option,
|
||||
Badge,
|
||||
IconPencil,
|
||||
IconTrashCan,
|
||||
IconArrowLink,
|
||||
} from "@probo/ui";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import type { TrustCenterFilesCardFragment$key, TrustCenterFilesCardFragment$data } from "./__generated__/TrustCenterFilesCardFragment.graphql";
|
||||
import { useFragment } from "react-relay";
|
||||
import { useMemo, useState, useCallback, useEffect } from "react";
|
||||
import { sprintf, getTrustCenterVisibilityOptions } from "@probo/helpers";
|
||||
import { formatDate } from "@probo/helpers";
|
||||
import clsx from "clsx";
|
||||
|
||||
const trustCenterFileFragment = graphql`
|
||||
fragment TrustCenterFilesCardFragment on TrustCenterFile {
|
||||
id
|
||||
name
|
||||
category
|
||||
fileUrl
|
||||
trustCenterVisibility
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
`;
|
||||
|
||||
type Mutation<Params> = (p: {
|
||||
variables: {
|
||||
input: {
|
||||
id: string;
|
||||
trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC";
|
||||
} & Params;
|
||||
};
|
||||
}) => void;
|
||||
|
||||
type Props<Params> = {
|
||||
files: TrustCenterFilesCardFragment$key[];
|
||||
params: Params;
|
||||
disabled?: boolean;
|
||||
onChangeVisibility: Mutation<Params>;
|
||||
onEdit: (file: { id: string; name: string; category: string }) => void;
|
||||
onDelete: (id: string) => void;
|
||||
variant?: "card" | "table";
|
||||
};
|
||||
|
||||
export function TrustCenterFilesCard<Params>(props: Props<Params>) {
|
||||
const { __ } = useTranslate();
|
||||
const [limit, setLimit] = useState<number | null>(4);
|
||||
const files = useMemo(() => {
|
||||
return limit ? props.files.slice(0, limit) : props.files;
|
||||
}, [props.files, limit]);
|
||||
const showMoreButton = limit !== null && props.files.length > limit;
|
||||
const variant = props.variant ?? "table";
|
||||
|
||||
const onChangeVisibility = (fileId: string, trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC") => {
|
||||
props.onChangeVisibility({
|
||||
variables: {
|
||||
input: {
|
||||
id: fileId,
|
||||
trustCenterVisibility,
|
||||
...props.params,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const Wrapper = variant === "card" ? Card : "div";
|
||||
|
||||
return (
|
||||
<Wrapper padded className="space-y-[10px]">
|
||||
<Table className={clsx(variant === "card" && "bg-invert")}>
|
||||
<Thead>
|
||||
<Tr>
|
||||
<Th>{__("Name")}</Th>
|
||||
<Th>{__("Category")}</Th>
|
||||
<Th>{__("Upload Date")}</Th>
|
||||
<Th>{__("Visibility")}</Th>
|
||||
<Th></Th>
|
||||
</Tr>
|
||||
</Thead>
|
||||
<Tbody>
|
||||
{files.length === 0 && (
|
||||
<Tr>
|
||||
<Td colSpan={5} className="text-center text-txt-secondary">
|
||||
{__("No files available")}
|
||||
</Td>
|
||||
</Tr>
|
||||
)}
|
||||
{files.map((fileFragmentRef, index) => (
|
||||
<FileRowWrapper
|
||||
key={index}
|
||||
fileFragmentRef={fileFragmentRef}
|
||||
onChangeVisibility={onChangeVisibility}
|
||||
onEdit={props.onEdit}
|
||||
onDelete={props.onDelete}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
))}
|
||||
</Tbody>
|
||||
</Table>
|
||||
{showMoreButton && (
|
||||
<Button
|
||||
variant="tertiary"
|
||||
onClick={() => setLimit(null)}
|
||||
className="mt-3 mx-auto"
|
||||
icon={IconChevronDown}
|
||||
>
|
||||
{sprintf(__("Show %s more"), props.files.length - limit)}
|
||||
</Button>
|
||||
)}
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
function FileRowWrapper(props: {
|
||||
fileFragmentRef: TrustCenterFilesCardFragment$key;
|
||||
onChangeVisibility: (fileId: string, trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC") => void;
|
||||
onEdit: (file: { id: string; name: string; category: string }) => void;
|
||||
onDelete: (id: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const file = useFragment(trustCenterFileFragment, props.fileFragmentRef);
|
||||
return (
|
||||
<FileRow
|
||||
file={file}
|
||||
onChangeVisibility={props.onChangeVisibility}
|
||||
onEdit={props.onEdit}
|
||||
onDelete={props.onDelete}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FileRow(props: {
|
||||
file: TrustCenterFilesCardFragment$data;
|
||||
onChangeVisibility: (fileId: string, trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC") => void;
|
||||
onEdit: (file: { id: string; name: string; category: string }) => void;
|
||||
onDelete: (id: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const file = props.file;
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
|
||||
const handleValueChange = useCallback((value: string | {}) => {
|
||||
const stringValue = typeof value === 'string' ? value : '';
|
||||
const typedValue = stringValue as "NONE" | "PRIVATE" | "PUBLIC";
|
||||
setOptimisticValue(typedValue);
|
||||
props.onChangeVisibility(file.id, typedValue);
|
||||
}, [file.id, props.onChangeVisibility]);
|
||||
|
||||
useEffect(() => {
|
||||
if (optimisticValue && file.trustCenterVisibility === optimisticValue) {
|
||||
setOptimisticValue(null);
|
||||
}
|
||||
}, [file.trustCenterVisibility, optimisticValue]);
|
||||
|
||||
const currentValue = optimisticValue || file.trustCenterVisibility;
|
||||
|
||||
const visibilityOptions = getTrustCenterVisibilityOptions(__);
|
||||
|
||||
return (
|
||||
<Tr>
|
||||
<Td>
|
||||
<div className="flex gap-4 items-center">
|
||||
{file.name}
|
||||
</div>
|
||||
</Td>
|
||||
<Td>{file.category}</Td>
|
||||
<Td>{formatDate(file.createdAt)}</Td>
|
||||
<Td noLink width={130} className="pr-0">
|
||||
<Field
|
||||
type="select"
|
||||
value={currentValue}
|
||||
onValueChange={handleValueChange}
|
||||
disabled={props.disabled}
|
||||
className="w-[105px]"
|
||||
>
|
||||
{visibilityOptions.map((option) => (
|
||||
<Option key={option.value} value={option.value}>
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<Badge variant={option.variant}>
|
||||
{option.label}
|
||||
</Badge>
|
||||
</div>
|
||||
</Option>
|
||||
))}
|
||||
</Field>
|
||||
</Td>
|
||||
<Td noLink width={120}>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={IconArrowLink}
|
||||
onClick={() => window.open(file.fileUrl, '_blank', 'noopener,noreferrer')}
|
||||
title={__("Download")}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={IconPencil}
|
||||
onClick={() => props.onEdit({ id: file.id, name: file.name, category: file.category })}
|
||||
disabled={props.disabled}
|
||||
title={__("Edit")}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={IconTrashCan}
|
||||
onClick={() => props.onDelete(file.id)}
|
||||
disabled={props.disabled}
|
||||
title={__("Delete")}
|
||||
/>
|
||||
</div>
|
||||
</Td>
|
||||
</Tr>
|
||||
);
|
||||
}
|
||||
91
apps/console/src/components/trustCenter/__generated__/TrustCenterFilesCardFragment.graphql.ts
generated
Normal file
91
apps/console/src/components/trustCenter/__generated__/TrustCenterFilesCardFragment.graphql.ts
generated
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* @generated SignedSource<<0defaaf1ce3544420e8fbd9c9f3af139>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ReaderFragment } from 'relay-runtime';
|
||||
export type TrustCenterVisibility = "NONE" | "PRIVATE" | "PUBLIC";
|
||||
import { FragmentRefs } from "relay-runtime";
|
||||
export type TrustCenterFilesCardFragment$data = {
|
||||
readonly category: string;
|
||||
readonly createdAt: any;
|
||||
readonly fileUrl: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly trustCenterVisibility: TrustCenterVisibility;
|
||||
readonly updatedAt: any;
|
||||
readonly " $fragmentType": "TrustCenterFilesCardFragment";
|
||||
};
|
||||
export type TrustCenterFilesCardFragment$key = {
|
||||
readonly " $data"?: TrustCenterFilesCardFragment$data;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFilesCardFragment">;
|
||||
};
|
||||
|
||||
const node: ReaderFragment = {
|
||||
"argumentDefinitions": [],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFilesCardFragment",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "fileUrl",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "trustCenterVisibility",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "createdAt",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "updatedAt",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "TrustCenterFile",
|
||||
"abstractKey": null
|
||||
};
|
||||
|
||||
(node as any).hash = "33cb01782ca37fc776cd8e5dfde20f76";
|
||||
|
||||
export default node;
|
||||
@@ -47,6 +47,11 @@ export const trustCenterAccessesPaginationFragment = graphql`
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFile {
|
||||
id
|
||||
name
|
||||
category
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,16 +99,21 @@ export const createTrustCenterAccessMutation = graphql`
|
||||
title
|
||||
documentType
|
||||
}
|
||||
report {
|
||||
id
|
||||
filename
|
||||
audit {
|
||||
id
|
||||
framework {
|
||||
name
|
||||
report {
|
||||
id
|
||||
filename
|
||||
audit {
|
||||
id
|
||||
framework {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFile {
|
||||
id
|
||||
name
|
||||
category
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,16 +148,21 @@ export const updateTrustCenterAccessMutation = graphql`
|
||||
title
|
||||
documentType
|
||||
}
|
||||
report {
|
||||
id
|
||||
filename
|
||||
audit {
|
||||
report {
|
||||
id
|
||||
framework {
|
||||
name
|
||||
filename
|
||||
audit {
|
||||
id
|
||||
framework {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFile {
|
||||
id
|
||||
name
|
||||
category
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
78
apps/console/src/hooks/graph/TrustCenterFileGraph.ts
Normal file
78
apps/console/src/hooks/graph/TrustCenterFileGraph.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { graphql } from "relay-runtime";
|
||||
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
|
||||
|
||||
export const createTrustCenterFileMutation = graphql`
|
||||
mutation TrustCenterFileGraphCreateMutation(
|
||||
$input: CreateTrustCenterFileInput!
|
||||
$connections: [ID!]!
|
||||
) {
|
||||
createTrustCenterFile(input: $input) {
|
||||
trustCenterFileEdge @prependEdge(connections: $connections) {
|
||||
node {
|
||||
id
|
||||
name
|
||||
category
|
||||
fileUrl
|
||||
trustCenterVisibility
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export function useCreateTrustCenterFileMutation() {
|
||||
return useMutationWithToasts(
|
||||
createTrustCenterFileMutation,
|
||||
{
|
||||
successMessage: "File uploaded successfully",
|
||||
errorMessage: "Failed to upload file",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export const updateTrustCenterFileMutation = graphql`
|
||||
mutation TrustCenterFileGraphUpdateMutation($input: UpdateTrustCenterFileInput!) {
|
||||
updateTrustCenterFile(input: $input) {
|
||||
trustCenterFile {
|
||||
id
|
||||
name
|
||||
category
|
||||
trustCenterVisibility
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export function useUpdateTrustCenterFileMutation() {
|
||||
return useMutationWithToasts(
|
||||
updateTrustCenterFileMutation,
|
||||
{
|
||||
successMessage: "File updated successfully",
|
||||
errorMessage: "Failed to update file",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export const deleteTrustCenterFileMutation = graphql`
|
||||
mutation TrustCenterFileGraphDeleteMutation(
|
||||
$input: DeleteTrustCenterFileInput!
|
||||
$connections: [ID!]!
|
||||
) {
|
||||
deleteTrustCenterFile(input: $input) {
|
||||
deletedTrustCenterFileId @deleteEdge(connections: $connections)
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export function useDeleteTrustCenterFileMutation() {
|
||||
return useMutationWithToasts(
|
||||
deleteTrustCenterFileMutation,
|
||||
{
|
||||
successMessage: "File deleted successfully",
|
||||
errorMessage: "Failed to delete file",
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -57,6 +57,15 @@ export const trustCenterQuery = graphql`
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFiles(first: 100) @connection(key: "TrustCenterPage_trustCenterFiles") {
|
||||
__id
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
...TrustCenterFilesCardFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
slackConnections(first: 100) {
|
||||
edges {
|
||||
node {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<5c208d2afc4eb2968b59215d3e79231b>>
|
||||
* @generated SignedSource<<d527603a814e765a1a2be0900d1c59e1>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -48,6 +48,11 @@ export type TrustCenterAccessGraphCreateMutation$data = {
|
||||
readonly filename: string;
|
||||
readonly id: string;
|
||||
} | null | undefined;
|
||||
readonly trustCenterFile: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
} | null | undefined;
|
||||
readonly updatedAt: any;
|
||||
};
|
||||
}>;
|
||||
@@ -186,6 +191,26 @@ v13 = {
|
||||
"kind": "ScalarField",
|
||||
"name": "filename",
|
||||
"storageKey": null
|
||||
},
|
||||
v14 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v4/*: any*/),
|
||||
(v6/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
@@ -293,7 +318,8 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
},
|
||||
(v14/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -422,7 +448,8 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
},
|
||||
(v14/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -460,16 +487,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "a27b7cdf2a4cadf8cc22a95f39c3c6b0",
|
||||
"cacheID": "4422a02632b77f81f3b5048b5acbac98",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterAccessGraphCreateMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterAccessGraphCreateMutation(\n $input: CreateTrustCenterAccessInput!\n) {\n createTrustCenterAccess(input: $input) {\n trustCenterAccessEdge {\n cursor\n node {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 }\n }\n }\n }\n }\n }\n}\n"
|
||||
"text": "mutation TrustCenterAccessGraphCreateMutation(\n $input: CreateTrustCenterAccessInput!\n) {\n createTrustCenterAccess(input: $input) {\n trustCenterAccessEdge {\n cursor\n node {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "091432e335b8fe3a97ac06d3765f172b";
|
||||
(node as any).hash = "c09c8a22a45226949a08f2262ddd0b1c";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<bf8e5a74bfd588ad123f628009b6440e>>
|
||||
* @generated SignedSource<<8c2482b7d32c42396e4645bd309e7cc2>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -350,6 +350,26 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/),
|
||||
(v6/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -403,16 +423,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "96e9906815501bb22bca79bb63a4a149",
|
||||
"cacheID": "12322ab403d03a821d2228ff68c3d191",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterAccessGraphPaginationQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustCenterAccessGraphPaginationQuery(\n $count: Int\n $cursor: CursorKey\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...TrustCenterAccessGraph_accesses\n id\n }\n}\n\nfragment TrustCenterAccessGraph_accesses on TrustCenter {\n accesses(first: $count, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC}) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n edges {\n cursor\n node {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 }\n }\n }\n __typename\n }\n }\n }\n id\n}\n"
|
||||
"text": "query TrustCenterAccessGraphPaginationQuery(\n $count: Int\n $cursor: CursorKey\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...TrustCenterAccessGraph_accesses\n id\n }\n}\n\nfragment TrustCenterAccessGraph_accesses on TrustCenter {\n accesses(first: $count, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC}) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n edges {\n cursor\n node {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 __typename\n }\n }\n }\n id\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "9e29aa4a382ca2d4bb9d1b014d8d81fd";
|
||||
(node as any).hash = "9c7f3e866e2593c169b1f98d0e637667";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<4fcca19ac1edb0d607a9682090e0cc3e>>
|
||||
* @generated SignedSource<<e0c9c25c78bb6c8cf63eb9437947a013>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -365,6 +365,26 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v4/*: any*/),
|
||||
(v8/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -418,12 +438,12 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "4ca52668a68c0789aa73c0d680ec0abe",
|
||||
"cacheID": "37deb80fc3ff8892d2e68f7588da4e55",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterAccessGraphQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustCenterAccessGraphQuery(\n $trustCenterId: ID!\n $count: Int!\n $cursor: CursorKey\n) {\n node(id: $trustCenterId) {\n __typename\n ... on TrustCenter {\n id\n ...TrustCenterAccessGraph_accesses\n }\n id\n }\n}\n\nfragment TrustCenterAccessGraph_accesses on TrustCenter {\n accesses(first: $count, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC}) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n edges {\n cursor\n node {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 }\n }\n }\n __typename\n }\n }\n }\n id\n}\n"
|
||||
"text": "query TrustCenterAccessGraphQuery(\n $trustCenterId: ID!\n $count: Int!\n $cursor: CursorKey\n) {\n node(id: $trustCenterId) {\n __typename\n ... on TrustCenter {\n id\n ...TrustCenterAccessGraph_accesses\n }\n id\n }\n}\n\nfragment TrustCenterAccessGraph_accesses on TrustCenter {\n accesses(first: $count, after: $cursor, orderBy: {field: CREATED_AT, direction: DESC}) {\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n edges {\n cursor\n node {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 __typename\n }\n }\n }\n id\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<395567ba680d0a9e1bad1cdef52bc2e1>>
|
||||
* @generated SignedSource<<8ecf71138aa0165738506f5e589d3181>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -16,6 +16,7 @@ export type UpdateTrustCenterAccessInput = {
|
||||
id: string;
|
||||
name?: string | null | undefined;
|
||||
reportIds?: ReadonlyArray<string> | null | undefined;
|
||||
trustCenterFileIds?: ReadonlyArray<string> | null | undefined;
|
||||
};
|
||||
export type TrustCenterAccessGraphUpdateMutation$variables = {
|
||||
input: UpdateTrustCenterAccessInput;
|
||||
@@ -46,6 +47,11 @@ export type TrustCenterAccessGraphUpdateMutation$data = {
|
||||
readonly filename: string;
|
||||
readonly id: string;
|
||||
} | null | undefined;
|
||||
readonly trustCenterFile: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
} | null | undefined;
|
||||
readonly updatedAt: any;
|
||||
};
|
||||
}>;
|
||||
@@ -174,6 +180,26 @@ v11 = {
|
||||
"kind": "ScalarField",
|
||||
"name": "filename",
|
||||
"storageKey": null
|
||||
},
|
||||
v12 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v4/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
@@ -270,7 +296,8 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
},
|
||||
(v12/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -385,7 +412,8 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
},
|
||||
(v12/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -404,16 +432,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "de3ddd0058b8881667e47e2bf32c8b73",
|
||||
"cacheID": "b66da9236d9f81563608b3aa5f730908",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterAccessGraphUpdateMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterAccessGraphUpdateMutation(\n $input: UpdateTrustCenterAccessInput!\n) {\n updateTrustCenterAccess(input: $input) {\n trustCenterAccess {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n updatedAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 }\n }\n }\n }\n }\n}\n"
|
||||
"text": "mutation TrustCenterAccessGraphUpdateMutation(\n $input: UpdateTrustCenterAccessInput!\n) {\n updateTrustCenterAccess(input: $input) {\n trustCenterAccess {\n id\n email\n name\n active\n hasAcceptedNonDisclosureAgreement\n createdAt\n updatedAt\n documentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n createdAt\n updatedAt\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 }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "723058aacc2e04bd2df4cf04c6df0a3c";
|
||||
(node as any).hash = "43e73cc9d80e898f1ba2a92eaf4646f5";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<ef0d644a344dbab40145e3f4128cd0ec>>
|
||||
* @generated SignedSource<<d572a906e6afd89e4a3f1dcffa5c0528>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -40,6 +40,11 @@ export type TrustCenterAccessGraph_accesses$data = {
|
||||
readonly filename: string;
|
||||
readonly id: string;
|
||||
} | null | undefined;
|
||||
readonly trustCenterFile: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
} | null | undefined;
|
||||
readonly updatedAt: any;
|
||||
};
|
||||
}>;
|
||||
@@ -348,6 +353,26 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v3/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -393,6 +418,6 @@ return {
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "9e29aa4a382ca2d4bb9d1b014d8d81fd";
|
||||
(node as any).hash = "9c7f3e866e2593c169b1f98d0e637667";
|
||||
|
||||
export default node;
|
||||
|
||||
211
apps/console/src/hooks/graph/__generated__/TrustCenterFileGraphCreateMutation.graphql.ts
generated
Normal file
211
apps/console/src/hooks/graph/__generated__/TrustCenterFileGraphCreateMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* @generated SignedSource<<e70731a64db78c30ad662330d2ec2099>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type TrustCenterVisibility = "NONE" | "PRIVATE" | "PUBLIC";
|
||||
export type CreateTrustCenterFileInput = {
|
||||
category: string;
|
||||
file: any;
|
||||
name: string;
|
||||
organizationId: string;
|
||||
trustCenterVisibility: TrustCenterVisibility;
|
||||
};
|
||||
export type TrustCenterFileGraphCreateMutation$variables = {
|
||||
connections: ReadonlyArray<string>;
|
||||
input: CreateTrustCenterFileInput;
|
||||
};
|
||||
export type TrustCenterFileGraphCreateMutation$data = {
|
||||
readonly createTrustCenterFile: {
|
||||
readonly trustCenterFileEdge: {
|
||||
readonly node: {
|
||||
readonly category: string;
|
||||
readonly createdAt: any;
|
||||
readonly fileUrl: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly trustCenterVisibility: TrustCenterVisibility;
|
||||
readonly updatedAt: any;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
export type TrustCenterFileGraphCreateMutation = {
|
||||
response: TrustCenterFileGraphCreateMutation$data;
|
||||
variables: TrustCenterFileGraphCreateMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "connections"
|
||||
},
|
||||
v1 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
},
|
||||
v2 = [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
v3 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFileEdge",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "fileUrl",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "trustCenterVisibility",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "createdAt",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "updatedAt",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileGraphCreateMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "CreateTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "createTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": [
|
||||
(v1/*: any*/),
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"kind": "Operation",
|
||||
"name": "TrustCenterFileGraphCreateMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "CreateTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "createTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"filters": null,
|
||||
"handle": "prependEdge",
|
||||
"key": "",
|
||||
"kind": "LinkedHandle",
|
||||
"name": "trustCenterFileEdge",
|
||||
"handleArgs": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "connections",
|
||||
"variableName": "connections"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "57c42327b83556d36745cf8218eb01b1",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterFileGraphCreateMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterFileGraphCreateMutation(\n $input: CreateTrustCenterFileInput!\n) {\n createTrustCenterFile(input: $input) {\n trustCenterFileEdge {\n node {\n id\n name\n category\n fileUrl\n trustCenterVisibility\n createdAt\n updatedAt\n }\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "fa3851bf4f5e38bc26d8a063d6afab4e";
|
||||
|
||||
export default node;
|
||||
132
apps/console/src/hooks/graph/__generated__/TrustCenterFileGraphDeleteMutation.graphql.ts
generated
Normal file
132
apps/console/src/hooks/graph/__generated__/TrustCenterFileGraphDeleteMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* @generated SignedSource<<f788919caaf846a6a1bdc81f19841823>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type DeleteTrustCenterFileInput = {
|
||||
id: string;
|
||||
};
|
||||
export type TrustCenterFileGraphDeleteMutation$variables = {
|
||||
connections: ReadonlyArray<string>;
|
||||
input: DeleteTrustCenterFileInput;
|
||||
};
|
||||
export type TrustCenterFileGraphDeleteMutation$data = {
|
||||
readonly deleteTrustCenterFile: {
|
||||
readonly deletedTrustCenterFileId: string;
|
||||
};
|
||||
};
|
||||
export type TrustCenterFileGraphDeleteMutation = {
|
||||
response: TrustCenterFileGraphDeleteMutation$data;
|
||||
variables: TrustCenterFileGraphDeleteMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "connections"
|
||||
},
|
||||
v1 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
},
|
||||
v2 = [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
v3 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "deletedTrustCenterFileId",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileGraphDeleteMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "DeleteTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "deleteTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": [
|
||||
(v1/*: any*/),
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"kind": "Operation",
|
||||
"name": "TrustCenterFileGraphDeleteMutation",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "DeleteTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "deleteTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v3/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"filters": null,
|
||||
"handle": "deleteEdge",
|
||||
"key": "",
|
||||
"kind": "ScalarHandle",
|
||||
"name": "deletedTrustCenterFileId",
|
||||
"handleArgs": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "connections",
|
||||
"variableName": "connections"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "ad78a064da9b58291653f8283012ffc6",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterFileGraphDeleteMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterFileGraphDeleteMutation(\n $input: DeleteTrustCenterFileInput!\n) {\n deleteTrustCenterFile(input: $input) {\n deletedTrustCenterFileId\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "26c1ce69e74f3a4a39d060b38afbe3e0";
|
||||
|
||||
export default node;
|
||||
141
apps/console/src/hooks/graph/__generated__/TrustCenterFileGraphUpdateMutation.graphql.ts
generated
Normal file
141
apps/console/src/hooks/graph/__generated__/TrustCenterFileGraphUpdateMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* @generated SignedSource<<b78cfbea93f3bccdba56cd29900ab724>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type TrustCenterVisibility = "NONE" | "PRIVATE" | "PUBLIC";
|
||||
export type UpdateTrustCenterFileInput = {
|
||||
category?: string | null | undefined;
|
||||
id: string;
|
||||
name?: string | null | undefined;
|
||||
trustCenterVisibility?: TrustCenterVisibility | null | undefined;
|
||||
};
|
||||
export type TrustCenterFileGraphUpdateMutation$variables = {
|
||||
input: UpdateTrustCenterFileInput;
|
||||
};
|
||||
export type TrustCenterFileGraphUpdateMutation$data = {
|
||||
readonly updateTrustCenterFile: {
|
||||
readonly trustCenterFile: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly trustCenterVisibility: TrustCenterVisibility;
|
||||
readonly updatedAt: any;
|
||||
};
|
||||
};
|
||||
};
|
||||
export type TrustCenterFileGraphUpdateMutation = {
|
||||
response: TrustCenterFileGraphUpdateMutation$data;
|
||||
variables: TrustCenterFileGraphUpdateMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "UpdateTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "updateTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "trustCenterVisibility",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "updatedAt",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileGraphUpdateMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "TrustCenterFileGraphUpdateMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "9ad761d91cfe34e7fa905a3f6a4d9e37",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterFileGraphUpdateMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterFileGraphUpdateMutation(\n $input: UpdateTrustCenterFileInput!\n) {\n updateTrustCenterFile(input: $input) {\n trustCenterFile {\n id\n name\n category\n trustCenterVisibility\n updatedAt\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "7306c3f9530a7636adc0b6a0cf28b67e";
|
||||
|
||||
export default node;
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<6d55d37aa2ddfae16f8fc829840113d4>>
|
||||
* @generated SignedSource<<285497dfb150c3f02c055a091769f301>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -69,6 +69,15 @@ export type TrustCenterGraphQuery$data = {
|
||||
};
|
||||
readonly updatedAt: any;
|
||||
} | null | undefined;
|
||||
readonly trustCenterFiles?: {
|
||||
readonly __id: string;
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly id: string;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFilesCardFragment">;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
readonly vendors?: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
@@ -259,6 +268,57 @@ v10 = [
|
||||
(v7/*: any*/)
|
||||
],
|
||||
v11 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "__typename",
|
||||
"storageKey": null
|
||||
},
|
||||
v12 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "cursor",
|
||||
"storageKey": null
|
||||
},
|
||||
v13 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "PageInfo",
|
||||
"kind": "LinkedField",
|
||||
"name": "pageInfo",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "endCursor",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasNextPage",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
v14 = {
|
||||
"kind": "ClientExtension",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "__id",
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
v15 = {
|
||||
"alias": null,
|
||||
"args": (v10/*: any*/),
|
||||
"concreteType": "SlackConnectionConnection",
|
||||
@@ -308,12 +368,19 @@ v11 = {
|
||||
],
|
||||
"storageKey": "slackConnections(first:100)"
|
||||
},
|
||||
v12 = {
|
||||
v16 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "trustCenterVisibility",
|
||||
"storageKey": null
|
||||
},
|
||||
v17 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
@@ -454,7 +521,50 @@ return {
|
||||
],
|
||||
"storageKey": "vendors(first:100)"
|
||||
},
|
||||
(v11/*: any*/)
|
||||
{
|
||||
"alias": "trustCenterFiles",
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "__TrustCenterPage_trustCenterFiles_connection",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"args": null,
|
||||
"kind": "FragmentSpread",
|
||||
"name": "TrustCenterFilesCardFragment"
|
||||
},
|
||||
(v11/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
(v12/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
(v13/*: any*/),
|
||||
(v14/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
(v15/*: any*/)
|
||||
],
|
||||
"type": "Organization",
|
||||
"abstractKey": null
|
||||
@@ -480,13 +590,7 @@ return {
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "__typename",
|
||||
"storageKey": null
|
||||
},
|
||||
(v11/*: any*/),
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"kind": "InlineFragment",
|
||||
@@ -534,7 +638,7 @@ return {
|
||||
"name": "documentType",
|
||||
"storageKey": null
|
||||
},
|
||||
(v12/*: any*/),
|
||||
(v16/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
@@ -651,7 +755,7 @@ return {
|
||||
"name": "state",
|
||||
"storageKey": null
|
||||
},
|
||||
(v12/*: any*/),
|
||||
(v16/*: any*/),
|
||||
(v5/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -688,13 +792,7 @@ return {
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v3/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
(v17/*: any*/),
|
||||
(v8/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
@@ -713,7 +811,66 @@ return {
|
||||
],
|
||||
"storageKey": "vendors(first:100)"
|
||||
},
|
||||
(v11/*: any*/)
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v10/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v3/*: any*/),
|
||||
(v17/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "fileUrl",
|
||||
"storageKey": null
|
||||
},
|
||||
(v16/*: any*/),
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/),
|
||||
(v11/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
(v12/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
(v13/*: any*/),
|
||||
(v14/*: any*/)
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:100)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v10/*: any*/),
|
||||
"filters": null,
|
||||
"handle": "connection",
|
||||
"key": "TrustCenterPage_trustCenterFiles",
|
||||
"kind": "LinkedHandle",
|
||||
"name": "trustCenterFiles"
|
||||
},
|
||||
(v15/*: any*/)
|
||||
],
|
||||
"type": "Organization",
|
||||
"abstractKey": null
|
||||
@@ -724,16 +881,28 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "06cd2015e9fc2e65d35ae3153e587c58",
|
||||
"cacheID": "45a68d6b8fc3128a695529daa40eba3a",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"metadata": {
|
||||
"connection": [
|
||||
{
|
||||
"count": null,
|
||||
"cursor": null,
|
||||
"direction": "forward",
|
||||
"path": [
|
||||
"organization",
|
||||
"trustCenterFiles"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": "TrustCenterGraphQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustCenterGraphQuery(\n $organizationId: ID!\n) {\n organization: node(id: $organizationId) {\n __typename\n ... on Organization {\n id\n name\n customDomain {\n id\n domain\n }\n trustCenter {\n id\n active\n ndaFileName\n ndaFileUrl\n createdAt\n updatedAt\n references(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n name\n description\n websiteUrl\n logoUrl\n createdAt\n updatedAt\n }\n }\n }\n }\n documents(first: 100) {\n edges {\n node {\n id\n ...TrustCenterDocumentsCardFragment\n }\n }\n }\n audits(first: 100) {\n edges {\n node {\n id\n ...TrustCenterAuditsCardFragment\n }\n }\n }\n vendors(first: 100) {\n edges {\n node {\n id\n ...TrustCenterVendorsCardFragment\n }\n }\n }\n slackConnections(first: 100) {\n edges {\n node {\n id\n channel\n channelId\n createdAt\n updatedAt\n }\n }\n }\n }\n id\n }\n}\n\nfragment TrustCenterAuditsCardFragment on Audit {\n id\n name\n framework {\n name\n id\n }\n validFrom\n validUntil\n state\n trustCenterVisibility\n createdAt\n}\n\nfragment TrustCenterDocumentsCardFragment on Document {\n id\n title\n createdAt\n documentType\n trustCenterVisibility\n versions(first: 1) {\n edges {\n node {\n id\n status\n }\n }\n }\n}\n\nfragment TrustCenterVendorsCardFragment on Vendor {\n id\n name\n category\n description\n showOnTrustCenter\n createdAt\n}\n"
|
||||
"text": "query TrustCenterGraphQuery(\n $organizationId: ID!\n) {\n organization: node(id: $organizationId) {\n __typename\n ... on Organization {\n id\n name\n customDomain {\n id\n domain\n }\n trustCenter {\n id\n active\n ndaFileName\n ndaFileUrl\n createdAt\n updatedAt\n references(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n name\n description\n websiteUrl\n logoUrl\n createdAt\n updatedAt\n }\n }\n }\n }\n documents(first: 100) {\n edges {\n node {\n id\n ...TrustCenterDocumentsCardFragment\n }\n }\n }\n audits(first: 100) {\n edges {\n node {\n id\n ...TrustCenterAuditsCardFragment\n }\n }\n }\n vendors(first: 100) {\n edges {\n node {\n id\n ...TrustCenterVendorsCardFragment\n }\n }\n }\n trustCenterFiles(first: 100) {\n edges {\n node {\n id\n ...TrustCenterFilesCardFragment\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n slackConnections(first: 100) {\n edges {\n node {\n id\n channel\n channelId\n createdAt\n updatedAt\n }\n }\n }\n }\n id\n }\n}\n\nfragment TrustCenterAuditsCardFragment on Audit {\n id\n name\n framework {\n name\n id\n }\n validFrom\n validUntil\n state\n trustCenterVisibility\n createdAt\n}\n\nfragment TrustCenterDocumentsCardFragment on Document {\n id\n title\n createdAt\n documentType\n trustCenterVisibility\n versions(first: 1) {\n edges {\n node {\n id\n status\n }\n }\n }\n}\n\nfragment TrustCenterFilesCardFragment on TrustCenterFile {\n id\n name\n category\n fileUrl\n trustCenterVisibility\n createdAt\n updatedAt\n}\n\nfragment TrustCenterVendorsCardFragment on Vendor {\n id\n name\n category\n description\n showOnTrustCenter\n createdAt\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "7ef9a5adc70dff604a149ea156e52edc";
|
||||
(node as any).hash = "1ee50612da47b187cb55b2e228ba5945";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Checkbox,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
updateTrustCenterAccessMutation,
|
||||
deleteTrustCenterAccessMutation
|
||||
} from "/hooks/graph/TrustCenterAccessGraph";
|
||||
import type { TrustCenterAccessGraph_accesses$data } from "/hooks/graph/__generated__/TrustCenterAccessGraph_accesses.graphql";
|
||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
|
||||
|
||||
@@ -76,6 +78,10 @@ export default function TrustCenterAccessTab() {
|
||||
const [selectedDocumentAccesses, setSelectedDocumentAccesses] = useState<Set<string>>(new Set());
|
||||
const [pendingEditEmail, setPendingEditEmail] = useState<string | null>(null);
|
||||
|
||||
const formattedDocumentAccesses = editingAccess?.documentAccesses
|
||||
?.map((docAccess) => getDocumentAccessInfo(docAccess, __))
|
||||
?.filter((info) => info !== null) ?? [];
|
||||
|
||||
const inviteForm = useFormWithSchema(inviteSchema, {
|
||||
defaultValues: { name: "", email: "" },
|
||||
});
|
||||
@@ -102,8 +108,48 @@ export default function TrustCenterAccessTab() {
|
||||
};
|
||||
};
|
||||
} | null;
|
||||
trustCenterFile?: {
|
||||
id: string;
|
||||
name: string;
|
||||
category: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
function getDocumentAccessInfo(
|
||||
docAccess: DocumentAccessType,
|
||||
__: (key: string) => string
|
||||
) {
|
||||
if (!!docAccess.document) {
|
||||
return {
|
||||
variant: "info" as const,
|
||||
name: docAccess.document?.title,
|
||||
type: __("Document"),
|
||||
category: docAccess.document?.documentType,
|
||||
id: docAccess.document?.id,
|
||||
};
|
||||
}
|
||||
if (!!docAccess.report) {
|
||||
return {
|
||||
variant: "success" as const,
|
||||
name: docAccess.report?.filename,
|
||||
type: __("Report"),
|
||||
category: docAccess.report?.audit?.framework?.name,
|
||||
id: docAccess.report?.id,
|
||||
};
|
||||
}
|
||||
if (!!docAccess.trustCenterFile) {
|
||||
return {
|
||||
variant: "highlight" as const,
|
||||
name: docAccess.trustCenterFile?.name,
|
||||
type: __("File"),
|
||||
category: docAccess.trustCenterFile?.category,
|
||||
id: docAccess.trustCenterFile?.id,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
type AccessType = {
|
||||
id: string;
|
||||
email: string;
|
||||
@@ -116,18 +162,22 @@ export default function TrustCenterAccessTab() {
|
||||
|
||||
const { data: trustCenterData, loadMore, hasNext, isLoadingNext } = useTrustCenterAccesses(organization.trustCenter?.id || "");
|
||||
|
||||
const accesses: AccessType[] = trustCenterData?.node?.accesses?.edges?.map((edge: any) => ({
|
||||
type AccessEdge = NonNullable<NonNullable<TrustCenterAccessGraph_accesses$data['accesses']>['edges']>[number];
|
||||
type DocumentAccessEdge = NonNullable<NonNullable<NonNullable<AccessEdge>['node']['documentAccesses']>['edges']>[number];
|
||||
|
||||
const accesses: AccessType[] = trustCenterData?.node?.accesses?.edges?.map((edge: AccessEdge) => ({
|
||||
id: edge.node.id,
|
||||
email: edge.node.email,
|
||||
name: edge.node.name,
|
||||
active: edge.node.active,
|
||||
hasAcceptedNonDisclosureAgreement: edge.node.hasAcceptedNonDisclosureAgreement,
|
||||
createdAt: edge.node.createdAt,
|
||||
documentAccesses: edge.node.documentAccesses?.edges?.map((docEdge: any) => ({
|
||||
documentAccesses: edge.node.documentAccesses?.edges?.map((docEdge: DocumentAccessEdge) => ({
|
||||
id: docEdge.node.id,
|
||||
active: docEdge.node.active,
|
||||
document: docEdge.node.document,
|
||||
report: docEdge.node.report
|
||||
report: docEdge.node.report,
|
||||
trustCenterFile: docEdge.node.trustCenterFile
|
||||
})) ?? []
|
||||
})) ?? [];
|
||||
|
||||
@@ -173,7 +223,7 @@ export default function TrustCenterAccessTab() {
|
||||
const getActiveDocumentIds = useCallback((access: AccessType) => {
|
||||
return access.documentAccesses
|
||||
.filter(docAccess => docAccess.active)
|
||||
.map(docAccess => docAccess.document?.id || docAccess.report?.id)
|
||||
.map(docAccess => docAccess.document?.id || docAccess.report?.id || docAccess.trustCenterFile?.id)
|
||||
.filter((id): id is string => id !== undefined);
|
||||
}, []);
|
||||
|
||||
@@ -212,19 +262,21 @@ export default function TrustCenterAccessTab() {
|
||||
const handleUpdateName = editForm.handleSubmit(async (data) => {
|
||||
if (!editingAccess) return;
|
||||
|
||||
const { documentIds, reportIds } = editingAccess.documentAccesses.reduce(
|
||||
const { documentIds, reportIds, trustCenterFileIds } = editingAccess.documentAccesses.reduce(
|
||||
(acc, docAccess) => {
|
||||
const id = docAccess.document?.id || docAccess.report?.id;
|
||||
const id = docAccess.document?.id || docAccess.report?.id || docAccess.trustCenterFile?.id;
|
||||
if (id && selectedDocumentAccesses.has(id)) {
|
||||
if (docAccess.document?.id) {
|
||||
acc.documentIds.push(docAccess.document.id);
|
||||
} else if (docAccess.report?.id) {
|
||||
acc.reportIds.push(docAccess.report.id);
|
||||
} else if (docAccess.trustCenterFile?.id) {
|
||||
acc.trustCenterFileIds.push(docAccess.trustCenterFile.id);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{ documentIds: [] as string[], reportIds: [] as string[] }
|
||||
{ documentIds: [] as string[], reportIds: [] as string[], trustCenterFileIds: [] as string[] }
|
||||
);
|
||||
|
||||
await updateInvitation({
|
||||
@@ -235,6 +287,7 @@ export default function TrustCenterAccessTab() {
|
||||
active: data.active,
|
||||
documentIds,
|
||||
reportIds,
|
||||
trustCenterFileIds,
|
||||
},
|
||||
},
|
||||
onSuccess: () => {
|
||||
@@ -431,7 +484,7 @@ export default function TrustCenterAccessTab() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{editingAccess && editingAccess.documentAccesses.length > 0 && (
|
||||
{formattedDocumentAccesses.length > 0 && (
|
||||
<div>
|
||||
<h4 className="font-medium text-txt-primary mb-4">
|
||||
{__("Document Access Permissions")}
|
||||
@@ -451,39 +504,20 @@ export default function TrustCenterAccessTab() {
|
||||
</Tr>
|
||||
</Thead>
|
||||
<Tbody>
|
||||
{editingAccess.documentAccesses.map((docAccess) => {
|
||||
const getDocumentInfo = () => {
|
||||
const isDocument = !!docAccess.document;
|
||||
return {
|
||||
isDocument,
|
||||
name: docAccess.document?.title || docAccess.report?.filename || __("Unknown Item"),
|
||||
type: isDocument ? __("Document") : __("Report"),
|
||||
category: isDocument
|
||||
? docAccess.document?.documentType
|
||||
: docAccess.report?.audit?.framework?.name || __("Compliance Report"),
|
||||
id: docAccess.document?.id || docAccess.report?.id || ''
|
||||
};
|
||||
};
|
||||
|
||||
const { isDocument, name, type, category, id } = getDocumentInfo();
|
||||
{formattedDocumentAccesses.map((info) => {
|
||||
const { variant, name, type, category, id } = info;
|
||||
|
||||
return (
|
||||
<Tr key={docAccess.id}>
|
||||
<Tr key={id}>
|
||||
<Td>
|
||||
<div className="font-medium text-txt-primary">
|
||||
{name}
|
||||
</div>
|
||||
</Td>
|
||||
<Td>
|
||||
<div className="flex items-center space-x-2">
|
||||
<div className={`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${
|
||||
isDocument
|
||||
? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200'
|
||||
: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200'
|
||||
}`}>
|
||||
{type}
|
||||
</div>
|
||||
</div>
|
||||
<Badge variant={variant}>
|
||||
{type}
|
||||
</Badge>
|
||||
</Td>
|
||||
<Td>
|
||||
<div className="text-txt-secondary">
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
Field,
|
||||
Spinner,
|
||||
useDialogRef,
|
||||
Dropzone,
|
||||
Option,
|
||||
Badge,
|
||||
} from "@probo/ui";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { useOutletContext } from "react-router";
|
||||
import { useState, useCallback } from "react";
|
||||
import z from "zod";
|
||||
import { getTrustCenterVisibilityOptions } from "@probo/helpers";
|
||||
import {
|
||||
useCreateTrustCenterFileMutation,
|
||||
useUpdateTrustCenterFileMutation,
|
||||
useDeleteTrustCenterFileMutation,
|
||||
} from "/hooks/graph/TrustCenterFileGraph";
|
||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||
import { TrustCenterFilesCard } from "/components/trustCenter/TrustCenterFilesCard";
|
||||
import type { TrustCenterFilesCardFragment$key } from "/components/trustCenter/__generated__/TrustCenterFilesCardFragment.graphql";
|
||||
|
||||
type ContextType = {
|
||||
organization: {
|
||||
id: string;
|
||||
trustCenterFiles?: {
|
||||
__id?: string;
|
||||
edges: Array<{
|
||||
node: TrustCenterFilesCardFragment$key;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export default function TrustCenterFilesTab() {
|
||||
const { __ } = useTranslate();
|
||||
const { organization } = useOutletContext<ContextType>();
|
||||
|
||||
const createSchema = z.object({
|
||||
name: z.string().min(1, __("Name is required")),
|
||||
category: z.string().min(1, __("Category is required")),
|
||||
trustCenterVisibility: z.enum(["NONE", "PRIVATE", "PUBLIC"]),
|
||||
});
|
||||
|
||||
const editSchema = z.object({
|
||||
name: z.string().min(1, __("Name is required")),
|
||||
category: z.string().min(1, __("Category is required")),
|
||||
});
|
||||
|
||||
const [createFile, isCreating] = useCreateTrustCenterFileMutation();
|
||||
const [updateFile, isUpdating] = useUpdateTrustCenterFileMutation();
|
||||
const [deleteFile, isDeleting] = useDeleteTrustCenterFileMutation();
|
||||
|
||||
const createDialogRef = useDialogRef();
|
||||
const editDialogRef = useDialogRef();
|
||||
const deleteDialogRef = useDialogRef();
|
||||
|
||||
const [editingFile, setEditingFile] = useState<{ id: string; name: string; category: string } | null>(null);
|
||||
const [deletingFileId, setDeletingFileId] = useState<string | null>(null);
|
||||
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
|
||||
const createForm = useFormWithSchema(createSchema, {
|
||||
defaultValues: { name: "", category: "", trustCenterVisibility: "NONE" },
|
||||
});
|
||||
|
||||
const editForm = useFormWithSchema(editSchema, {
|
||||
defaultValues: { name: "", category: "" },
|
||||
});
|
||||
|
||||
const files = organization.trustCenterFiles?.edges?.map((edge) => edge.node) || [];
|
||||
|
||||
const handleFileUpload = useCallback((acceptedFiles: File[]) => {
|
||||
if (acceptedFiles.length > 0) {
|
||||
const file = acceptedFiles[0];
|
||||
|
||||
if (file.type !== "application/pdf") {
|
||||
createForm.setError("root", {
|
||||
type: "manual",
|
||||
message: __("Only PDF files are allowed"),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setUploadedFile(file);
|
||||
createForm.clearErrors("root");
|
||||
if (!createForm.getValues().name) {
|
||||
createForm.setValue("name", file.name.replace(/\.[^/.]+$/, ""));
|
||||
}
|
||||
}
|
||||
}, [createForm, __]);
|
||||
|
||||
const handleCreate = createForm.handleSubmit(async (data) => {
|
||||
if (!uploadedFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsUploading(true);
|
||||
|
||||
const connectionId = organization.trustCenterFiles?.__id;
|
||||
|
||||
try {
|
||||
await createFile({
|
||||
variables: {
|
||||
input: {
|
||||
organizationId: organization.id,
|
||||
name: data.name,
|
||||
category: data.category,
|
||||
trustCenterVisibility: data.trustCenterVisibility,
|
||||
file: null,
|
||||
},
|
||||
connections: connectionId ? [connectionId] : [],
|
||||
},
|
||||
uploadables: {
|
||||
"input.file": uploadedFile,
|
||||
},
|
||||
onSuccess: () => {
|
||||
createDialogRef.current?.close();
|
||||
createForm.reset();
|
||||
setUploadedFile(null);
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
});
|
||||
|
||||
const handleEdit = useCallback((file: { id: string; name: string; category: string }) => {
|
||||
setEditingFile(file);
|
||||
editForm.reset({ name: file.name, category: file.category });
|
||||
editDialogRef.current?.open();
|
||||
}, [editDialogRef, editForm]);
|
||||
|
||||
const handleUpdate = editForm.handleSubmit(async (data) => {
|
||||
if (!editingFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
await updateFile({
|
||||
variables: {
|
||||
input: {
|
||||
id: editingFile.id,
|
||||
name: data.name,
|
||||
category: data.category,
|
||||
},
|
||||
},
|
||||
onSuccess: () => {
|
||||
editDialogRef.current?.close();
|
||||
setEditingFile(null);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const handleDeleteClick = useCallback((id: string) => {
|
||||
setDeletingFileId(id);
|
||||
deleteDialogRef.current?.open();
|
||||
}, [deleteDialogRef]);
|
||||
|
||||
const handleDeleteConfirm = useCallback(async () => {
|
||||
if (!deletingFileId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const connectionId = organization.trustCenterFiles?.__id;
|
||||
|
||||
await deleteFile({
|
||||
variables: {
|
||||
input: { id: deletingFileId },
|
||||
connections: connectionId ? [connectionId] : [],
|
||||
},
|
||||
onSuccess: () => {
|
||||
deleteDialogRef.current?.close();
|
||||
setDeletingFileId(null);
|
||||
},
|
||||
});
|
||||
}, [deletingFileId, deleteFile, deleteDialogRef, organization.trustCenterFiles?.__id]);
|
||||
|
||||
const handleChangeVisibility = useCallback((params: {
|
||||
variables: {
|
||||
input: {
|
||||
id: string;
|
||||
trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC";
|
||||
};
|
||||
};
|
||||
}) => {
|
||||
updateFile(params);
|
||||
}, [updateFile]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="text-base font-medium">{__("Files")}</h3>
|
||||
<p className="text-sm text-txt-tertiary">
|
||||
{__("Upload and manage files for your trust center")}
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => createDialogRef.current?.open()}>
|
||||
{__("Add File")}
|
||||
</Button>
|
||||
</div>
|
||||
{(isUpdating || isDeleting) && (
|
||||
<div className="flex items-center justify-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
<Card padded>
|
||||
<TrustCenterFilesCard
|
||||
files={files}
|
||||
params={{}}
|
||||
disabled={isUpdating || isDeleting}
|
||||
onChangeVisibility={handleChangeVisibility}
|
||||
onEdit={handleEdit}
|
||||
onDelete={handleDeleteClick}
|
||||
variant="table"
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<Dialog ref={createDialogRef} title={__("Add File")}>
|
||||
<form onSubmit={handleCreate}>
|
||||
<DialogContent padded className="space-y-4">
|
||||
<Dropzone
|
||||
description={__("Upload PDF file (max 10MB)")}
|
||||
isUploading={isUploading}
|
||||
onDrop={handleFileUpload}
|
||||
maxSize={10}
|
||||
accept={{ "application/pdf": [".pdf"] }}
|
||||
/>
|
||||
{uploadedFile && (
|
||||
<div className="text-sm text-txt-secondary">
|
||||
{__("Selected file")}: {uploadedFile.name}
|
||||
</div>
|
||||
)}
|
||||
{createForm.formState.errors.root && (
|
||||
<p className="text-sm text-txt-danger">
|
||||
{createForm.formState.errors.root.message}
|
||||
</p>
|
||||
)}
|
||||
<Field
|
||||
label={__("Name")}
|
||||
type="text"
|
||||
{...createForm.register("name")}
|
||||
error={createForm.formState.errors.name?.message}
|
||||
/>
|
||||
<Field
|
||||
label={__("Category")}
|
||||
type="text"
|
||||
{...createForm.register("category")}
|
||||
error={createForm.formState.errors.category?.message}
|
||||
/>
|
||||
<Field
|
||||
label={__("Visibility")}
|
||||
type="select"
|
||||
value={createForm.watch("trustCenterVisibility")}
|
||||
onValueChange={(value) => createForm.setValue("trustCenterVisibility", value as "NONE" | "PRIVATE" | "PUBLIC")}
|
||||
error={createForm.formState.errors.trustCenterVisibility?.message}
|
||||
>
|
||||
{getTrustCenterVisibilityOptions(__).map((option) => (
|
||||
<Option key={option.value} value={option.value}>
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<Badge variant={option.variant}>
|
||||
{option.label}
|
||||
</Badge>
|
||||
</div>
|
||||
</Option>
|
||||
))}
|
||||
</Field>
|
||||
</DialogContent>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isCreating || isUploading || !uploadedFile}
|
||||
>
|
||||
{(isCreating || isUploading) && <Spinner />}
|
||||
{__("Add File")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Dialog>
|
||||
|
||||
<Dialog ref={editDialogRef} title={__("Edit File")}>
|
||||
<form onSubmit={handleUpdate}>
|
||||
<DialogContent padded className="space-y-4">
|
||||
<Field
|
||||
label={__("Name")}
|
||||
type="text"
|
||||
{...editForm.register("name")}
|
||||
error={editForm.formState.errors.name?.message}
|
||||
/>
|
||||
<Field
|
||||
label={__("Category")}
|
||||
type="text"
|
||||
{...editForm.register("category")}
|
||||
error={editForm.formState.errors.category?.message}
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isUpdating}
|
||||
>
|
||||
{isUpdating && <Spinner />}
|
||||
{__("Save")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Dialog>
|
||||
|
||||
<Dialog ref={deleteDialogRef} title={__("Delete File")}>
|
||||
<DialogContent padded>
|
||||
<p>{__("Are you sure you want to delete this file? This action cannot be undone.")}</p>
|
||||
</DialogContent>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="danger"
|
||||
onClick={handleDeleteConfirm}
|
||||
disabled={isDeleting}
|
||||
>
|
||||
{isDeleting && <Spinner />}
|
||||
{__("Delete")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -287,6 +287,9 @@ export default function TrustCenterPage({ queryRef }: Props) {
|
||||
<TabLink to={`/organizations/${organizationId}/trust-center/documents`}>
|
||||
{__("Documents")}
|
||||
</TabLink>
|
||||
<TabLink to={`/organizations/${organizationId}/trust-center/files`}>
|
||||
{__("Files")}
|
||||
</TabLink>
|
||||
<TabLink to={`/organizations/${organizationId}/trust-center/access`}>
|
||||
{__("Access")}
|
||||
</TabLink>
|
||||
|
||||
@@ -44,6 +44,13 @@ export const trustCenterRoutes = [
|
||||
() => import("/pages/organizations/trustCenter/TrustCenterDocumentsTab")
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "files",
|
||||
fallback: LinkCardSkeleton,
|
||||
Component: lazy(
|
||||
() => import("/pages/organizations/trustCenter/TrustCenterFilesTab")
|
||||
),
|
||||
},
|
||||
{
|
||||
path: "access",
|
||||
fallback: LinkCardSkeleton,
|
||||
|
||||
@@ -21,6 +21,7 @@ import { useIsAuthenticated } from "/hooks/useIsAuthenticated.ts";
|
||||
type Props = PropsWithChildren<{
|
||||
documentId?: string;
|
||||
reportId?: string;
|
||||
trustCenterFileId?: string;
|
||||
onSuccess?: () => void;
|
||||
}>;
|
||||
|
||||
@@ -33,6 +34,7 @@ export function RequestAccessDialog({
|
||||
children,
|
||||
documentId,
|
||||
reportId,
|
||||
trustCenterFileId,
|
||||
onSuccess,
|
||||
}: Props) {
|
||||
const trustCenter = useTrustCenter();
|
||||
@@ -46,7 +48,7 @@ export function RequestAccessDialog({
|
||||
});
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const dialogRef = useDialogRef();
|
||||
const [commitMutation, isMutating] = useMutation({ documentId, reportId });
|
||||
const [commitMutation, isMutating] = useMutation({ documentId, reportId, trustCenterFileId });
|
||||
|
||||
const submitCallback = (data: z.infer<typeof schema> | null) => {
|
||||
commitMutation(data)
|
||||
@@ -155,13 +157,26 @@ const requestReportAccessMutation = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
const requestTrustCenterFileAccessMutation = graphql`
|
||||
mutation RequestAccessDialogTrustCenterFileMutation(
|
||||
$input: RequestTrustCenterFileAccessInput!
|
||||
) {
|
||||
requestTrustCenterFileAccess(input: $input) {
|
||||
trustCenterAccess {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Use the correct mutation using the shape
|
||||
*/
|
||||
function useMutation({
|
||||
documentId,
|
||||
reportId,
|
||||
}: Pick<Props, "documentId" | "reportId">): [
|
||||
trustCenterFileId,
|
||||
}: Pick<Props, "documentId" | "reportId" | "trustCenterFileId">): [
|
||||
(data: z.infer<typeof schema> | null) => Promise<unknown>,
|
||||
boolean,
|
||||
] {
|
||||
@@ -173,8 +188,25 @@ function useMutation({
|
||||
useMutationWithToasts(requestDocumentAccessMutation);
|
||||
const [commitRequestReportAccess, isRequestingReportAccess] =
|
||||
useMutationWithToasts(requestReportAccessMutation);
|
||||
const [commitRequestTrustCenterFileAccess, isRequestingTrustCenterFileAccess] =
|
||||
useMutationWithToasts(requestTrustCenterFileAccessMutation);
|
||||
|
||||
if (reportId) {
|
||||
if (trustCenterFileId) {
|
||||
return [
|
||||
(data) => {
|
||||
return commitRequestTrustCenterFileAccess({
|
||||
variables: {
|
||||
input: {
|
||||
trustCenterId: trustCenter.id,
|
||||
trustCenterFileId: trustCenterFileId,
|
||||
...data,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
isRequestingTrustCenterFileAccess,
|
||||
];
|
||||
} else if (reportId) {
|
||||
return [
|
||||
(data) => {
|
||||
return commitRequestReportAccess({
|
||||
|
||||
88
apps/trust/src/components/TrustCenterFileRow.tsx
Normal file
88
apps/trust/src/components/TrustCenterFileRow.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import { graphql } from "relay-runtime";
|
||||
import type { TrustCenterFileRowFragment$key } from "./__generated__/TrustCenterFileRowFragment.graphql";
|
||||
import { useFragment } from "react-relay";
|
||||
import {
|
||||
Button,
|
||||
IconArrowInbox,
|
||||
IconLock,
|
||||
IconPageTextLine,
|
||||
Spinner,
|
||||
} from "@probo/ui";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import type { TrustCenterFileRowDownloadMutation } from "./__generated__/TrustCenterFileRowDownloadMutation.graphql";
|
||||
import { useMutationWithToasts } from "/hooks/useMutationWithToast";
|
||||
import { downloadFile } from "@probo/helpers";
|
||||
import { RequestAccessDialog } from "/components/RequestAccessDialog.tsx";
|
||||
import { useState } from "react";
|
||||
|
||||
const downloadMutation = graphql`
|
||||
mutation TrustCenterFileRowDownloadMutation($input: ExportTrustCenterFileInput!) {
|
||||
exportTrustCenterFile(input: $input) {
|
||||
data
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const trustCenterFileRowFragment = graphql`
|
||||
fragment TrustCenterFileRowFragment on TrustCenterFile {
|
||||
id
|
||||
name
|
||||
isUserAuthorized
|
||||
hasUserRequestedAccess
|
||||
}
|
||||
`;
|
||||
|
||||
export function TrustCenterFileRow(props: { file: TrustCenterFileRowFragment$key }) {
|
||||
const file = useFragment(trustCenterFileRowFragment, props.file);
|
||||
const { __ } = useTranslate();
|
||||
const [commitDownload, downloading] =
|
||||
useMutationWithToasts<TrustCenterFileRowDownloadMutation>(downloadMutation);
|
||||
const handleDownload = () => {
|
||||
commitDownload({
|
||||
variables: {
|
||||
input: {
|
||||
trustCenterFileId: file.id,
|
||||
},
|
||||
},
|
||||
onSuccess(response) {
|
||||
downloadFile(response.exportTrustCenterFile.data, file.name);
|
||||
},
|
||||
});
|
||||
};
|
||||
const [hasRequested, setHasRequested] = useState(
|
||||
file.hasUserRequestedAccess,
|
||||
);
|
||||
return (
|
||||
<div className="text-sm border-1 border-border-solid -mt-[1px] flex gap-3 flex-col md:flex-row md:justify-between px-6 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<IconPageTextLine size={16} className=" flex-none text-txt-tertiary" />
|
||||
{file.name}
|
||||
</div>
|
||||
{file.isUserAuthorized ? (
|
||||
<Button
|
||||
className="w-full md:w-max"
|
||||
variant="secondary"
|
||||
disabled={downloading}
|
||||
icon={downloading ? Spinner : IconArrowInbox}
|
||||
onClick={handleDownload}
|
||||
>
|
||||
{__("Download")}
|
||||
</Button>
|
||||
) : (
|
||||
<RequestAccessDialog
|
||||
trustCenterFileId={file.id}
|
||||
onSuccess={() => setHasRequested(true)}
|
||||
>
|
||||
<Button
|
||||
disabled={hasRequested}
|
||||
className="w-full md:w-max"
|
||||
variant="secondary"
|
||||
icon={IconLock}
|
||||
>
|
||||
{hasRequested ? __("Access requested") : __("Request access")}
|
||||
</Button>
|
||||
</RequestAccessDialog>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
108
apps/trust/src/components/__generated__/RequestAccessDialogTrustCenterFileMutation.graphql.ts
generated
Normal file
108
apps/trust/src/components/__generated__/RequestAccessDialogTrustCenterFileMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @generated SignedSource<<4c07d5c8e345a8e3015f512403927890>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type RequestTrustCenterFileAccessInput = {
|
||||
email?: string | null | undefined;
|
||||
name?: string | null | undefined;
|
||||
trustCenterFileId: string;
|
||||
trustCenterId: string;
|
||||
};
|
||||
export type RequestAccessDialogTrustCenterFileMutation$variables = {
|
||||
input: RequestTrustCenterFileAccessInput;
|
||||
};
|
||||
export type RequestAccessDialogTrustCenterFileMutation$data = {
|
||||
readonly requestTrustCenterFileAccess: {
|
||||
readonly trustCenterAccess: {
|
||||
readonly id: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
export type RequestAccessDialogTrustCenterFileMutation = {
|
||||
response: RequestAccessDialogTrustCenterFileMutation$data;
|
||||
variables: RequestAccessDialogTrustCenterFileMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "RequestAccessesPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "requestTrustCenterFileAccess",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterAccess",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterAccess",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "RequestAccessDialogTrustCenterFileMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "RequestAccessDialogTrustCenterFileMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "73b3007ef1a45f6dc6d31be0c627e482",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "RequestAccessDialogTrustCenterFileMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation RequestAccessDialogTrustCenterFileMutation(\n $input: RequestTrustCenterFileAccessInput!\n) {\n requestTrustCenterFileAccess(input: $input) {\n trustCenterAccess {\n id\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "a97eb6c4ec94c79a293d1cc51bf18e66";
|
||||
|
||||
export default node;
|
||||
92
apps/trust/src/components/__generated__/TrustCenterFileRowDownloadMutation.graphql.ts
generated
Normal file
92
apps/trust/src/components/__generated__/TrustCenterFileRowDownloadMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @generated SignedSource<<8d608da0bcff489887f71f6e69f1bfe3>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type ExportTrustCenterFileInput = {
|
||||
trustCenterFileId: string;
|
||||
};
|
||||
export type TrustCenterFileRowDownloadMutation$variables = {
|
||||
input: ExportTrustCenterFileInput;
|
||||
};
|
||||
export type TrustCenterFileRowDownloadMutation$data = {
|
||||
readonly exportTrustCenterFile: {
|
||||
readonly data: string;
|
||||
};
|
||||
};
|
||||
export type TrustCenterFileRowDownloadMutation = {
|
||||
response: TrustCenterFileRowDownloadMutation$data;
|
||||
variables: TrustCenterFileRowDownloadMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "ExportTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "exportTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "data",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileRowDownloadMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "TrustCenterFileRowDownloadMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "8a97b9e7ac44deea6da6e79f1d0c662f",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterFileRowDownloadMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterFileRowDownloadMutation(\n $input: ExportTrustCenterFileInput!\n) {\n exportTrustCenterFile(input: $input) {\n data\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "e6d74e96e929cf1aa79711b8315a8b85";
|
||||
|
||||
export default node;
|
||||
66
apps/trust/src/components/__generated__/TrustCenterFileRowFragment.graphql.ts
generated
Normal file
66
apps/trust/src/components/__generated__/TrustCenterFileRowFragment.graphql.ts
generated
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @generated SignedSource<<0261adc72d21035b906b6156ea9d0b40>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ReaderFragment } from 'relay-runtime';
|
||||
import { FragmentRefs } from "relay-runtime";
|
||||
export type TrustCenterFileRowFragment$data = {
|
||||
readonly hasUserRequestedAccess: boolean;
|
||||
readonly id: string;
|
||||
readonly isUserAuthorized: boolean;
|
||||
readonly name: string;
|
||||
readonly " $fragmentType": "TrustCenterFileRowFragment";
|
||||
};
|
||||
export type TrustCenterFileRowFragment$key = {
|
||||
readonly " $data"?: TrustCenterFileRowFragment$data;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFileRowFragment">;
|
||||
};
|
||||
|
||||
const node: ReaderFragment = {
|
||||
"argumentDefinitions": [],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileRowFragment",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasUserRequestedAccess",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "TrustCenterFile",
|
||||
"abstractKey": null
|
||||
};
|
||||
|
||||
(node as any).hash = "4ff11c14e65566f0dfe3a77ea73903e8";
|
||||
|
||||
export default node;
|
||||
@@ -6,6 +6,7 @@ import { documentTypeLabel } from "/helpers/documents";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Fragment } from "react";
|
||||
import { DocumentRow } from "/components/DocumentRow";
|
||||
import { TrustCenterFileRow } from "/components/TrustCenterFileRow";
|
||||
import { Rows } from "/components/Rows.tsx";
|
||||
import { RowHeader } from "/components/RowHeader.tsx";
|
||||
|
||||
@@ -21,9 +22,12 @@ export function DocumentsPage({ queryRef }: Props) {
|
||||
);
|
||||
const documents =
|
||||
data.currentTrustCenter?.documents.edges.map((edge) => edge.node) ?? [];
|
||||
const files =
|
||||
data.currentTrustCenter?.trustCenterFiles.edges.map((edge) => edge.node) ?? [];
|
||||
const documentsPerType = groupBy(documents, (document) =>
|
||||
documentTypeLabel(document.documentType, __)
|
||||
);
|
||||
const filesPerCategory = groupBy(files, (file) => file.category);
|
||||
return (
|
||||
<div>
|
||||
<h2 className="font-medium mb-1">{__("Documents")}</h2>
|
||||
@@ -39,6 +43,14 @@ export function DocumentsPage({ queryRef }: Props) {
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
{objectEntries(filesPerCategory).map(([category, files]) => (
|
||||
<Fragment key={category}>
|
||||
<RowHeader>{category}</RowHeader>
|
||||
{files.map((file) => (
|
||||
<TrustCenterFileRow key={file.id} file={file} />
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
</Rows>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ import { AuditRow } from "/components/AuditRow";
|
||||
import { documentTypeLabel } from "/helpers/documents";
|
||||
import { Fragment } from "react";
|
||||
import { DocumentRow } from "/components/DocumentRow";
|
||||
import { TrustCenterFileRow } from "/components/TrustCenterFileRow";
|
||||
import { VendorRow } from "/components/VendorRow";
|
||||
import { RowHeader } from "/components/RowHeader.tsx";
|
||||
import { Rows } from "/components/Rows.tsx";
|
||||
@@ -52,6 +53,15 @@ const overviewFragment = graphql`
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFiles(first: 5) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
category
|
||||
...TrustCenterFileRowFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -69,6 +79,7 @@ export function OverviewPage() {
|
||||
<Documents
|
||||
audits={trustCenter.audits.edges}
|
||||
documents={fragment.documents.edges}
|
||||
files={fragment.trustCenterFiles.edges}
|
||||
url={getTrustCenterUrl("documents")}
|
||||
/>
|
||||
<Subprocessors
|
||||
@@ -82,10 +93,12 @@ export function OverviewPage() {
|
||||
|
||||
function Documents({
|
||||
documents,
|
||||
files,
|
||||
audits,
|
||||
url,
|
||||
}: {
|
||||
documents: OverviewPageFragment$data["documents"]["edges"];
|
||||
files: OverviewPageFragment$data["trustCenterFiles"]["edges"];
|
||||
audits: NonNullable<
|
||||
TrustGraphQuery$data["trustCenterBySlug"]
|
||||
>["audits"]["edges"];
|
||||
@@ -96,8 +109,12 @@ function Documents({
|
||||
documents.map((edge) => edge.node),
|
||||
(node) => documentTypeLabel(node.documentType, __)
|
||||
);
|
||||
const filesPerCategory = groupBy(
|
||||
files.map((edge) => edge.node),
|
||||
(node) => node.category
|
||||
);
|
||||
const hasAudits = audits.length > 0;
|
||||
const hasDocuments = hasAudits || documents.length > 0;
|
||||
const hasDocuments = hasAudits || documents.length > 0 || files.length > 0;
|
||||
|
||||
if (!hasDocuments) {
|
||||
return null;
|
||||
@@ -126,6 +143,14 @@ function Documents({
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
{objectEntries(filesPerCategory).map(([category, files]) => (
|
||||
<Fragment key={category}>
|
||||
<RowHeader>{category}</RowHeader>
|
||||
{files.map((file) => (
|
||||
<TrustCenterFileRow key={file.id} file={file} />
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
<Link to={url} className="text-sm font-medium flex gap-2 items-center">
|
||||
{__("See all documents")}
|
||||
<IconChevronRight size={16} />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<7b1972657d83c7bb17b997e287f575d8>>
|
||||
* @generated SignedSource<<cde79d7c929ba1be8e0d033c90e7eeb7>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -32,6 +32,15 @@ export type OverviewPageFragment$data = {
|
||||
};
|
||||
}>;
|
||||
};
|
||||
readonly trustCenterFiles: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFileRowFragment">;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
readonly vendors: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
@@ -55,7 +64,14 @@ var v0 = {
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
};
|
||||
},
|
||||
v1 = [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 5
|
||||
}
|
||||
];
|
||||
return {
|
||||
"argumentDefinitions": [],
|
||||
"kind": "Fragment",
|
||||
@@ -177,13 +193,7 @@ return {
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 5
|
||||
}
|
||||
],
|
||||
"args": (v1/*: any*/),
|
||||
"concreteType": "DocumentConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "documents",
|
||||
@@ -226,6 +236,52 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": "documents(first:5)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v1/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"args": null,
|
||||
"kind": "FragmentSpread",
|
||||
"name": "TrustCenterFileRowFragment"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:5)"
|
||||
}
|
||||
],
|
||||
"type": "TrustCenter",
|
||||
@@ -233,6 +289,6 @@ return {
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "0bda7993ef3be4cfe86083658fc77813";
|
||||
(node as any).hash = "0f4e9ac02d068ba971bb1f5be5fdaccf";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -46,6 +46,15 @@ export const trustDocumentsQuery = graphql`
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFiles(first: 50) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
category
|
||||
...TrustCenterFileRowFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -117,6 +126,15 @@ export const currentTrustDocumentsQuery = graphql`
|
||||
}
|
||||
}
|
||||
}
|
||||
trustCenterFiles(first: 50) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
category
|
||||
...TrustCenterFileRowFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<091d468e321f2cd6cdead063c35c6a45>>
|
||||
* @generated SignedSource<<dabe16493c003a98ed8fd555efc85ddc>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -27,6 +27,15 @@ export type TrustGraphCurrentDocumentsQuery$data = {
|
||||
readonly organization: {
|
||||
readonly name: string;
|
||||
};
|
||||
readonly trustCenterFiles: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFileRowFragment">;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
} | null | undefined;
|
||||
};
|
||||
export type TrustGraphCurrentDocumentsQuery = {
|
||||
@@ -62,6 +71,27 @@ v3 = {
|
||||
"kind": "ScalarField",
|
||||
"name": "documentType",
|
||||
"storageKey": null
|
||||
},
|
||||
v4 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
v5 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
v6 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasUserRequestedAccess",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
@@ -130,6 +160,46 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": "documents(first:50)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
(v4/*: any*/),
|
||||
{
|
||||
"args": null,
|
||||
"kind": "FragmentSpread",
|
||||
"name": "TrustCenterFileRowFragment"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:50)"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -199,20 +269,8 @@ return {
|
||||
"name": "title",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasUserRequestedAccess",
|
||||
"storageKey": null
|
||||
}
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -221,6 +279,44 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": "documents(first:50)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v2/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
(v4/*: any*/),
|
||||
(v1/*: any*/),
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:50)"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -228,16 +324,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "9e99faf40ba87ee06df5ddd64431586e",
|
||||
"cacheID": "c9c4cb18da98c40646fbbe21c2c5b46f",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustGraphCurrentDocumentsQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustGraphCurrentDocumentsQuery {\n currentTrustCenter {\n id\n organization {\n name\n id\n }\n documents(first: 50) {\n edges {\n node {\n id\n documentType\n ...DocumentRowFragment\n }\n }\n }\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n"
|
||||
"text": "query TrustGraphCurrentDocumentsQuery {\n currentTrustCenter {\n id\n organization {\n name\n id\n }\n documents(first: 50) {\n edges {\n node {\n id\n documentType\n ...DocumentRowFragment\n }\n }\n }\n trustCenterFiles(first: 50) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "73636da5c06a16813a57b92f30ab93d2";
|
||||
(node as any).hash = "0900835ad8e59a40a2907fb787b936ef";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<fe440b5c7a8a8ed54723161632320857>>
|
||||
* @generated SignedSource<<fe9ca4e5a2ddb60ea7a7f353d431d18c>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -136,13 +136,27 @@ v12 = [
|
||||
}
|
||||
],
|
||||
v13 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
v14 = [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 5
|
||||
}
|
||||
],
|
||||
v15 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
v14 = {
|
||||
v16 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
@@ -358,13 +372,7 @@ return {
|
||||
"storageKey": null
|
||||
},
|
||||
(v6/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
(v13/*: any*/),
|
||||
(v8/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
@@ -384,13 +392,7 @@ return {
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 5
|
||||
}
|
||||
],
|
||||
"args": (v14/*: any*/),
|
||||
"concreteType": "DocumentConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "documents",
|
||||
@@ -420,8 +422,8 @@ return {
|
||||
"name": "title",
|
||||
"storageKey": null
|
||||
},
|
||||
(v13/*: any*/),
|
||||
(v14/*: any*/),
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
@@ -438,6 +440,44 @@ return {
|
||||
],
|
||||
"storageKey": "documents(first:5)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v14/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
(v13/*: any*/),
|
||||
(v6/*: any*/),
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:5)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v12/*: any*/),
|
||||
@@ -479,8 +519,8 @@ return {
|
||||
"name": "filename",
|
||||
"storageKey": null
|
||||
},
|
||||
(v13/*: any*/),
|
||||
(v14/*: any*/)
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
@@ -512,12 +552,12 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "d2c9b2a457cd3840f4b23d71cd399c84",
|
||||
"cacheID": "da8080ccbc08adb03fbf360f1e472f84",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustGraphCurrentQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustGraphCurrentQuery {\n currentTrustCenter {\n id\n slug\n isUserAuthenticated\n hasAcceptedNonDisclosureAgreement\n ndaFileName\n ndaFileUrl\n organization {\n name\n description\n websiteUrl\n logoUrl\n email\n headquarterAddress\n id\n }\n ...OverviewPageFragment\n audits(first: 50) {\n edges {\n node {\n id\n ...AuditRowFragment\n }\n }\n }\n }\n}\n\nfragment AuditRowFragment on Audit {\n report {\n id\n filename\n isUserAuthorized\n hasUserRequestedAccess\n }\n framework {\n id\n name\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment OverviewPageFragment on TrustCenter {\n references(first: 14) {\n edges {\n node {\n id\n name\n logoUrl\n websiteUrl\n }\n }\n }\n vendors(first: 3) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n documents(first: 5) {\n edges {\n node {\n id\n ...DocumentRowFragment\n documentType\n }\n }\n }\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
|
||||
"text": "query TrustGraphCurrentQuery {\n currentTrustCenter {\n id\n slug\n isUserAuthenticated\n hasAcceptedNonDisclosureAgreement\n ndaFileName\n ndaFileUrl\n organization {\n name\n description\n websiteUrl\n logoUrl\n email\n headquarterAddress\n id\n }\n ...OverviewPageFragment\n audits(first: 50) {\n edges {\n node {\n id\n ...AuditRowFragment\n }\n }\n }\n }\n}\n\nfragment AuditRowFragment on Audit {\n report {\n id\n filename\n isUserAuthorized\n hasUserRequestedAccess\n }\n framework {\n id\n name\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment OverviewPageFragment on TrustCenter {\n references(first: 14) {\n edges {\n node {\n id\n name\n logoUrl\n websiteUrl\n }\n }\n }\n vendors(first: 3) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n documents(first: 5) {\n edges {\n node {\n id\n ...DocumentRowFragment\n documentType\n }\n }\n }\n trustCenterFiles(first: 5) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<922757406dbc7a2c20b502ef6dd4c0d8>>
|
||||
* @generated SignedSource<<0faaebe3baf4c750825599985210137d>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -29,6 +29,15 @@ export type TrustGraphDocumentsQuery$data = {
|
||||
readonly organization: {
|
||||
readonly name: string;
|
||||
};
|
||||
readonly trustCenterFiles: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly category: string;
|
||||
readonly id: string;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFileRowFragment">;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
} | null | undefined;
|
||||
};
|
||||
export type TrustGraphDocumentsQuery = {
|
||||
@@ -78,6 +87,27 @@ v5 = {
|
||||
"kind": "ScalarField",
|
||||
"name": "documentType",
|
||||
"storageKey": null
|
||||
},
|
||||
v6 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
v7 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
v8 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasUserRequestedAccess",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
@@ -146,6 +176,46 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": "documents(first:50)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v4/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v6/*: any*/),
|
||||
{
|
||||
"args": null,
|
||||
"kind": "FragmentSpread",
|
||||
"name": "TrustCenterFileRowFragment"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:50)"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -215,20 +285,8 @@ return {
|
||||
"name": "title",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasUserRequestedAccess",
|
||||
"storageKey": null
|
||||
}
|
||||
(v7/*: any*/),
|
||||
(v8/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -237,6 +295,44 @@ return {
|
||||
}
|
||||
],
|
||||
"storageKey": "documents(first:50)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v4/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v6/*: any*/),
|
||||
(v3/*: any*/),
|
||||
(v7/*: any*/),
|
||||
(v8/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:50)"
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
@@ -244,16 +340,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "8a333723782b24714393e89240704cf2",
|
||||
"cacheID": "151fc8b1cf3becb2a69d87ce978fb71b",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustGraphDocumentsQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustGraphDocumentsQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n organization {\n name\n id\n }\n documents(first: 50) {\n edges {\n node {\n id\n documentType\n ...DocumentRowFragment\n }\n }\n }\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n"
|
||||
"text": "query TrustGraphDocumentsQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n organization {\n name\n id\n }\n documents(first: 50) {\n edges {\n node {\n id\n documentType\n ...DocumentRowFragment\n }\n }\n }\n trustCenterFiles(first: 50) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "9c56f70fca2afb316f4fd38d646ec545";
|
||||
(node as any).hash = "79e21d586ec18a0977c37df27aa9bdea";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<e1f3b93147b9e72d9cfc41e8e0befd6e>>
|
||||
* @generated SignedSource<<8b9ec6ee6f688ae6f6d1463104c72df4>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -152,13 +152,27 @@ v14 = [
|
||||
}
|
||||
],
|
||||
v15 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
v16 = [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 5
|
||||
}
|
||||
],
|
||||
v17 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
v16 = {
|
||||
v18 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
@@ -374,13 +388,7 @@ return {
|
||||
"storageKey": null
|
||||
},
|
||||
(v8/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "category",
|
||||
"storageKey": null
|
||||
},
|
||||
(v15/*: any*/),
|
||||
(v10/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
@@ -400,13 +408,7 @@ return {
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Literal",
|
||||
"name": "first",
|
||||
"value": 5
|
||||
}
|
||||
],
|
||||
"args": (v16/*: any*/),
|
||||
"concreteType": "DocumentConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "documents",
|
||||
@@ -436,8 +438,8 @@ return {
|
||||
"name": "title",
|
||||
"storageKey": null
|
||||
},
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/),
|
||||
(v17/*: any*/),
|
||||
(v18/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
@@ -454,6 +456,44 @@ return {
|
||||
],
|
||||
"storageKey": "documents(first:5)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v16/*: any*/),
|
||||
"concreteType": "TrustCenterFileConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterFiles",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFileEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterFile",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v15/*: any*/),
|
||||
(v8/*: any*/),
|
||||
(v17/*: any*/),
|
||||
(v18/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": "trustCenterFiles(first:5)"
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v14/*: any*/),
|
||||
@@ -495,8 +535,8 @@ return {
|
||||
"name": "filename",
|
||||
"storageKey": null
|
||||
},
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/)
|
||||
(v17/*: any*/),
|
||||
(v18/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
@@ -528,12 +568,12 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "c3cb244842768ef771ea209a51a06c4a",
|
||||
"cacheID": "f3ac933cf00a798d12b1a8e1fedcaee9",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustGraphQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustGraphQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n slug\n isUserAuthenticated\n hasAcceptedNonDisclosureAgreement\n ndaFileName\n ndaFileUrl\n organization {\n name\n description\n websiteUrl\n logoUrl\n email\n headquarterAddress\n id\n }\n ...OverviewPageFragment\n audits(first: 50) {\n edges {\n node {\n id\n ...AuditRowFragment\n }\n }\n }\n }\n}\n\nfragment AuditRowFragment on Audit {\n report {\n id\n filename\n isUserAuthorized\n hasUserRequestedAccess\n }\n framework {\n id\n name\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment OverviewPageFragment on TrustCenter {\n references(first: 14) {\n edges {\n node {\n id\n name\n logoUrl\n websiteUrl\n }\n }\n }\n vendors(first: 3) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n documents(first: 5) {\n edges {\n node {\n id\n ...DocumentRowFragment\n documentType\n }\n }\n }\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
|
||||
"text": "query TrustGraphQuery(\n $slug: String!\n) {\n trustCenterBySlug(slug: $slug) {\n id\n slug\n isUserAuthenticated\n hasAcceptedNonDisclosureAgreement\n ndaFileName\n ndaFileUrl\n organization {\n name\n description\n websiteUrl\n logoUrl\n email\n headquarterAddress\n id\n }\n ...OverviewPageFragment\n audits(first: 50) {\n edges {\n node {\n id\n ...AuditRowFragment\n }\n }\n }\n }\n}\n\nfragment AuditRowFragment on Audit {\n report {\n id\n filename\n isUserAuthorized\n hasUserRequestedAccess\n }\n framework {\n id\n name\n }\n}\n\nfragment DocumentRowFragment on Document {\n id\n title\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment OverviewPageFragment on TrustCenter {\n references(first: 14) {\n edges {\n node {\n id\n name\n logoUrl\n websiteUrl\n }\n }\n }\n vendors(first: 3) {\n edges {\n node {\n id\n countries\n ...VendorRowFragment\n }\n }\n }\n documents(first: 5) {\n edges {\n node {\n id\n ...DocumentRowFragment\n documentType\n }\n }\n }\n trustCenterFiles(first: 5) {\n edges {\n node {\n id\n category\n ...TrustCenterFileRowFragment\n }\n }\n }\n}\n\nfragment TrustCenterFileRowFragment on TrustCenterFile {\n id\n name\n isUserAuthorized\n hasUserRequestedAccess\n}\n\nfragment VendorRowFragment on Vendor {\n id\n name\n category\n websiteUrl\n privacyPolicyUrl\n countries\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -62,4 +62,5 @@ const (
|
||||
InvitationEntityType
|
||||
MembershipEntityType
|
||||
SlackMessageEntityType
|
||||
TrustCenterFileEntityType
|
||||
)
|
||||
|
||||
21
pkg/coredata/migrations/20251023T000000Z.sql
Normal file
21
pkg/coredata/migrations/20251023T000000Z.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE trust_center_files (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
tenant_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
file_id TEXT NOT NULL REFERENCES files(id) ON UPDATE CASCADE ON DELETE RESTRICT,
|
||||
trust_center_visibility trust_center_visibility NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE trust_center_document_accesses ADD COLUMN trust_center_file_id TEXT REFERENCES trust_center_files(id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE trust_center_document_accesses DROP CONSTRAINT trust_center_document_accesses_check;
|
||||
|
||||
ALTER TABLE trust_center_document_accesses ADD CONSTRAINT trust_center_document_accesses_check CHECK (
|
||||
(document_id IS NOT NULL)::int + (report_id IS NOT NULL)::int + (trust_center_file_id IS NOT NULL)::int = 1
|
||||
);
|
||||
|
||||
ALTER TABLE trust_center_document_accesses ADD CONSTRAINT trust_center_document_accesses_trust_center_file_id_key UNIQUE (trust_center_access_id, trust_center_file_id);
|
||||
@@ -32,6 +32,7 @@ type (
|
||||
TrustCenterAccessID gid.GID `db:"trust_center_access_id"`
|
||||
DocumentID *gid.GID `db:"document_id"`
|
||||
ReportID *gid.GID `db:"report_id"`
|
||||
TrustCenterFileID *gid.GID `db:"trust_center_file_id"`
|
||||
Active bool `db:"active"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
@@ -61,6 +62,7 @@ SELECT
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -105,6 +107,7 @@ SELECT
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -153,6 +156,7 @@ SELECT
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -200,6 +204,7 @@ INSERT INTO trust_center_document_accesses (
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -209,6 +214,7 @@ INSERT INTO trust_center_document_accesses (
|
||||
@trust_center_access_id,
|
||||
@document_id,
|
||||
@report_id,
|
||||
@trust_center_file_id,
|
||||
@active,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@@ -221,6 +227,7 @@ INSERT INTO trust_center_document_accesses (
|
||||
"trust_center_access_id": tcda.TrustCenterAccessID,
|
||||
"document_id": tcda.DocumentID,
|
||||
"report_id": tcda.ReportID,
|
||||
"trust_center_file_id": tcda.TrustCenterFileID,
|
||||
"active": tcda.Active,
|
||||
"created_at": tcda.CreatedAt,
|
||||
"updated_at": tcda.UpdatedAt,
|
||||
@@ -338,6 +345,7 @@ SELECT
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -384,6 +392,7 @@ SELECT
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -543,12 +552,13 @@ WITH document_access_data AS (
|
||||
@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,
|
||||
false AS active,
|
||||
@created_at::timestamptz AS created_at,
|
||||
@updated_at::timestamptz AS updated_at
|
||||
)
|
||||
INSERT INTO trust_center_document_accesses (
|
||||
id, tenant_id, trust_center_access_id, document_id, report_id, active, created_at, updated_at
|
||||
id, tenant_id, trust_center_access_id, document_id, report_id, trust_center_file_id, active, created_at, updated_at
|
||||
)
|
||||
SELECT * FROM document_access_data
|
||||
`
|
||||
@@ -589,12 +599,13 @@ WITH report_access_data AS (
|
||||
@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,
|
||||
false AS active,
|
||||
@created_at::timestamptz AS created_at,
|
||||
@updated_at::timestamptz AS updated_at
|
||||
)
|
||||
INSERT INTO trust_center_document_accesses (
|
||||
id, tenant_id, trust_center_access_id, document_id, report_id, active, created_at, updated_at
|
||||
id, tenant_id, trust_center_access_id, document_id, report_id, trust_center_file_id, active, created_at, updated_at
|
||||
)
|
||||
SELECT * FROM report_access_data
|
||||
`
|
||||
@@ -614,3 +625,129 @@ SELECT * FROM report_access_data
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcda *TrustCenterDocumentAccess) LoadByTrustCenterAccessIDAndTrustCenterFileID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
trustCenterAccessID gid.GID,
|
||||
trustCenterFileID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
trust_center_access_id,
|
||||
document_id,
|
||||
report_id,
|
||||
trust_center_file_id,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
trust_center_document_accesses
|
||||
WHERE
|
||||
%s
|
||||
AND trust_center_access_id = @trust_center_access_id
|
||||
AND trust_center_file_id = @trust_center_file_id
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"trust_center_file_id": trustCenterFileID,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query trust center document access: %w", err)
|
||||
}
|
||||
|
||||
access, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TrustCenterDocumentAccess])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect trust center document access: %w", err)
|
||||
}
|
||||
|
||||
*tcda = access
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ActivateByTrustCenterFileIDs(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
trustCenterAccessID gid.GID,
|
||||
trustCenterFileIDs []gid.GID,
|
||||
updatedAt time.Time,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE trust_center_document_accesses
|
||||
SET active = true, 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)
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"trust_center_file_ids": trustCenterFileIDs,
|
||||
"updated_at": updatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot activate trust center document accesses by trust center file IDs: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tcdas TrustCenterDocumentAccesses) BulkInsertTrustCenterFileAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
trustCenterAccessID gid.GID,
|
||||
trustCenterFileIDs []gid.GID,
|
||||
createdAt time.Time,
|
||||
) 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,
|
||||
@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,
|
||||
false AS active,
|
||||
@created_at::timestamptz AS created_at,
|
||||
@updated_at::timestamptz AS updated_at
|
||||
)
|
||||
INSERT INTO trust_center_document_accesses (
|
||||
id, tenant_id, trust_center_access_id, document_id, report_id, trust_center_file_id, active, created_at, updated_at
|
||||
)
|
||||
SELECT * FROM trust_center_file_access_data
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"trust_center_document_access_entity_type": TrustCenterDocumentAccessEntityType,
|
||||
"trust_center_access_id": trustCenterAccessID,
|
||||
"trust_center_file_ids": trustCenterFileIDs,
|
||||
"created_at": createdAt,
|
||||
"updated_at": createdAt,
|
||||
}
|
||||
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center file accesses: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
347
pkg/coredata/trust_center_file.go
Normal file
347
pkg/coredata/trust_center_file.go
Normal file
@@ -0,0 +1,347 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
TrustCenterFile struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
Name string `db:"name"`
|
||||
Category string `db:"category"`
|
||||
FileID gid.GID `db:"file_id"`
|
||||
TrustCenterVisibility TrustCenterVisibility `db:"trust_center_visibility"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
TrustCenterFiles []*TrustCenterFile
|
||||
)
|
||||
|
||||
func (t TrustCenterFile) CursorKey(orderBy TrustCenterFileOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case TrustCenterFileOrderFieldName:
|
||||
return page.NewCursorKey(t.ID, t.Name)
|
||||
case TrustCenterFileOrderFieldCreatedAt:
|
||||
return page.NewCursorKey(t.ID, t.CreatedAt)
|
||||
case TrustCenterFileOrderFieldUpdatedAt:
|
||||
return page.NewCursorKey(t.ID, t.UpdatedAt)
|
||||
}
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (t *TrustCenterFile) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
trustCenterFileID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
name,
|
||||
category,
|
||||
file_id,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
trust_center_files
|
||||
WHERE
|
||||
%s
|
||||
AND id = @trust_center_file_id
|
||||
LIMIT 1;
|
||||
`
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"trust_center_file_id": trustCenterFileID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query trust_center_files: %w", err)
|
||||
}
|
||||
|
||||
file, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TrustCenterFile])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect trust center file: %w", err)
|
||||
}
|
||||
|
||||
*t = file
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t TrustCenterFile) Insert(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
INSERT INTO
|
||||
trust_center_files (
|
||||
tenant_id,
|
||||
id,
|
||||
organization_id,
|
||||
name,
|
||||
category,
|
||||
file_id,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
@tenant_id,
|
||||
@id,
|
||||
@organization_id,
|
||||
@name,
|
||||
@category,
|
||||
@file_id,
|
||||
@trust_center_visibility,
|
||||
@created_at,
|
||||
@updated_at
|
||||
);
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"tenant_id": scope.GetTenantID(),
|
||||
"id": t.ID,
|
||||
"organization_id": t.OrganizationID,
|
||||
"name": t.Name,
|
||||
"category": t.Category,
|
||||
"file_id": t.FileID,
|
||||
"trust_center_visibility": t.TrustCenterVisibility,
|
||||
"created_at": t.CreatedAt,
|
||||
"updated_at": t.UpdatedAt,
|
||||
}
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot insert trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TrustCenterFile) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE trust_center_files
|
||||
SET
|
||||
name = @name,
|
||||
category = @category,
|
||||
trust_center_visibility = @trust_center_visibility,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
RETURNING
|
||||
id,
|
||||
organization_id,
|
||||
name,
|
||||
category,
|
||||
file_id,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": t.ID,
|
||||
"name": t.Name,
|
||||
"category": t.Category,
|
||||
"trust_center_visibility": t.TrustCenterVisibility,
|
||||
"updated_at": t.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update trust center file: %w", err)
|
||||
}
|
||||
|
||||
file, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TrustCenterFile])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect updated trust center file: %w", err)
|
||||
}
|
||||
|
||||
*t = file
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TrustCenterFile) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
DELETE FROM
|
||||
trust_center_files
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"id": t.ID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot delete trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TrustCenterFiles) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[TrustCenterFileOrderField],
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
name,
|
||||
category,
|
||||
file_id,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
trust_center_files
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query trust_center_files: %w", err)
|
||||
}
|
||||
|
||||
files, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TrustCenterFile])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect trust center files: %w", err)
|
||||
}
|
||||
|
||||
*t = files
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TrustCenterFiles) CountByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
) (int, error) {
|
||||
q := `
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
trust_center_files
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
var count int
|
||||
err := conn.QueryRow(ctx, q, args).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("cannot count trust center files: %w", err)
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (t *TrustCenterFiles) LoadAllByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
organizationID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
name,
|
||||
category,
|
||||
file_id,
|
||||
trust_center_visibility,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
trust_center_files
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
ORDER BY
|
||||
created_at DESC
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot query trust center files: %w", err)
|
||||
}
|
||||
|
||||
files, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TrustCenterFile])
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot collect trust center files: %w", err)
|
||||
}
|
||||
|
||||
*t = files
|
||||
|
||||
return nil
|
||||
}
|
||||
51
pkg/coredata/trust_center_file_order_field.go
Normal file
51
pkg/coredata/trust_center_file_order_field.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
type (
|
||||
TrustCenterFileOrderField string
|
||||
)
|
||||
|
||||
const (
|
||||
TrustCenterFileOrderFieldName TrustCenterFileOrderField = "NAME"
|
||||
TrustCenterFileOrderFieldCreatedAt TrustCenterFileOrderField = "CREATED_AT"
|
||||
TrustCenterFileOrderFieldUpdatedAt TrustCenterFileOrderField = "UPDATED_AT"
|
||||
)
|
||||
|
||||
func (p TrustCenterFileOrderField) Column() string {
|
||||
switch p {
|
||||
case TrustCenterFileOrderFieldName:
|
||||
return "name"
|
||||
case TrustCenterFileOrderFieldCreatedAt:
|
||||
return "created_at"
|
||||
case TrustCenterFileOrderFieldUpdatedAt:
|
||||
return "updated_at"
|
||||
default:
|
||||
return string(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (p TrustCenterFileOrderField) String() string {
|
||||
return string(p)
|
||||
}
|
||||
|
||||
func (p TrustCenterFileOrderField) MarshalText() ([]byte, error) {
|
||||
return []byte(p.String()), nil
|
||||
}
|
||||
|
||||
func (p *TrustCenterFileOrderField) UnmarshalText(text []byte) error {
|
||||
*p = TrustCenterFileOrderField(text)
|
||||
return nil
|
||||
}
|
||||
@@ -98,6 +98,7 @@ type (
|
||||
TrustCenters *TrustCenterService
|
||||
TrustCenterAccesses *TrustCenterAccessService
|
||||
TrustCenterReferences *TrustCenterReferenceService
|
||||
TrustCenterFiles *TrustCenterFileService
|
||||
Nonconformities *NonconformityService
|
||||
Obligations *ObligationService
|
||||
Snapshots *SnapshotService
|
||||
@@ -208,6 +209,18 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
tenantService.TrustCenters = &TrustCenterService{svc: tenantService}
|
||||
tenantService.TrustCenterAccesses = &TrustCenterAccessService{svc: tenantService}
|
||||
tenantService.TrustCenterReferences = &TrustCenterReferenceService{svc: tenantService}
|
||||
tenantService.TrustCenterFiles = &TrustCenterFileService{
|
||||
svc: tenantService,
|
||||
fileValidator: &filevalidation.FileValidator{
|
||||
MaxFileSize: 10 * 1024 * 1024, // 10MB
|
||||
AllowedMimeTypes: map[string]bool{
|
||||
"application/pdf": true,
|
||||
},
|
||||
AllowedExtensions: map[string][]string{
|
||||
".pdf": {"application/pdf"},
|
||||
},
|
||||
},
|
||||
}
|
||||
tenantService.Nonconformities = &NonconformityService{svc: tenantService}
|
||||
tenantService.Obligations = &ObligationService{svc: tenantService}
|
||||
tenantService.Snapshots = &SnapshotService{svc: tenantService}
|
||||
|
||||
@@ -41,11 +41,12 @@ type (
|
||||
}
|
||||
|
||||
UpdateTrustCenterAccessRequest struct {
|
||||
ID gid.GID
|
||||
Name *string
|
||||
Active *bool
|
||||
DocumentIDs []gid.GID
|
||||
ReportIDs []gid.GID
|
||||
ID gid.GID
|
||||
Name *string
|
||||
Active *bool
|
||||
DocumentIDs []gid.GID
|
||||
ReportIDs []gid.GID
|
||||
TrustCenterFileIDs []gid.GID
|
||||
}
|
||||
|
||||
DeleteTrustCenterAccessRequest struct {
|
||||
@@ -65,9 +66,12 @@ func (s TrustCenterAccessService) ListForTrustCenterID(
|
||||
) (*page.Page[*coredata.TrustCenterAccess, coredata.TrustCenterAccessOrderField], error) {
|
||||
var accesses coredata.TrustCenterAccesses
|
||||
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
return accesses.LoadByTrustCenterID(ctx, conn, s.svc.scope, trustCenterID, cursor)
|
||||
})
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return accesses.LoadByTrustCenterID(ctx, conn, s.svc.scope, trustCenterID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -83,9 +87,12 @@ func (s TrustCenterAccessService) ListDocumentAccesses(
|
||||
) (*page.Page[*coredata.TrustCenterDocumentAccess, coredata.TrustCenterDocumentAccessOrderField], error) {
|
||||
var documentAccesses coredata.TrustCenterDocumentAccesses
|
||||
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
return documentAccesses.LoadByTrustCenterAccessID(ctx, conn, s.svc.scope, trustCenterAccessID, cursor)
|
||||
})
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return documentAccesses.LoadByTrustCenterAccessID(ctx, conn, s.svc.scope, trustCenterAccessID, cursor)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -100,9 +107,12 @@ func (s TrustCenterAccessService) Get(
|
||||
) (*coredata.TrustCenterAccess, error) {
|
||||
var access coredata.TrustCenterAccess
|
||||
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
return access.LoadByID(ctx, conn, s.svc.scope, accessID)
|
||||
})
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return access.LoadByID(ctx, conn, s.svc.scope, accessID)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -117,9 +127,12 @@ func (s TrustCenterAccessService) GetDocumentAccess(
|
||||
) (*coredata.TrustCenterDocumentAccess, error) {
|
||||
var documentAccess coredata.TrustCenterDocumentAccess
|
||||
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
return documentAccess.LoadByID(ctx, conn, s.svc.scope, documentAccessID)
|
||||
})
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return documentAccess.LoadByID(ctx, conn, s.svc.scope, documentAccessID)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -133,12 +146,15 @@ func (s TrustCenterAccessService) CountDocumentAccesses(
|
||||
trustCenterAccessID gid.GID,
|
||||
) (int, error) {
|
||||
var count int
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
var documentAccesses coredata.TrustCenterDocumentAccesses
|
||||
var err error
|
||||
count, err = documentAccesses.CountByTrustCenterAccessID(ctx, conn, s.svc.scope, trustCenterAccessID)
|
||||
return err
|
||||
})
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
var documentAccesses coredata.TrustCenterDocumentAccesses
|
||||
var err error
|
||||
count, err = documentAccesses.CountByTrustCenterAccessID(ctx, conn, s.svc.scope, trustCenterAccessID)
|
||||
return err
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -161,9 +177,12 @@ func (s TrustCenterAccessService) ValidateToken(
|
||||
}
|
||||
|
||||
access := &coredata.TrustCenterAccess{}
|
||||
err = s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
return access.LoadByTrustCenterIDAndEmail(ctx, conn, s.svc.scope, token.Data.TrustCenterID, token.Data.Email)
|
||||
})
|
||||
err = s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return access.LoadByTrustCenterIDAndEmail(ctx, conn, s.svc.scope, token.Data.TrustCenterID, token.Data.Email)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("access not found or revoked: %w", err)
|
||||
@@ -188,67 +207,85 @@ func (s TrustCenterAccessService) Create(
|
||||
|
||||
var access *coredata.TrustCenterAccess
|
||||
|
||||
err := s.svc.pg.WithTx(ctx, func(tx pg.Conn) error {
|
||||
trustCenter := &coredata.TrustCenter{}
|
||||
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, req.TrustCenterID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center: %w", err)
|
||||
}
|
||||
organizationID := trustCenter.OrganizationID
|
||||
|
||||
documentIDs := []gid.GID{}
|
||||
reportIDs := []gid.GID{}
|
||||
|
||||
var allDocuments coredata.Documents
|
||||
filter := coredata.NewDocumentTrustCenterFilter()
|
||||
|
||||
if err := allDocuments.LoadAllByOrganizationID(ctx, tx, s.svc.scope, organizationID, filter); err != nil {
|
||||
return fmt.Errorf("cannot list documents: %w", err)
|
||||
}
|
||||
|
||||
for _, doc := range allDocuments {
|
||||
documentIDs = append(documentIDs, doc.ID)
|
||||
}
|
||||
|
||||
var allAudits coredata.Audits
|
||||
auditFilter := coredata.NewAuditTrustCenterFilter()
|
||||
|
||||
if err := allAudits.LoadAllByOrganizationID(ctx, tx, s.svc.scope, organizationID, auditFilter); err != nil {
|
||||
return fmt.Errorf("cannot list audits: %w", err)
|
||||
}
|
||||
|
||||
for _, audit := range allAudits {
|
||||
if audit.ReportID != nil {
|
||||
reportIDs = append(reportIDs, *audit.ReportID)
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
trustCenter := &coredata.TrustCenter{}
|
||||
if err := trustCenter.LoadByID(ctx, tx, s.svc.scope, req.TrustCenterID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center: %w", err)
|
||||
}
|
||||
}
|
||||
organizationID := trustCenter.OrganizationID
|
||||
|
||||
access = &coredata.TrustCenterAccess{
|
||||
ID: gid.New(s.svc.scope.GetTenantID(), coredata.TrustCenterAccessEntityType),
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
TrustCenterID: req.TrustCenterID,
|
||||
Email: req.Email,
|
||||
Name: req.Name,
|
||||
Active: false,
|
||||
HasAcceptedNonDisclosureAgreement: false,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
documentIDs := []gid.GID{}
|
||||
reportIDs := []gid.GID{}
|
||||
trustCenterFileIDs := []gid.GID{}
|
||||
|
||||
if err := access.Insert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert trust center access: %w", err)
|
||||
}
|
||||
var allDocuments coredata.Documents
|
||||
filter := coredata.NewDocumentTrustCenterFilter()
|
||||
|
||||
var documentAccesses coredata.TrustCenterDocumentAccesses
|
||||
if err := documentAccesses.BulkInsertDocumentAccesses(ctx, tx, s.svc.scope, access.ID, documentIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center document accesses: %w", err)
|
||||
}
|
||||
if err := allDocuments.LoadAllByOrganizationID(ctx, tx, s.svc.scope, organizationID, filter); err != nil {
|
||||
return fmt.Errorf("cannot list documents: %w", err)
|
||||
}
|
||||
|
||||
if err := documentAccesses.BulkInsertReportAccesses(ctx, tx, s.svc.scope, access.ID, reportIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center report accesses: %w", err)
|
||||
}
|
||||
for _, doc := range allDocuments {
|
||||
documentIDs = append(documentIDs, doc.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
var allAudits coredata.Audits
|
||||
auditFilter := coredata.NewAuditTrustCenterFilter()
|
||||
|
||||
if err := allAudits.LoadAllByOrganizationID(ctx, tx, s.svc.scope, organizationID, auditFilter); err != nil {
|
||||
return fmt.Errorf("cannot list audits: %w", err)
|
||||
}
|
||||
|
||||
for _, audit := range allAudits {
|
||||
if audit.ReportID != nil {
|
||||
reportIDs = append(reportIDs, *audit.ReportID)
|
||||
}
|
||||
}
|
||||
|
||||
var allTrustCenterFiles coredata.TrustCenterFiles
|
||||
|
||||
if err := allTrustCenterFiles.LoadAllByOrganizationID(ctx, tx, s.svc.scope, organizationID); err != nil {
|
||||
return fmt.Errorf("cannot list trust center files: %w", err)
|
||||
}
|
||||
|
||||
for _, file := range allTrustCenterFiles {
|
||||
trustCenterFileIDs = append(trustCenterFileIDs, file.ID)
|
||||
}
|
||||
|
||||
access = &coredata.TrustCenterAccess{
|
||||
ID: gid.New(s.svc.scope.GetTenantID(), coredata.TrustCenterAccessEntityType),
|
||||
TenantID: s.svc.scope.GetTenantID(),
|
||||
TrustCenterID: req.TrustCenterID,
|
||||
Email: req.Email,
|
||||
Name: req.Name,
|
||||
Active: false,
|
||||
HasAcceptedNonDisclosureAgreement: false,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := access.Insert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert trust center access: %w", err)
|
||||
}
|
||||
|
||||
var documentAccesses coredata.TrustCenterDocumentAccesses
|
||||
if err := documentAccesses.BulkInsertDocumentAccesses(ctx, tx, s.svc.scope, access.ID, documentIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center document accesses: %w", err)
|
||||
}
|
||||
|
||||
if err := documentAccesses.BulkInsertReportAccesses(ctx, tx, s.svc.scope, access.ID, reportIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center report accesses: %w", err)
|
||||
}
|
||||
|
||||
if err := documentAccesses.BulkInsertTrustCenterFileAccesses(ctx, tx, s.svc.scope, access.ID, trustCenterFileIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center file accesses: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -269,52 +306,61 @@ func (s TrustCenterAccessService) Update(
|
||||
return nil, fmt.Errorf("name is required")
|
||||
}
|
||||
|
||||
err := s.svc.pg.WithTx(ctx, func(tx pg.Conn) error {
|
||||
access = &coredata.TrustCenterAccess{}
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
access = &coredata.TrustCenterAccess{}
|
||||
|
||||
if err := access.LoadByID(ctx, tx, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center access: %w", err)
|
||||
}
|
||||
|
||||
shouldSendEmail := req.Active != nil && *req.Active && !access.Active
|
||||
if req.Name != nil {
|
||||
access.Name = *req.Name
|
||||
}
|
||||
if req.Active != nil {
|
||||
access.Active = *req.Active
|
||||
}
|
||||
access.UpdatedAt = now
|
||||
|
||||
if err := access.Update(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update trust center access: %w", err)
|
||||
}
|
||||
|
||||
if req.DocumentIDs != nil || req.ReportIDs != nil {
|
||||
if err := coredata.DeactivateByTrustCenterAccessID(ctx, tx, s.svc.scope, access.ID, now); err != nil {
|
||||
return fmt.Errorf("cannot deactivate existing document accesses: %w", err)
|
||||
if err := access.LoadByID(ctx, tx, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center access: %w", err)
|
||||
}
|
||||
|
||||
if req.DocumentIDs != nil {
|
||||
if err := coredata.ActivateByDocumentIDs(ctx, tx, s.svc.scope, access.ID, req.DocumentIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot activate document accesses: %w", err)
|
||||
shouldSendEmail := req.Active != nil && *req.Active && !access.Active
|
||||
if req.Name != nil {
|
||||
access.Name = *req.Name
|
||||
}
|
||||
if req.Active != nil {
|
||||
access.Active = *req.Active
|
||||
}
|
||||
access.UpdatedAt = now
|
||||
|
||||
if err := access.Update(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update trust center access: %w", err)
|
||||
}
|
||||
|
||||
if req.DocumentIDs != nil || req.ReportIDs != nil || req.TrustCenterFileIDs != nil {
|
||||
if err := coredata.DeactivateByTrustCenterAccessID(ctx, tx, s.svc.scope, access.ID, now); err != nil {
|
||||
return fmt.Errorf("cannot deactivate existing document accesses: %w", err)
|
||||
}
|
||||
|
||||
if req.DocumentIDs != nil {
|
||||
if err := coredata.ActivateByDocumentIDs(ctx, tx, s.svc.scope, access.ID, req.DocumentIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot activate document accesses: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if req.ReportIDs != nil {
|
||||
if err := coredata.ActivateByReportIDs(ctx, tx, s.svc.scope, access.ID, req.ReportIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot activate report accesses: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if req.TrustCenterFileIDs != nil {
|
||||
if err := coredata.ActivateByTrustCenterFileIDs(ctx, tx, s.svc.scope, access.ID, req.TrustCenterFileIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot activate trust center file accesses: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if req.ReportIDs != nil {
|
||||
if err := coredata.ActivateByReportIDs(ctx, tx, s.svc.scope, access.ID, req.ReportIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot activate report accesses: %w", err)
|
||||
if shouldSendEmail {
|
||||
if err := s.sendAccessEmail(ctx, tx, access); err != nil {
|
||||
return fmt.Errorf("failed to send access email: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if shouldSendEmail {
|
||||
if err := s.sendAccessEmail(ctx, tx, access); err != nil {
|
||||
return fmt.Errorf("failed to send access email: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -327,19 +373,22 @@ func (s TrustCenterAccessService) Delete(
|
||||
ctx context.Context,
|
||||
req *DeleteTrustCenterAccessRequest,
|
||||
) error {
|
||||
err := s.svc.pg.WithTx(ctx, func(tx pg.Conn) error {
|
||||
access := &coredata.TrustCenterAccess{}
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
access := &coredata.TrustCenterAccess{}
|
||||
|
||||
if err := access.LoadByID(ctx, tx, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center access: %w", err)
|
||||
}
|
||||
if err := access.LoadByID(ctx, tx, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center access: %w", err)
|
||||
}
|
||||
|
||||
if err := access.Delete(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete trust center access: %w", err)
|
||||
}
|
||||
if err := access.Delete(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete trust center access: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
405
pkg/probo/trust_center_file_service.go
Normal file
405
pkg/probo/trust_center_file_service.go
Normal file
@@ -0,0 +1,405 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package probo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/filevalidation"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"go.gearno.de/crypto/uuid"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
TrustCenterFileService struct {
|
||||
svc *TenantService
|
||||
fileValidator *filevalidation.FileValidator
|
||||
}
|
||||
|
||||
CreateTrustCenterFileRequest struct {
|
||||
OrganizationID gid.GID
|
||||
Name string
|
||||
Category string
|
||||
File File
|
||||
TrustCenterVisibility coredata.TrustCenterVisibility
|
||||
}
|
||||
|
||||
UpdateTrustCenterFileRequest struct {
|
||||
ID gid.GID
|
||||
Name *string
|
||||
Category *string
|
||||
TrustCenterVisibility *coredata.TrustCenterVisibility
|
||||
}
|
||||
|
||||
GetTrustCenterFileRequest struct {
|
||||
ID gid.GID
|
||||
}
|
||||
|
||||
DeleteTrustCenterFileRequest struct {
|
||||
ID gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
func (s TrustCenterFileService) ListForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.TrustCenterFileOrderField],
|
||||
) (*page.Page[*coredata.TrustCenterFile, coredata.TrustCenterFileOrderField], error) {
|
||||
var files coredata.TrustCenterFiles
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
if err := files.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor); err != nil {
|
||||
return fmt.Errorf("cannot load trust center files: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(files, cursor), nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) CountForOrganizationID(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
) (int, error) {
|
||||
var count int
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
var err error
|
||||
count, err = (&coredata.TrustCenterFiles{}).CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot count trust center files: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) Get(
|
||||
ctx context.Context,
|
||||
req *GetTrustCenterFileRequest,
|
||||
) (*coredata.TrustCenterFile, error) {
|
||||
var file *coredata.TrustCenterFile
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
file = &coredata.TrustCenterFile{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) Create(
|
||||
ctx context.Context,
|
||||
req *CreateTrustCenterFileRequest,
|
||||
) (*coredata.TrustCenterFile, error) {
|
||||
if req.Name == "" {
|
||||
return nil, fmt.Errorf("name is required")
|
||||
}
|
||||
|
||||
// Validate file
|
||||
filename := req.File.Filename
|
||||
contentType := req.File.ContentType
|
||||
fileSize, err := s.svc.fileManager.GetFileSize(req.File.Content)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get file size: %w", err)
|
||||
}
|
||||
|
||||
if err := s.fileValidator.Validate(filename, contentType, fileSize); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
trustCenterFileID := gid.New(s.svc.scope.GetTenantID(), coredata.TrustCenterFileEntityType)
|
||||
|
||||
var file *coredata.TrustCenterFile
|
||||
var s3Key string
|
||||
|
||||
err = s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
fileID, objectKey, err := s.uploadFile(ctx, tx, req.File, trustCenterFileID, req.OrganizationID, now)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot upload file: %w", err)
|
||||
}
|
||||
s3Key = objectKey
|
||||
|
||||
file = &coredata.TrustCenterFile{
|
||||
ID: trustCenterFileID,
|
||||
OrganizationID: req.OrganizationID,
|
||||
Name: req.Name,
|
||||
Category: req.Category,
|
||||
FileID: fileID,
|
||||
TrustCenterVisibility: req.TrustCenterVisibility,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := file.Insert(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot insert trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
s.cleanupS3Object(ctx, s3Key)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) Update(
|
||||
ctx context.Context,
|
||||
req *UpdateTrustCenterFileRequest,
|
||||
) (*coredata.TrustCenterFile, error) {
|
||||
now := time.Now()
|
||||
|
||||
var file *coredata.TrustCenterFile
|
||||
|
||||
if req.Name != nil && *req.Name == "" {
|
||||
return nil, fmt.Errorf("name is required")
|
||||
}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
file = &coredata.TrustCenterFile{}
|
||||
|
||||
if err := file.LoadByID(ctx, tx, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
if req.Name != nil {
|
||||
file.Name = *req.Name
|
||||
}
|
||||
if req.Category != nil {
|
||||
file.Category = *req.Category
|
||||
}
|
||||
if req.TrustCenterVisibility != nil {
|
||||
file.TrustCenterVisibility = *req.TrustCenterVisibility
|
||||
}
|
||||
file.UpdatedAt = now
|
||||
|
||||
if err := file.Update(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) Delete(
|
||||
ctx context.Context,
|
||||
req *DeleteTrustCenterFileRequest,
|
||||
) error {
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
file := &coredata.TrustCenterFile{}
|
||||
|
||||
if err := file.LoadByID(ctx, tx, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
if err := file.Delete(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) GenerateFileURL(
|
||||
ctx context.Context,
|
||||
trustCenterFileID gid.GID,
|
||||
duration time.Duration,
|
||||
) (string, error) {
|
||||
var storedFile *coredata.File
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
file := &coredata.TrustCenterFile{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, trustCenterFileID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
storedFile = &coredata.File{}
|
||||
if err := storedFile.LoadByID(ctx, conn, s.svc.scope, file.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
fileURL, err := s.svc.fileManager.GenerateFileUrl(ctx, storedFile, duration)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot generate file URL: %w", err)
|
||||
}
|
||||
|
||||
return fileURL, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) uploadFile(
|
||||
ctx context.Context,
|
||||
tx pg.Conn,
|
||||
file File,
|
||||
trustCenterFileID gid.GID,
|
||||
organizationID gid.GID,
|
||||
now time.Time,
|
||||
) (gid.GID, string, error) {
|
||||
fileID := gid.New(s.svc.scope.GetTenantID(), coredata.FileEntityType)
|
||||
|
||||
objectKey, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
return gid.GID{}, "", fmt.Errorf("cannot generate object key: %w", err)
|
||||
}
|
||||
|
||||
var fileSize int64
|
||||
var fileContent io.ReadSeeker
|
||||
filename := file.Filename
|
||||
contentType := file.ContentType
|
||||
|
||||
if readSeeker, ok := file.Content.(io.ReadSeeker); ok {
|
||||
if file.Size <= 0 {
|
||||
size, err := readSeeker.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
return gid.GID{}, "", fmt.Errorf("cannot determine file size: %w", err)
|
||||
}
|
||||
fileSize = size
|
||||
|
||||
_, err = readSeeker.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
return gid.GID{}, "", fmt.Errorf("cannot reset file position: %w", err)
|
||||
}
|
||||
} else {
|
||||
fileSize = file.Size
|
||||
}
|
||||
fileContent = readSeeker
|
||||
} else {
|
||||
buf, err := io.ReadAll(file.Content)
|
||||
if err != nil {
|
||||
return gid.GID{}, "", fmt.Errorf("cannot read file: %w", err)
|
||||
}
|
||||
fileSize = int64(len(buf))
|
||||
fileContent = bytes.NewReader(buf)
|
||||
}
|
||||
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
if filename != "" {
|
||||
if detectedType := mime.TypeByExtension(filepath.Ext(filename)); detectedType != "" {
|
||||
contentType = detectedType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, err = s.svc.s3.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(objectKey.String()),
|
||||
Body: fileContent,
|
||||
ContentType: aws.String(contentType),
|
||||
Metadata: map[string]string{
|
||||
"type": "trust-center-file",
|
||||
"trust-center-file-id": trustCenterFileID.String(),
|
||||
"organization-id": organizationID.String(),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return gid.GID{}, "", fmt.Errorf("cannot upload file to S3: %w", err)
|
||||
}
|
||||
|
||||
fileRecord := &coredata.File{
|
||||
ID: fileID,
|
||||
BucketName: s.svc.bucket,
|
||||
MimeType: contentType,
|
||||
FileName: filename,
|
||||
FileKey: objectKey.String(),
|
||||
FileSize: fileSize,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := fileRecord.Insert(ctx, tx, s.svc.scope); err != nil {
|
||||
return gid.GID{}, "", fmt.Errorf("cannot insert file: %w", err)
|
||||
}
|
||||
|
||||
return fileID, objectKey.String(), nil
|
||||
}
|
||||
|
||||
func (s TrustCenterFileService) cleanupS3Object(ctx context.Context, s3Key string) {
|
||||
if s3Key == "" {
|
||||
return
|
||||
}
|
||||
|
||||
s.svc.s3.DeleteObject(ctx, &s3.DeleteObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(s3Key),
|
||||
})
|
||||
}
|
||||
@@ -1187,6 +1187,24 @@ enum TrustCenterReferenceOrderField
|
||||
)
|
||||
}
|
||||
|
||||
enum TrustCenterFileOrderField
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderField"
|
||||
) {
|
||||
NAME
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderFieldName"
|
||||
)
|
||||
CREATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderFieldCreatedAt"
|
||||
)
|
||||
UPDATED_AT
|
||||
@goEnum(
|
||||
value: "github.com/getprobo/probo/pkg/coredata.TrustCenterFileOrderFieldUpdatedAt"
|
||||
)
|
||||
}
|
||||
|
||||
enum SnapshotsType
|
||||
@goModel(model: "github.com/getprobo/probo/pkg/coredata.SnapshotsType") {
|
||||
RISKS
|
||||
@@ -1422,6 +1440,14 @@ input TrustCenterReferenceOrder
|
||||
field: TrustCenterReferenceOrderField!
|
||||
}
|
||||
|
||||
input TrustCenterFileOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterFileOrderBy"
|
||||
) {
|
||||
direction: OrderDirection!
|
||||
field: TrustCenterFileOrderField!
|
||||
}
|
||||
|
||||
input EvidenceOrder
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.EvidenceOrderBy"
|
||||
@@ -1749,6 +1775,14 @@ type Organization implements Node {
|
||||
orderBy: SnapshotOrder
|
||||
): SnapshotConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenterFiles(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
orderBy: TrustCenterFileOrder
|
||||
): TrustCenterFileConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenter: TrustCenter @goField(forceResolver: true)
|
||||
|
||||
customDomain: CustomDomain @goField(forceResolver: true)
|
||||
@@ -2391,6 +2425,7 @@ type TrustCenterDocumentAccess implements Node {
|
||||
trustCenterAccess: TrustCenterAccess! @goField(forceResolver: true)
|
||||
document: Document @goField(forceResolver: true)
|
||||
report: Report @goField(forceResolver: true)
|
||||
trustCenterFile: TrustCenterFile @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterDocumentAccessConnection
|
||||
@@ -2441,6 +2476,31 @@ type TrustCenterReferenceEdge {
|
||||
node: TrustCenterReference!
|
||||
}
|
||||
|
||||
type TrustCenterFile implements Node {
|
||||
id: ID!
|
||||
name: String!
|
||||
category: String!
|
||||
fileUrl: String! @goField(forceResolver: true)
|
||||
trustCenterVisibility: TrustCenterVisibility!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
organization: Organization! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterFileConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.TrustCenterFileConnection"
|
||||
) {
|
||||
totalCount: Int! @goField(forceResolver: true)
|
||||
edges: [TrustCenterFileEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type TrustCenterFileEdge {
|
||||
cursor: CursorKey!
|
||||
node: TrustCenterFile!
|
||||
}
|
||||
|
||||
type UserConnection
|
||||
@goModel(
|
||||
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.UserConnection"
|
||||
@@ -2824,6 +2884,23 @@ type Mutation {
|
||||
input: DeleteTrustCenterReferenceInput!
|
||||
): DeleteTrustCenterReferencePayload!
|
||||
|
||||
# Trust Center File mutations
|
||||
createTrustCenterFile(
|
||||
input: CreateTrustCenterFileInput!
|
||||
): CreateTrustCenterFilePayload!
|
||||
|
||||
updateTrustCenterFile(
|
||||
input: UpdateTrustCenterFileInput!
|
||||
): UpdateTrustCenterFilePayload!
|
||||
|
||||
getTrustCenterFile(
|
||||
input: GetTrustCenterFileInput!
|
||||
): GetTrustCenterFilePayload!
|
||||
|
||||
deleteTrustCenterFile(
|
||||
input: DeleteTrustCenterFileInput!
|
||||
): DeleteTrustCenterFilePayload!
|
||||
|
||||
# User mutations
|
||||
confirmEmail(input: ConfirmEmailInput!): ConfirmEmailPayload!
|
||||
inviteUser(input: InviteUserInput!): InviteUserPayload!
|
||||
@@ -3151,6 +3228,7 @@ input UpdateTrustCenterAccessInput {
|
||||
active: Boolean
|
||||
documentIds: [ID!]
|
||||
reportIds: [ID!]
|
||||
trustCenterFileIds: [ID!]
|
||||
}
|
||||
|
||||
input DeleteTrustCenterAccessInput {
|
||||
@@ -3177,6 +3255,29 @@ input DeleteTrustCenterReferenceInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input CreateTrustCenterFileInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
category: String!
|
||||
file: Upload!
|
||||
trustCenterVisibility: TrustCenterVisibility!
|
||||
}
|
||||
|
||||
input UpdateTrustCenterFileInput {
|
||||
id: ID!
|
||||
name: String
|
||||
category: String
|
||||
trustCenterVisibility: TrustCenterVisibility
|
||||
}
|
||||
|
||||
input GetTrustCenterFileInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input DeleteTrustCenterFileInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input CreateVendorInput {
|
||||
organizationId: ID!
|
||||
name: String!
|
||||
@@ -3854,6 +3955,22 @@ type DeleteTrustCenterReferencePayload {
|
||||
deletedTrustCenterReferenceId: ID!
|
||||
}
|
||||
|
||||
type CreateTrustCenterFilePayload {
|
||||
trustCenterFileEdge: TrustCenterFileEdge!
|
||||
}
|
||||
|
||||
type UpdateTrustCenterFilePayload {
|
||||
trustCenterFile: TrustCenterFile!
|
||||
}
|
||||
|
||||
type GetTrustCenterFilePayload {
|
||||
trustCenterFile: TrustCenterFile!
|
||||
}
|
||||
|
||||
type DeleteTrustCenterFilePayload {
|
||||
deletedTrustCenterFileId: ID!
|
||||
}
|
||||
|
||||
type CreateControlPayload {
|
||||
controlEdge: ControlEdge!
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
65
pkg/server/api/console/v1/types/trust_center_file.go
Normal file
65
pkg/server/api/console/v1/types/trust_center_file.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
type TrustCenterFileOrderBy = OrderBy[coredata.TrustCenterFileOrderField]
|
||||
|
||||
type TrustCenterFileConnection struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
Edges []*TrustCenterFileEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
ParentID gid.GID `json:"-"`
|
||||
}
|
||||
|
||||
func NewTrustCenterFile(tcf *coredata.TrustCenterFile) *TrustCenterFile {
|
||||
return &TrustCenterFile{
|
||||
ID: tcf.ID,
|
||||
Name: tcf.Name,
|
||||
Category: tcf.Category,
|
||||
TrustCenterVisibility: tcf.TrustCenterVisibility,
|
||||
CreatedAt: tcf.CreatedAt,
|
||||
UpdatedAt: tcf.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFileConnection(
|
||||
p *page.Page[*coredata.TrustCenterFile, coredata.TrustCenterFileOrderField],
|
||||
parentID gid.GID,
|
||||
) *TrustCenterFileConnection {
|
||||
var edges = make([]*TrustCenterFileEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewTrustCenterFileEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &TrustCenterFileConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
ParentID: parentID,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFileEdge(tcf *coredata.TrustCenterFile, orderBy coredata.TrustCenterFileOrderField) *TrustCenterFileEdge {
|
||||
return &TrustCenterFileEdge{
|
||||
Cursor: tcf.CursorKey(orderBy),
|
||||
Node: NewTrustCenterFile(tcf),
|
||||
}
|
||||
}
|
||||
@@ -541,6 +541,18 @@ type CreateTrustCenterAccessPayload struct {
|
||||
TrustCenterAccessEdge *TrustCenterAccessEdge `json:"trustCenterAccessEdge"`
|
||||
}
|
||||
|
||||
type CreateTrustCenterFileInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
File graphql.Upload `json:"file"`
|
||||
TrustCenterVisibility coredata.TrustCenterVisibility `json:"trustCenterVisibility"`
|
||||
}
|
||||
|
||||
type CreateTrustCenterFilePayload struct {
|
||||
TrustCenterFileEdge *TrustCenterFileEdge `json:"trustCenterFileEdge"`
|
||||
}
|
||||
|
||||
type CreateTrustCenterReferenceInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
Name string `json:"name"`
|
||||
@@ -916,6 +928,14 @@ type DeleteTrustCenterAccessPayload struct {
|
||||
DeletedTrustCenterAccessID gid.GID `json:"deletedTrustCenterAccessId"`
|
||||
}
|
||||
|
||||
type DeleteTrustCenterFileInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
}
|
||||
|
||||
type DeleteTrustCenterFilePayload struct {
|
||||
DeletedTrustCenterFileID gid.GID `json:"deletedTrustCenterFileId"`
|
||||
}
|
||||
|
||||
type DeleteTrustCenterNDAInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
}
|
||||
@@ -1170,6 +1190,14 @@ type GenerateFrameworkStateOfApplicabilityPayload struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type GetTrustCenterFileInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
}
|
||||
|
||||
type GetTrustCenterFilePayload struct {
|
||||
TrustCenterFile *TrustCenterFile `json:"trustCenterFile"`
|
||||
}
|
||||
|
||||
type ImportFrameworkInput struct {
|
||||
OrganizationID gid.GID `json:"organizationId"`
|
||||
File graphql.Upload `json:"file"`
|
||||
@@ -1365,6 +1393,7 @@ type Organization struct {
|
||||
ContinualImprovements *ContinualImprovementConnection `json:"continualImprovements"`
|
||||
ProcessingActivities *ProcessingActivityConnection `json:"processingActivities"`
|
||||
Snapshots *SnapshotConnection `json:"snapshots"`
|
||||
TrustCenterFiles *TrustCenterFileConnection `json:"trustCenterFiles"`
|
||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||
CustomDomain *CustomDomain `json:"customDomain,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
@@ -1675,6 +1704,7 @@ type TrustCenterDocumentAccess struct {
|
||||
TrustCenterAccess *TrustCenterAccess `json:"trustCenterAccess"`
|
||||
Document *Document `json:"document,omitempty"`
|
||||
Report *Report `json:"report,omitempty"`
|
||||
TrustCenterFile *TrustCenterFile `json:"trustCenterFile,omitempty"`
|
||||
}
|
||||
|
||||
func (TrustCenterDocumentAccess) IsNode() {}
|
||||
@@ -1690,6 +1720,25 @@ type TrustCenterEdge struct {
|
||||
Node *TrustCenter `json:"node"`
|
||||
}
|
||||
|
||||
type TrustCenterFile struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
FileURL string `json:"fileUrl"`
|
||||
TrustCenterVisibility coredata.TrustCenterVisibility `json:"trustCenterVisibility"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Organization *Organization `json:"organization"`
|
||||
}
|
||||
|
||||
func (TrustCenterFile) IsNode() {}
|
||||
func (this TrustCenterFile) GetID() gid.GID { return this.ID }
|
||||
|
||||
type TrustCenterFileEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *TrustCenterFile `json:"node"`
|
||||
}
|
||||
|
||||
type TrustCenterReference struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -1948,17 +1997,29 @@ type UpdateTaskPayload struct {
|
||||
}
|
||||
|
||||
type UpdateTrustCenterAccessInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
DocumentIds []gid.GID `json:"documentIds,omitempty"`
|
||||
ReportIds []gid.GID `json:"reportIds,omitempty"`
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
DocumentIds []gid.GID `json:"documentIds,omitempty"`
|
||||
ReportIds []gid.GID `json:"reportIds,omitempty"`
|
||||
TrustCenterFileIds []gid.GID `json:"trustCenterFileIds,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterAccessPayload struct {
|
||||
TrustCenterAccess *TrustCenterAccess `json:"trustCenterAccess"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterFileInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
Category *string `json:"category,omitempty"`
|
||||
TrustCenterVisibility *coredata.TrustCenterVisibility `json:"trustCenterVisibility,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterFilePayload struct {
|
||||
TrustCenterFile *TrustCenterFile `json:"trustCenterFile"`
|
||||
}
|
||||
|
||||
type UpdateTrustCenterInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
Active *bool `json:"active,omitempty"`
|
||||
|
||||
@@ -1288,11 +1288,12 @@ func (r *mutationResolver) UpdateTrustCenterAccess(ctx context.Context, input ty
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
access, err := prb.TrustCenterAccesses.Update(ctx, &probo.UpdateTrustCenterAccessRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Active: input.Active,
|
||||
DocumentIDs: input.DocumentIds,
|
||||
ReportIDs: input.ReportIds,
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Active: input.Active,
|
||||
DocumentIDs: input.DocumentIds,
|
||||
ReportIDs: input.ReportIds,
|
||||
TrustCenterFileIDs: input.TrustCenterFileIds,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update trust center access: %w", err))
|
||||
@@ -1390,6 +1391,82 @@ func (r *mutationResolver) DeleteTrustCenterReference(ctx context.Context, input
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateTrustCenterFile is the resolver for the createTrustCenterFile field.
|
||||
func (r *mutationResolver) CreateTrustCenterFile(ctx context.Context, input types.CreateTrustCenterFileInput) (*types.CreateTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Create(ctx, &probo.CreateTrustCenterFileRequest{
|
||||
OrganizationID: input.OrganizationID,
|
||||
Name: input.Name,
|
||||
Category: input.Category,
|
||||
File: probo.File{
|
||||
Content: input.File.File,
|
||||
Filename: input.File.Filename,
|
||||
Size: input.File.Size,
|
||||
ContentType: input.File.ContentType,
|
||||
},
|
||||
TrustCenterVisibility: input.TrustCenterVisibility,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.CreateTrustCenterFilePayload{
|
||||
TrustCenterFileEdge: types.NewTrustCenterFileEdge(file, coredata.TrustCenterFileOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateTrustCenterFile is the resolver for the updateTrustCenterFile field.
|
||||
func (r *mutationResolver) UpdateTrustCenterFile(ctx context.Context, input types.UpdateTrustCenterFileInput) (*types.UpdateTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Update(ctx, &probo.UpdateTrustCenterFileRequest{
|
||||
ID: input.ID,
|
||||
Name: input.Name,
|
||||
Category: input.Category,
|
||||
TrustCenterVisibility: input.TrustCenterVisibility,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot update trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.UpdateTrustCenterFilePayload{
|
||||
TrustCenterFile: types.NewTrustCenterFile(file),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetTrustCenterFile is the resolver for the getTrustCenterFile field.
|
||||
func (r *mutationResolver) GetTrustCenterFile(ctx context.Context, input types.GetTrustCenterFileInput) (*types.GetTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Get(ctx, &probo.GetTrustCenterFileRequest{
|
||||
ID: input.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.GetTrustCenterFilePayload{
|
||||
TrustCenterFile: types.NewTrustCenterFile(file),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteTrustCenterFile is the resolver for the deleteTrustCenterFile field.
|
||||
func (r *mutationResolver) DeleteTrustCenterFile(ctx context.Context, input types.DeleteTrustCenterFileInput) (*types.DeleteTrustCenterFilePayload, error) {
|
||||
prb := r.ProboService(ctx, input.ID.TenantID())
|
||||
|
||||
err := prb.TrustCenterFiles.Delete(ctx, &probo.DeleteTrustCenterFileRequest{
|
||||
ID: input.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot delete trust center file: %w", err)
|
||||
}
|
||||
|
||||
return &types.DeleteTrustCenterFilePayload{
|
||||
DeletedTrustCenterFileID: input.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConfirmEmail is the resolver for the confirmEmail field.
|
||||
func (r *mutationResolver) ConfirmEmail(ctx context.Context, input types.ConfirmEmailInput) (*types.ConfirmEmailPayload, error) {
|
||||
err := r.authSvc.ConfirmEmail(ctx, input.Token)
|
||||
@@ -4153,6 +4230,31 @@ func (r *organizationResolver) Snapshots(ctx context.Context, obj *types.Organiz
|
||||
return types.NewSnapshotConnection(page, r, obj.ID), nil
|
||||
}
|
||||
|
||||
// TrustCenterFiles is the resolver for the trustCenterFiles field.
|
||||
func (r *organizationResolver) TrustCenterFiles(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.TrustCenterFileOrderField]) (*types.TrustCenterFileConnection, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.TrustCenterFileOrderField]{
|
||||
Field: coredata.TrustCenterFileOrderFieldCreatedAt,
|
||||
Direction: page.OrderDirectionDesc,
|
||||
}
|
||||
if orderBy != nil {
|
||||
pageOrderBy = page.OrderBy[coredata.TrustCenterFileOrderField]{
|
||||
Field: orderBy.Field,
|
||||
Direction: orderBy.Direction,
|
||||
}
|
||||
}
|
||||
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
pageResult, err := prb.TrustCenterFiles.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list organization trust center files: %w", err))
|
||||
}
|
||||
|
||||
return types.NewTrustCenterFileConnection(pageResult, obj.ID), nil
|
||||
}
|
||||
|
||||
// TrustCenter is the resolver for the trustCenter field.
|
||||
func (r *organizationResolver) TrustCenter(ctx context.Context, obj *types.Organization) (*types.TrustCenter, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -4930,6 +5032,29 @@ func (r *trustCenterDocumentAccessResolver) Report(ctx context.Context, obj *typ
|
||||
return types.NewReport(report), nil
|
||||
}
|
||||
|
||||
// TrustCenterFile is the resolver for the trustCenterFile field.
|
||||
func (r *trustCenterDocumentAccessResolver) TrustCenterFile(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.TrustCenterFile, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
documentAccess, err := prb.TrustCenterAccesses.GetDocumentAccess(ctx, obj.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load trust center document access: %w", err)
|
||||
}
|
||||
|
||||
if documentAccess.TrustCenterFileID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
trustCenterFile, err := prb.TrustCenterFiles.Get(ctx, &probo.GetTrustCenterFileRequest{
|
||||
ID: *documentAccess.TrustCenterFileID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
return types.NewTrustCenterFile(trustCenterFile), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *trustCenterDocumentAccessConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterDocumentAccessConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
@@ -4942,6 +5067,48 @@ func (r *trustCenterDocumentAccessConnectionResolver) TotalCount(ctx context.Con
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FileURL is the resolver for the fileUrl field.
|
||||
func (r *trustCenterFileResolver) FileURL(ctx context.Context, obj *types.TrustCenterFile) (string, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
fileURL, err := prb.TrustCenterFiles.GenerateFileURL(ctx, obj.ID, 1*time.Hour)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to generate file URL: %w", err))
|
||||
}
|
||||
|
||||
return fileURL, nil
|
||||
}
|
||||
|
||||
// Organization is the resolver for the organization field.
|
||||
func (r *trustCenterFileResolver) Organization(ctx context.Context, obj *types.TrustCenterFile) (*types.Organization, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
|
||||
file, err := prb.TrustCenterFiles.Get(ctx, &probo.GetTrustCenterFileRequest{
|
||||
ID: obj.ID,
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get trust center file: %w", err))
|
||||
}
|
||||
|
||||
organization, err := prb.Organizations.Get(ctx, file.OrganizationID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get organization: %w", err))
|
||||
}
|
||||
|
||||
return types.NewOrganization(organization), nil
|
||||
}
|
||||
|
||||
// TotalCount is the resolver for the totalCount field.
|
||||
func (r *trustCenterFileConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterFileConnection) (int, error) {
|
||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||
|
||||
count, err := prb.TrustCenterFiles.CountForOrganizationID(ctx, obj.ParentID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot count trust center files: %w", err))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *trustCenterReferenceResolver) LogoURL(ctx context.Context, obj *types.TrustCenterReference) (string, error) {
|
||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||
@@ -5563,6 +5730,16 @@ func (r *Resolver) TrustCenterDocumentAccessConnection() schema.TrustCenterDocum
|
||||
return &trustCenterDocumentAccessConnectionResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterFile returns schema.TrustCenterFileResolver implementation.
|
||||
func (r *Resolver) TrustCenterFile() schema.TrustCenterFileResolver {
|
||||
return &trustCenterFileResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterFileConnection returns schema.TrustCenterFileConnectionResolver implementation.
|
||||
func (r *Resolver) TrustCenterFileConnection() schema.TrustCenterFileConnectionResolver {
|
||||
return &trustCenterFileConnectionResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterReference returns schema.TrustCenterReferenceResolver implementation.
|
||||
func (r *Resolver) TrustCenterReference() schema.TrustCenterReferenceResolver {
|
||||
return &trustCenterReferenceResolver{r}
|
||||
@@ -5658,6 +5835,8 @@ type trustCenterResolver struct{ *Resolver }
|
||||
type trustCenterAccessResolver struct{ *Resolver }
|
||||
type trustCenterDocumentAccessResolver struct{ *Resolver }
|
||||
type trustCenterDocumentAccessConnectionResolver struct{ *Resolver }
|
||||
type trustCenterFileResolver struct{ *Resolver }
|
||||
type trustCenterFileConnectionResolver struct{ *Resolver }
|
||||
type trustCenterReferenceResolver struct{ *Resolver }
|
||||
type trustCenterReferenceConnectionResolver struct{ *Resolver }
|
||||
type userConnectionResolver struct{ *Resolver }
|
||||
|
||||
@@ -476,6 +476,24 @@ type TrustCenterReferenceEdge {
|
||||
node: TrustCenterReference!
|
||||
}
|
||||
|
||||
type TrustCenterFile implements Node {
|
||||
id: ID!
|
||||
name: String!
|
||||
category: String!
|
||||
isUserAuthorized: Boolean! @goField(forceResolver: true)
|
||||
hasUserRequestedAccess: Boolean! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterFileConnection {
|
||||
edges: [TrustCenterFileEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type TrustCenterFileEdge {
|
||||
cursor: CursorKey!
|
||||
node: TrustCenterFile!
|
||||
}
|
||||
|
||||
type TrustCenter implements Node {
|
||||
id: ID!
|
||||
active: Boolean!
|
||||
@@ -513,6 +531,13 @@ type TrustCenter implements Node {
|
||||
last: Int
|
||||
before: CursorKey
|
||||
): TrustCenterReferenceConnection! @goField(forceResolver: true)
|
||||
|
||||
trustCenterFiles(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
): TrustCenterFileConnection! @goField(forceResolver: true)
|
||||
}
|
||||
|
||||
type TrustCenterAccess implements Node {
|
||||
@@ -559,6 +584,17 @@ input RequestReportAccessInput {
|
||||
name: String
|
||||
}
|
||||
|
||||
input RequestTrustCenterFileAccessInput {
|
||||
trustCenterId: ID!
|
||||
trustCenterFileId: ID!
|
||||
email: String
|
||||
name: String
|
||||
}
|
||||
|
||||
input ExportTrustCenterFileInput {
|
||||
trustCenterFileId: ID!
|
||||
}
|
||||
|
||||
type ExportDocumentPDFPayload {
|
||||
data: String!
|
||||
}
|
||||
@@ -567,6 +603,10 @@ type ExportReportPDFPayload {
|
||||
data: String!
|
||||
}
|
||||
|
||||
type ExportTrustCenterFilePayload {
|
||||
data: String!
|
||||
}
|
||||
|
||||
type AcceptNonDisclosureAgreementPayload {
|
||||
success: Boolean!
|
||||
}
|
||||
@@ -598,4 +638,12 @@ type Mutation {
|
||||
requestReportAccess(
|
||||
input: RequestReportAccessInput!
|
||||
): RequestAccessesPayload! @mustBeAuthenticated(role: NONE)
|
||||
|
||||
requestTrustCenterFileAccess(
|
||||
input: RequestTrustCenterFileAccessInput!
|
||||
): RequestAccessesPayload! @mustBeAuthenticated(role: NONE)
|
||||
|
||||
exportTrustCenterFile(
|
||||
input: ExportTrustCenterFileInput!
|
||||
): ExportTrustCenterFilePayload! @mustBeAuthenticated(role: NONE)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -148,6 +148,7 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
|
||||
var documentIDs []gid.GID
|
||||
var reportIDs []gid.GID
|
||||
var fileIDs []gid.GID
|
||||
|
||||
switch action.ActionID {
|
||||
case "accept_all":
|
||||
@@ -157,9 +158,9 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
return
|
||||
}
|
||||
|
||||
documentIDs, reportIDs, err = tenantSvc.SlackMessages.GetSlackMessageMetadataByID(ctx, currentMessageId)
|
||||
documentIDs, reportIDs, fileIDs, err = tenantSvc.SlackMessages.GetSlackMessageDocumentIDs(ctx, currentMessageId)
|
||||
if err != nil {
|
||||
logger.ErrorCtx(ctx, "cannot load slack message metadata by ID", log.Error(err))
|
||||
logger.ErrorCtx(ctx, "cannot load slack message document ids", log.Error(err))
|
||||
httpserver.RenderJSON(w, http.StatusInternalServerError, SlackInteractiveResponse{Success: false, Message: "internal server error"})
|
||||
return
|
||||
}
|
||||
@@ -180,6 +181,14 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
}
|
||||
reportIDs = []gid.GID{repID}
|
||||
|
||||
case "accept_file":
|
||||
fileID, err := gid.ParseGID(action.Value)
|
||||
if err != nil {
|
||||
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: "invalid file ID"})
|
||||
return
|
||||
}
|
||||
fileIDs = []gid.GID{fileID}
|
||||
|
||||
default:
|
||||
httpserver.RenderJSON(w, http.StatusBadRequest, SlackInteractiveResponse{Success: false, Message: fmt.Sprintf("unknown action: %s", action.ActionID)})
|
||||
return
|
||||
@@ -191,6 +200,7 @@ func slackHandler(trustSvc *trust.Service, slackSigningSecret string, logger *lo
|
||||
requesterEmail,
|
||||
documentIDs,
|
||||
reportIDs,
|
||||
fileIDs,
|
||||
); err != nil {
|
||||
logger.ErrorCtx(ctx, "failed to grant access", log.Error(err))
|
||||
httpserver.RenderJSON(w, http.StatusInternalServerError, SlackInteractiveResponse{Success: false, Message: "internal server error"})
|
||||
|
||||
49
pkg/server/api/trust/v1/types/trust_center_file.go
Normal file
49
pkg/server/api/trust/v1/types/trust_center_file.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
)
|
||||
|
||||
func NewTrustCenterFileConnection(
|
||||
p *page.Page[*coredata.TrustCenterFile, coredata.TrustCenterFileOrderField],
|
||||
) *TrustCenterFileConnection {
|
||||
edges := make([]*TrustCenterFileEdge, len(p.Data))
|
||||
for i, trustCenterFile := range p.Data {
|
||||
edges[i] = NewTrustCenterFileEdge(trustCenterFile, p.Cursor.OrderBy.Field)
|
||||
}
|
||||
|
||||
return &TrustCenterFileConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFile(f *coredata.TrustCenterFile) *TrustCenterFile {
|
||||
return &TrustCenterFile{
|
||||
ID: f.ID,
|
||||
Name: f.Name,
|
||||
Category: f.Category,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTrustCenterFileEdge(f *coredata.TrustCenterFile, orderField coredata.TrustCenterFileOrderField) *TrustCenterFileEdge {
|
||||
return &TrustCenterFileEdge{
|
||||
Node: NewTrustCenterFile(f),
|
||||
Cursor: f.CursorKey(orderField),
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,14 @@ type ExportReportPDFPayload struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type ExportTrustCenterFileInput struct {
|
||||
TrustCenterFileID gid.GID `json:"trustCenterFileId"`
|
||||
}
|
||||
|
||||
type ExportTrustCenterFilePayload struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type Framework struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -151,6 +159,13 @@ type RequestReportAccessInput struct {
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type RequestTrustCenterFileAccessInput struct {
|
||||
TrustCenterID gid.GID `json:"trustCenterId"`
|
||||
TrustCenterFileID gid.GID `json:"trustCenterFileId"`
|
||||
Email *string `json:"email,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type TrustCenter struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Active bool `json:"active"`
|
||||
@@ -164,6 +179,7 @@ type TrustCenter struct {
|
||||
Audits *AuditConnection `json:"audits"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
References *TrustCenterReferenceConnection `json:"references"`
|
||||
TrustCenterFiles *TrustCenterFileConnection `json:"trustCenterFiles"`
|
||||
}
|
||||
|
||||
func (TrustCenter) IsNode() {}
|
||||
@@ -180,6 +196,27 @@ type TrustCenterAccess struct {
|
||||
func (TrustCenterAccess) IsNode() {}
|
||||
func (this TrustCenterAccess) GetID() gid.GID { return this.ID }
|
||||
|
||||
type TrustCenterFile struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Category string `json:"category"`
|
||||
IsUserAuthorized bool `json:"isUserAuthorized"`
|
||||
HasUserRequestedAccess bool `json:"hasUserRequestedAccess"`
|
||||
}
|
||||
|
||||
func (TrustCenterFile) IsNode() {}
|
||||
func (this TrustCenterFile) GetID() gid.GID { return this.ID }
|
||||
|
||||
type TrustCenterFileConnection struct {
|
||||
Edges []*TrustCenterFileEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type TrustCenterFileEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *TrustCenterFile `json:"node"`
|
||||
}
|
||||
|
||||
type TrustCenterReference struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -445,6 +445,138 @@ func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RequestTrustCenterFileAccess is the resolver for the requestTrustCenterFileAccess field.
|
||||
func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, input types.RequestTrustCenterFileAccessInput) (*types.RequestAccessesPayload, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, input.TrustCenterID.TenantID())
|
||||
|
||||
trustCenterFile, err := publicTrustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load trust center file: %w", err))
|
||||
}
|
||||
|
||||
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityPublic {
|
||||
return nil, fmt.Errorf("trust center file is publicly available and does not require access request")
|
||||
}
|
||||
|
||||
userData := r.UserFromContext(ctx)
|
||||
if userData != nil {
|
||||
return nil, fmt.Errorf("session users cannot request trust center access")
|
||||
}
|
||||
|
||||
email := input.Email
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
if email != nil || input.Name != nil {
|
||||
return nil, fmt.Errorf("email and name are not allowed for authenticated users")
|
||||
}
|
||||
emailValue := tokenData.GetEmail()
|
||||
email = &emailValue
|
||||
}
|
||||
if email == nil {
|
||||
return nil, fmt.Errorf("email is required for unauthenticated users")
|
||||
}
|
||||
|
||||
access, err := publicTrustService.TrustCenterAccesses.Request(ctx, &trust.TrustCenterAccessRequest{
|
||||
TrustCenterID: input.TrustCenterID,
|
||||
Email: *email,
|
||||
Name: input.Name,
|
||||
DocumentIDs: []gid.GID{},
|
||||
ReportIDs: []gid.GID{},
|
||||
TrustCenterFileIDs: []gid.GID{input.TrustCenterFileID},
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot request trust center file access: %w", err))
|
||||
}
|
||||
|
||||
return &types.RequestAccessesPayload{
|
||||
TrustCenterAccess: &types.TrustCenterAccess{
|
||||
ID: access.ID,
|
||||
Email: access.Email,
|
||||
Name: access.Name,
|
||||
CreatedAt: access.CreatedAt,
|
||||
UpdatedAt: access.UpdatedAt,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ExportTrustCenterFile is the resolver for the exportTrustCenterFile field.
|
||||
func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input types.ExportTrustCenterFileInput) (*types.ExportTrustCenterFilePayload, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, input.TrustCenterFileID.TenantID())
|
||||
|
||||
trustCenterFile, err := publicTrustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load trust center file: %w", err))
|
||||
}
|
||||
|
||||
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityPublic {
|
||||
fileData, err := publicTrustService.TrustCenterFiles.ExportFileWithoutWatermark(ctx, input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot export trust center file: %w", err))
|
||||
}
|
||||
|
||||
return &types.ExportTrustCenterFilePayload{
|
||||
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(fileData)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
privateTrustService, err := r.PrivateTrustService(ctx, input.TrustCenterFileID.TenantID())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot export trust center file: %w", err)
|
||||
}
|
||||
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
ndaExists := true
|
||||
hasAcceptedNDA := false
|
||||
|
||||
trustCenter, _, err := privateTrustService.TrustCenters.Get(ctx, tokenData.TrustCenterID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot get trust center: %w", err))
|
||||
}
|
||||
if trustCenter.NonDisclosureAgreementFileID == nil {
|
||||
ndaExists = false
|
||||
}
|
||||
|
||||
if ndaExists {
|
||||
hasAcceptedNDA, err = privateTrustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(ctx, tokenData.TrustCenterID, tokenData.GetEmail())
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot check if user has accepted NDA: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
fileAccess, err := privateTrustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx, tokenData.TrustCenterID, tokenData.GetEmail(), input.TrustCenterFileID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot check trust center file access: %w", err))
|
||||
}
|
||||
|
||||
if !fileAccess.Active {
|
||||
return nil, fmt.Errorf("access denied: no permission to access this file")
|
||||
}
|
||||
|
||||
if ndaExists && !hasAcceptedNDA {
|
||||
return nil, fmt.Errorf("user has not accepted NDA")
|
||||
}
|
||||
}
|
||||
|
||||
userData := UserFromContext(ctx)
|
||||
userEmail := ""
|
||||
if userData != nil {
|
||||
userEmail = userData.EmailAddress
|
||||
}
|
||||
if tokenData != nil {
|
||||
userEmail = tokenData.GetEmail()
|
||||
}
|
||||
|
||||
fileData, err := privateTrustService.TrustCenterFiles.ExportFile(ctx, input.TrustCenterFileID, userEmail)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot export trust center file: %w", err))
|
||||
}
|
||||
|
||||
return &types.ExportTrustCenterFilePayload{
|
||||
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(fileData)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *organizationResolver) LogoURL(ctx context.Context, obj *types.Organization) (*string, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
@@ -772,6 +904,84 @@ func (r *trustCenterResolver) References(ctx context.Context, obj *types.TrustCe
|
||||
return types.NewTrustCenterReferenceConnection(referencePage), nil
|
||||
}
|
||||
|
||||
// TrustCenterFiles is the resolver for the trustCenterFiles field.
|
||||
func (r *trustCenterResolver) TrustCenterFiles(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.TrustCenterFileConnection, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
|
||||
pageOrderBy := page.OrderBy[coredata.TrustCenterFileOrderField]{
|
||||
Field: coredata.TrustCenterFileOrderFieldName,
|
||||
Direction: page.OrderDirectionAsc,
|
||||
}
|
||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||
|
||||
trustCenterFilePage, err := publicTrustService.TrustCenterFiles.ListForOrganizationId(ctx, obj.Organization.ID, cursor)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot list public trust center files: %w", err))
|
||||
}
|
||||
|
||||
return types.NewTrustCenterFileConnection(trustCenterFilePage), nil
|
||||
}
|
||||
|
||||
// IsUserAuthorized is the resolver for the isUserAuthorized field.
|
||||
func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
|
||||
trustCenterFile, err := publicTrustService.TrustCenterFiles.Get(ctx, obj.ID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot load trust center file: %w", err))
|
||||
}
|
||||
|
||||
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityPublic {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
privateTrustService, err := r.PrivateTrustService(ctx, obj.ID.TenantID())
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
userData := r.UserFromContext(ctx)
|
||||
if userData != nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
fileAccess, err := privateTrustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx, tokenData.TrustCenterID, tokenData.GetEmail(), obj.ID)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return fileAccess.Active, nil
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("no user or token data found"))
|
||||
}
|
||||
|
||||
// HasUserRequestedAccess is the resolver for the hasUserRequestedAccess field.
|
||||
func (r *trustCenterFileResolver) HasUserRequestedAccess(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
|
||||
privateTrustService, err := r.PrivateTrustService(ctx, obj.ID.TenantID())
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
userData := r.UserFromContext(ctx)
|
||||
if userData != nil {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
tokenData := TokenAccessFromContext(ctx)
|
||||
if tokenData != nil {
|
||||
_, err := privateTrustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx, tokenData.TrustCenterID, tokenData.GetEmail(), obj.ID)
|
||||
if err != nil {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// LogoURL is the resolver for the logoUrl field.
|
||||
func (r *trustCenterReferenceResolver) LogoURL(ctx context.Context, obj *types.TrustCenterReference) (string, error) {
|
||||
publicTrustService := r.PublicTrustService(ctx, obj.ID.TenantID())
|
||||
@@ -805,6 +1015,11 @@ func (r *Resolver) Report() schema.ReportResolver { return &reportResolver{r} }
|
||||
// TrustCenter returns schema.TrustCenterResolver implementation.
|
||||
func (r *Resolver) TrustCenter() schema.TrustCenterResolver { return &trustCenterResolver{r} }
|
||||
|
||||
// TrustCenterFile returns schema.TrustCenterFileResolver implementation.
|
||||
func (r *Resolver) TrustCenterFile() schema.TrustCenterFileResolver {
|
||||
return &trustCenterFileResolver{r}
|
||||
}
|
||||
|
||||
// TrustCenterReference returns schema.TrustCenterReferenceResolver implementation.
|
||||
func (r *Resolver) TrustCenterReference() schema.TrustCenterReferenceResolver {
|
||||
return &trustCenterReferenceResolver{r}
|
||||
@@ -817,4 +1032,5 @@ type organizationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
type reportResolver struct{ *Resolver }
|
||||
type trustCenterResolver struct{ *Resolver }
|
||||
type trustCenterFileResolver struct{ *Resolver }
|
||||
type trustCenterReferenceResolver struct{ *Resolver }
|
||||
|
||||
@@ -74,6 +74,7 @@ type (
|
||||
Frameworks *FrameworkService
|
||||
TrustCenterAccesses *TrustCenterAccessService
|
||||
TrustCenterReferences *TrustCenterReferenceService
|
||||
TrustCenterFiles *TrustCenterFileService
|
||||
Reports *ReportService
|
||||
Organizations *OrganizationService
|
||||
SlackMessages *SlackMessageService
|
||||
@@ -136,6 +137,7 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
||||
tenantService.Frameworks = &FrameworkService{svc: tenantService}
|
||||
tenantService.TrustCenterAccesses = &TrustCenterAccessService{svc: tenantService, auth: s.auth, logger: s.logger}
|
||||
tenantService.TrustCenterReferences = &TrustCenterReferenceService{svc: tenantService}
|
||||
tenantService.TrustCenterFiles = &TrustCenterFileService{svc: tenantService}
|
||||
tenantService.Reports = &ReportService{svc: tenantService}
|
||||
tenantService.Organizations = &OrganizationService{svc: tenantService}
|
||||
tenantService.SlackMessages = &SlackMessageService{svc: tenantService, slackClient: slackClient}
|
||||
|
||||
@@ -51,9 +51,17 @@ type (
|
||||
Granted bool
|
||||
}
|
||||
|
||||
SlackMessageFile struct {
|
||||
ID string
|
||||
Name string
|
||||
Category string
|
||||
Granted bool
|
||||
}
|
||||
|
||||
SlackMessageMetadata struct {
|
||||
Documents []SlackMessageDocument
|
||||
Reports []SlackMessageReport
|
||||
Files []SlackMessageFile
|
||||
}
|
||||
)
|
||||
|
||||
@@ -61,6 +69,7 @@ func (m SlackMessageMetadata) toMap() map[string]any {
|
||||
return map[string]any{
|
||||
"documents": m.Documents,
|
||||
"reports": m.Reports,
|
||||
"files": m.Files,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +95,10 @@ func (s *Service) GetInitialSlackMessageByChannelAndTS(
|
||||
return &slackMessage, nil
|
||||
}
|
||||
|
||||
func (s *SlackMessageService) GetSlackMessageMetadataByID(
|
||||
func (s *SlackMessageService) GetSlackMessageDocumentIDs(
|
||||
ctx context.Context,
|
||||
slackMessageID gid.GID,
|
||||
) (documentIDs []gid.GID, reportIDs []gid.GID, err error) {
|
||||
) (documentIDs []gid.GID, reportIDs []gid.GID, fileIDs []gid.GID, err error) {
|
||||
var slackMessage coredata.SlackMessage
|
||||
|
||||
err = s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
@@ -101,52 +110,14 @@ func (s *SlackMessageService) GetSlackMessageMetadataByID(
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
documents, ok := slackMessage.Metadata["documents"].([]any)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("invalid documents metadata")
|
||||
}
|
||||
documentIDs = extractIDsFromMetadata(slackMessage.Metadata, "documents")
|
||||
reportIDs = extractIDsFromMetadata(slackMessage.Metadata, "reports")
|
||||
fileIDs = extractIDsFromMetadata(slackMessage.Metadata, "files")
|
||||
|
||||
for _, docAny := range documents {
|
||||
doc, ok := docAny.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
idStr, ok := doc["ID"].(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
docID, err := gid.ParseGID(idStr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
documentIDs = append(documentIDs, docID)
|
||||
}
|
||||
|
||||
reports, ok := slackMessage.Metadata["reports"].([]any)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("invalid reports metadata")
|
||||
}
|
||||
|
||||
for _, repAny := range reports {
|
||||
rep, ok := repAny.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
idStr, ok := rep["ID"].(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
repID, err := gid.ParseGID(idStr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
reportIDs = append(reportIDs, repID)
|
||||
}
|
||||
|
||||
return documentIDs, reportIDs, nil
|
||||
return documentIDs, reportIDs, fileIDs, nil
|
||||
}
|
||||
|
||||
func (s *SlackMessageService) UpdateSlackAccessMessage(
|
||||
@@ -171,7 +142,7 @@ func (s *SlackMessageService) UpdateSlackAccessMessage(
|
||||
return fmt.Errorf("cannot load trust center access: %w", err)
|
||||
}
|
||||
|
||||
documents, reports, err := s.loadDocumentsAndReportsFromAccesses(ctx, tx, trustCenterAccess.ID)
|
||||
documents, reports, files, err := s.loadDocumentsReportsAndFilesFromAccesses(ctx, tx, trustCenterAccess.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -185,6 +156,7 @@ func (s *SlackMessageService) UpdateSlackAccessMessage(
|
||||
trustCenter.OrganizationID,
|
||||
documents,
|
||||
reports,
|
||||
files,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -193,6 +165,7 @@ func (s *SlackMessageService) UpdateSlackAccessMessage(
|
||||
metadata := SlackMessageMetadata{
|
||||
Documents: documents,
|
||||
Reports: reports,
|
||||
Files: files,
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
@@ -261,9 +234,9 @@ func (s *SlackMessageService) QueueSlackNotification(
|
||||
return fmt.Errorf("no slack connector found for organization")
|
||||
}
|
||||
|
||||
documents, reports, err := s.loadDocumentsAndReportsFromAccesses(ctx, tx, trustCenterAccess.ID)
|
||||
documents, reports, files, err := s.loadDocumentsReportsAndFilesFromAccesses(ctx, tx, trustCenterAccess.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load documents and reports: %w", err)
|
||||
return fmt.Errorf("cannot load documents, reports and files: %w", err)
|
||||
}
|
||||
|
||||
slackMessageID := gid.New(s.svc.scope.GetTenantID(), coredata.SlackMessageEntityType)
|
||||
@@ -275,6 +248,7 @@ func (s *SlackMessageService) QueueSlackNotification(
|
||||
trustCenter.OrganizationID,
|
||||
documents,
|
||||
reports,
|
||||
files,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot build access request message: %w", err)
|
||||
@@ -283,6 +257,7 @@ func (s *SlackMessageService) QueueSlackNotification(
|
||||
metadata := SlackMessageMetadata{
|
||||
Documents: documents,
|
||||
Reports: reports,
|
||||
Files: files,
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
@@ -334,28 +309,30 @@ func (s *SlackMessageService) QueueSlackNotification(
|
||||
})
|
||||
}
|
||||
|
||||
func (s *SlackMessageService) loadDocumentsAndReportsFromAccesses(
|
||||
func (s *SlackMessageService) loadDocumentsReportsAndFilesFromAccesses(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
trustCenterAccessID gid.GID,
|
||||
) (
|
||||
documents []SlackMessageDocument,
|
||||
reports []SlackMessageReport,
|
||||
files []SlackMessageFile,
|
||||
err error,
|
||||
) {
|
||||
documents = []SlackMessageDocument{}
|
||||
reports = []SlackMessageReport{}
|
||||
files = []SlackMessageFile{}
|
||||
|
||||
var accesses coredata.TrustCenterDocumentAccesses
|
||||
if err := accesses.LoadAllByTrustCenterAccessID(ctx, conn, s.svc.scope, trustCenterAccessID); err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot load trust center document accesses: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("cannot load trust center document accesses: %w", err)
|
||||
}
|
||||
|
||||
for _, access := range accesses {
|
||||
if access.DocumentID != nil {
|
||||
doc := &coredata.Document{}
|
||||
if err := doc.LoadByID(ctx, conn, s.svc.scope, *access.DocumentID); err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot load document: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("cannot load document: %w", err)
|
||||
}
|
||||
documents = append(documents, SlackMessageDocument{
|
||||
ID: access.DocumentID.String(),
|
||||
@@ -367,17 +344,17 @@ func (s *SlackMessageService) loadDocumentsAndReportsFromAccesses(
|
||||
if access.ReportID != nil {
|
||||
rep := &coredata.Report{}
|
||||
if err := rep.LoadByID(ctx, conn, s.svc.scope, *access.ReportID); err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot load report: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("cannot load report: %w", err)
|
||||
}
|
||||
|
||||
audit := &coredata.Audit{}
|
||||
if err := audit.LoadByReportID(ctx, conn, s.svc.scope, *access.ReportID); err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot load audit: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("cannot load audit: %w", err)
|
||||
}
|
||||
|
||||
framework := &coredata.Framework{}
|
||||
if err := framework.LoadByID(ctx, conn, s.svc.scope, audit.FrameworkID); err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot load framework: %w", err)
|
||||
return nil, nil, nil, fmt.Errorf("cannot load framework: %w", err)
|
||||
}
|
||||
|
||||
label := framework.Name
|
||||
@@ -391,9 +368,22 @@ func (s *SlackMessageService) loadDocumentsAndReportsFromAccesses(
|
||||
Granted: access.Active,
|
||||
})
|
||||
}
|
||||
|
||||
if access.TrustCenterFileID != nil {
|
||||
file := &coredata.TrustCenterFile{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, *access.TrustCenterFileID); err != nil {
|
||||
return nil, nil, nil, fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
files = append(files, SlackMessageFile{
|
||||
ID: access.TrustCenterFileID.String(),
|
||||
Name: file.Name,
|
||||
Category: file.Category,
|
||||
Granted: access.Active,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return documents, reports, nil
|
||||
return documents, reports, files, nil
|
||||
}
|
||||
|
||||
func (s *SlackMessageService) buildAccessRequestMessage(
|
||||
@@ -403,9 +393,11 @@ func (s *SlackMessageService) buildAccessRequestMessage(
|
||||
organizationID gid.GID,
|
||||
documents []SlackMessageDocument,
|
||||
reports []SlackMessageReport,
|
||||
files []SlackMessageFile,
|
||||
) (map[string]any, error) {
|
||||
var documentIDs []string
|
||||
var reportIDs []string
|
||||
var fileIDs []string
|
||||
|
||||
for _, doc := range documents {
|
||||
documentIDs = append(documentIDs, doc.ID)
|
||||
@@ -413,6 +405,9 @@ func (s *SlackMessageService) buildAccessRequestMessage(
|
||||
for _, rep := range reports {
|
||||
reportIDs = append(reportIDs, rep.ID)
|
||||
}
|
||||
for _, file := range files {
|
||||
fileIDs = append(fileIDs, file.ID)
|
||||
}
|
||||
|
||||
templateData := struct {
|
||||
RequesterName string
|
||||
@@ -422,8 +417,10 @@ func (s *SlackMessageService) buildAccessRequestMessage(
|
||||
SlackMessageID string
|
||||
DocumentIDs []string
|
||||
ReportIDs []string
|
||||
FileIDs []string
|
||||
Documents []SlackMessageDocument
|
||||
Reports []SlackMessageReport
|
||||
Files []SlackMessageFile
|
||||
}{
|
||||
RequesterName: requesterName,
|
||||
RequesterEmail: requesterEmail,
|
||||
@@ -432,8 +429,10 @@ func (s *SlackMessageService) buildAccessRequestMessage(
|
||||
SlackMessageID: slackMessageID.String(),
|
||||
DocumentIDs: documentIDs,
|
||||
ReportIDs: reportIDs,
|
||||
FileIDs: fileIDs,
|
||||
Documents: documents,
|
||||
Reports: reports,
|
||||
Files: files,
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -448,3 +447,30 @@ func (s *SlackMessageService) buildAccessRequestMessage(
|
||||
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func extractIDsFromMetadata(metadata map[string]any, fieldName string) []gid.GID {
|
||||
ids := []gid.GID{}
|
||||
|
||||
items, ok := metadata[fieldName].([]any)
|
||||
if !ok || items == nil {
|
||||
return ids
|
||||
}
|
||||
|
||||
for _, itemAny := range items {
|
||||
item, ok := itemAny.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
idStr, ok := item["ID"].(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
id, err := gid.ParseGID(idStr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
@@ -107,6 +107,40 @@
|
||||
"value": "{{.ID}}",
|
||||
"style": "primary"
|
||||
}{{end}}
|
||||
}{{end}}{{end}}{{if .Files}},
|
||||
{
|
||||
"type": "divider"
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "*📎 Requested Files*"
|
||||
}
|
||||
}{{range .Files}},
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "<https://{{$.Domain}}/organizations/{{$.OrganizationID}}/trust-center/files|{{jsonEscape .Name}}>{{if .Category}} ({{jsonEscape .Category}}){{end}}"
|
||||
},
|
||||
"accessory": {{if .Granted}}{
|
||||
"type": "button",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "✓ Granted"
|
||||
},
|
||||
"url": "https://{{$.Domain}}/organizations/{{$.OrganizationID}}/trust-center/access"
|
||||
}{{else}}{
|
||||
"type": "button",
|
||||
"text": {
|
||||
"type": "plain_text",
|
||||
"text": "Accept"
|
||||
},
|
||||
"action_id": "accept_file",
|
||||
"value": "{{.ID}}",
|
||||
"style": "primary"
|
||||
}{{end}}
|
||||
}{{end}}{{end}},
|
||||
{
|
||||
"type": "context",
|
||||
|
||||
@@ -67,11 +67,12 @@ type (
|
||||
}
|
||||
|
||||
TrustCenterAccessRequest struct {
|
||||
TrustCenterID gid.GID
|
||||
Email string
|
||||
Name *string
|
||||
DocumentIDs []gid.GID
|
||||
ReportIDs []gid.GID
|
||||
TrustCenterID gid.GID
|
||||
Email string
|
||||
Name *string
|
||||
DocumentIDs []gid.GID
|
||||
ReportIDs []gid.GID
|
||||
TrustCenterFileIDs []gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
@@ -145,6 +146,20 @@ func (s TrustCenterAccessService) Request(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trustCenterFileIDs := req.TrustCenterFileIDs
|
||||
if req.TrustCenterFileIDs == nil {
|
||||
var allTrustCenterFiles coredata.TrustCenterFiles
|
||||
|
||||
if err := allTrustCenterFiles.LoadAllByOrganizationID(ctx, tx, s.svc.scope, organizationID); err != nil {
|
||||
return fmt.Errorf("cannot list trust center files: %w", err)
|
||||
}
|
||||
|
||||
for _, file := range allTrustCenterFiles {
|
||||
trustCenterFileIDs = append(trustCenterFileIDs, file.ID)
|
||||
}
|
||||
}
|
||||
|
||||
existingAccess := &coredata.TrustCenterAccess{}
|
||||
err := existingAccess.LoadByTrustCenterIDAndEmail(ctx, tx, s.svc.scope, req.TrustCenterID, req.Email)
|
||||
|
||||
@@ -186,9 +201,10 @@ func (s TrustCenterAccessService) Request(
|
||||
return fmt.Errorf("cannot load existing access records: %w", err)
|
||||
}
|
||||
|
||||
existingDocumentIDs, existingReportIDs := extractExistingIDs(existingAccesses)
|
||||
existingDocumentIDs, existingReportIDs, existingTrustCenterFileIDs := extractExistingIDs(existingAccesses)
|
||||
newDocumentIDs := filterExistingIDs(documentIDs, existingDocumentIDs)
|
||||
newReportIDs := filterExistingIDs(reportIDs, existingReportIDs)
|
||||
newTrustCenterFileIDs := filterExistingIDs(trustCenterFileIDs, existingTrustCenterFileIDs)
|
||||
|
||||
var accesses coredata.TrustCenterDocumentAccesses
|
||||
|
||||
@@ -200,6 +216,10 @@ func (s TrustCenterAccessService) Request(
|
||||
return fmt.Errorf("cannot bulk insert trust center report accesses: %w", err)
|
||||
}
|
||||
|
||||
if err := accesses.BulkInsertTrustCenterFileAccesses(ctx, tx, s.svc.scope, access.ID, newTrustCenterFileIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot bulk insert trust center file accesses: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -335,12 +355,48 @@ func (s TrustCenterAccessService) LoadReportAccess(
|
||||
return reportAccess, nil
|
||||
}
|
||||
|
||||
func (s TrustCenterAccessService) LoadTrustCenterFileAccess(
|
||||
ctx context.Context,
|
||||
trustCenterID gid.GID,
|
||||
email string,
|
||||
trustCenterFileID gid.GID,
|
||||
) (*coredata.TrustCenterDocumentAccess, error) {
|
||||
var fileAccess *coredata.TrustCenterDocumentAccess
|
||||
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
access := &coredata.TrustCenterAccess{}
|
||||
err := access.LoadByTrustCenterIDAndEmail(ctx, conn, s.svc.scope, trustCenterID, email)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load trust center access: %w", err)
|
||||
}
|
||||
|
||||
if !access.Active {
|
||||
return fmt.Errorf("trust center access is not active")
|
||||
}
|
||||
|
||||
fileAccess = &coredata.TrustCenterDocumentAccess{}
|
||||
err = fileAccess.LoadByTrustCenterAccessIDAndTrustCenterFileID(ctx, conn, s.svc.scope, access.ID, trustCenterFileID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load trust center file access: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fileAccess, nil
|
||||
}
|
||||
|
||||
func (s *TrustCenterAccessService) AcceptByIDs(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
email string,
|
||||
documentIDs []gid.GID,
|
||||
reportIDs []gid.GID,
|
||||
fileIDs []gid.GID,
|
||||
) error {
|
||||
return s.svc.pg.WithTx(ctx, func(tx pg.Conn) error {
|
||||
trustCenter := &coredata.TrustCenter{}
|
||||
@@ -366,6 +422,11 @@ func (s *TrustCenterAccessService) AcceptByIDs(
|
||||
return fmt.Errorf("cannot activate report accesses: %w", err)
|
||||
}
|
||||
}
|
||||
if len(fileIDs) > 0 {
|
||||
if err := coredata.ActivateByTrustCenterFileIDs(ctx, tx, s.svc.scope, access.ID, fileIDs, now); err != nil {
|
||||
return fmt.Errorf("cannot activate trust center file accesses: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if wasInactive {
|
||||
access.Active = true
|
||||
@@ -470,9 +531,10 @@ func (s *TrustCenterAccessService) sendTrustCenterAccessEmail(
|
||||
return nil
|
||||
}
|
||||
|
||||
func extractExistingIDs(accesses coredata.TrustCenterDocumentAccesses) ([]gid.GID, []gid.GID) {
|
||||
func extractExistingIDs(accesses coredata.TrustCenterDocumentAccesses) ([]gid.GID, []gid.GID, []gid.GID) {
|
||||
var documentIDs []gid.GID
|
||||
var reportIDs []gid.GID
|
||||
var trustCenterFileIDs []gid.GID
|
||||
|
||||
for _, access := range accesses {
|
||||
if access.DocumentID != nil {
|
||||
@@ -481,9 +543,12 @@ func extractExistingIDs(accesses coredata.TrustCenterDocumentAccesses) ([]gid.GI
|
||||
if access.ReportID != nil {
|
||||
reportIDs = append(reportIDs, *access.ReportID)
|
||||
}
|
||||
if access.TrustCenterFileID != nil {
|
||||
trustCenterFileIDs = append(trustCenterFileIDs, *access.TrustCenterFileID)
|
||||
}
|
||||
}
|
||||
|
||||
return documentIDs, reportIDs
|
||||
return documentIDs, reportIDs, trustCenterFileIDs
|
||||
}
|
||||
|
||||
func filterExistingIDs(allIDs []gid.GID, existingIDs []gid.GID) []gid.GID {
|
||||
|
||||
150
pkg/trust/trust_center_file_service.go
Normal file
150
pkg/trust/trust_center_file_service.go
Normal file
@@ -0,0 +1,150 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package trust
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/getprobo/probo/pkg/coredata"
|
||||
"github.com/getprobo/probo/pkg/gid"
|
||||
"github.com/getprobo/probo/pkg/page"
|
||||
"github.com/getprobo/probo/pkg/watermarkpdf"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type TrustCenterFileService struct {
|
||||
svc *TenantService
|
||||
}
|
||||
|
||||
func (s *TrustCenterFileService) Get(
|
||||
ctx context.Context,
|
||||
trustCenterFileID gid.GID,
|
||||
) (*coredata.TrustCenterFile, error) {
|
||||
trustCenterFile := &coredata.TrustCenterFile{}
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := trustCenterFile.LoadByID(ctx, conn, s.svc.scope, trustCenterFileID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return trustCenterFile, nil
|
||||
}
|
||||
|
||||
func (s *TrustCenterFileService) ListForOrganizationId(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor[coredata.TrustCenterFileOrderField],
|
||||
) (*page.Page[*coredata.TrustCenterFile, coredata.TrustCenterFileOrderField], error) {
|
||||
var trustCenterFiles coredata.TrustCenterFiles
|
||||
|
||||
err := s.svc.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
err := trustCenterFiles.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load trust center files: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(trustCenterFiles, cursor), nil
|
||||
}
|
||||
|
||||
func (s *TrustCenterFileService) ExportFile(
|
||||
ctx context.Context,
|
||||
trustCenterFileID gid.GID,
|
||||
email string,
|
||||
) ([]byte, error) {
|
||||
pdfData, err := s.exportFileData(ctx, trustCenterFileID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot export trust center file: %w", err)
|
||||
}
|
||||
|
||||
watermarkedPDF, err := watermarkpdf.AddConfidentialWithTimestamp(pdfData, email)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot add watermark to PDF: %w", err)
|
||||
}
|
||||
|
||||
return watermarkedPDF, nil
|
||||
}
|
||||
|
||||
func (s *TrustCenterFileService) ExportFileWithoutWatermark(
|
||||
ctx context.Context,
|
||||
trustCenterFileID gid.GID,
|
||||
) ([]byte, error) {
|
||||
return s.exportFileData(ctx, trustCenterFileID)
|
||||
}
|
||||
|
||||
func (s *TrustCenterFileService) exportFileData(
|
||||
ctx context.Context,
|
||||
trustCenterFileID gid.GID,
|
||||
) ([]byte, error) {
|
||||
var trustCenterFile *coredata.TrustCenterFile
|
||||
var file *coredata.File
|
||||
|
||||
err := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||
trustCenterFile = &coredata.TrustCenterFile{}
|
||||
if err := trustCenterFile.LoadByID(ctx, conn, s.svc.scope, trustCenterFileID); err != nil {
|
||||
return fmt.Errorf("cannot load trust center file: %w", err)
|
||||
}
|
||||
|
||||
file = &coredata.File{}
|
||||
if err := file.LoadByID(ctx, conn, s.svc.scope, trustCenterFile.FileID); err != nil {
|
||||
return fmt.Errorf("cannot load file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result, err := s.svc.s3.GetObject(ctx, &s3.GetObjectInput{
|
||||
Bucket: aws.String(s.svc.bucket),
|
||||
Key: aws.String(file.FileKey),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot download file from S3: %w", err)
|
||||
}
|
||||
defer result.Body.Close()
|
||||
|
||||
fileData, err := io.ReadAll(result.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot read file data: %w", err)
|
||||
}
|
||||
|
||||
return fileData, nil
|
||||
}
|
||||
Reference in New Issue
Block a user