Add baa on vendors

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-12 17:26:27 +02:00
parent e78a7beaa3
commit 3839d2000d
22 changed files with 3954 additions and 144 deletions

View File

@@ -153,6 +153,7 @@ export const vendorNodeQuery = graphql`
...useVendorFormFragment
...VendorComplianceTabFragment
...VendorRiskAssessmentTabFragment
...VendorOverviewTabBusinessAssociateAgreementFragment
}
}
viewer {

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<2b4b64bb6df013e073b34e8249232ab2>>
* @generated SignedSource<<9174011c1abd05e499786607130d0c82>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -19,7 +19,7 @@ export type VendorGraphNodeQuery$data = {
readonly id?: string;
readonly name?: string;
readonly websiteUrl?: string | null | undefined;
readonly " $fragmentSpreads": FragmentRefs<"VendorComplianceTabFragment" | "VendorRiskAssessmentTabFragment" | "useVendorFormFragment">;
readonly " $fragmentSpreads": FragmentRefs<"VendorComplianceTabFragment" | "VendorOverviewTabBusinessAssociateAgreementFragment" | "VendorRiskAssessmentTabFragment" | "useVendorFormFragment">;
};
readonly viewer: {
readonly user: {
@@ -110,38 +110,52 @@ v10 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "cursor",
"name": "validUntil",
"storageKey": null
},
v11 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "endCursor",
"name": "fileUrl",
"storageKey": null
},
v12 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasNextPage",
"name": "cursor",
"storageKey": null
},
v13 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasPreviousPage",
"name": "endCursor",
"storageKey": null
},
v14 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "startCursor",
"name": "hasNextPage",
"storageKey": null
},
v15 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasPreviousPage",
"storageKey": null
},
v16 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "startCursor",
"storageKey": null
},
v17 = {
"kind": "ClientExtension",
"selections": [
{
@@ -153,7 +167,7 @@ v15 = {
}
]
},
v16 = [
v18 = [
"orderBy"
];
return {
@@ -194,6 +208,11 @@ return {
"args": null,
"kind": "FragmentSpread",
"name": "VendorRiskAssessmentTabFragment"
},
{
"args": null,
"kind": "FragmentSpread",
"name": "VendorOverviewTabBusinessAssociateAgreementFragment"
}
],
"type": "Vendor",
@@ -382,13 +401,7 @@ return {
"name": "reportDate",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validUntil",
"storageKey": null
},
(v10/*: any*/),
{
"alias": null,
"args": null,
@@ -396,13 +409,7 @@ return {
"name": "reportName",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileUrl",
"storageKey": null
},
(v11/*: any*/),
{
"alias": null,
"args": null,
@@ -414,7 +421,7 @@ return {
],
"storageKey": null
},
(v10/*: any*/)
(v12/*: any*/)
],
"storageKey": null
},
@@ -426,21 +433,21 @@ return {
"name": "pageInfo",
"plural": false,
"selections": [
(v11/*: any*/),
(v12/*: any*/),
(v13/*: any*/),
(v14/*: any*/)
(v14/*: any*/),
(v15/*: any*/),
(v16/*: any*/)
],
"storageKey": null
},
(v15/*: any*/)
(v17/*: any*/)
],
"storageKey": "complianceReports(first:50)"
},
{
"alias": null,
"args": (v9/*: any*/),
"filters": (v16/*: any*/),
"filters": (v18/*: any*/),
"handle": "connection",
"key": "VendorComplianceTabFragment_complianceReports",
"kind": "LinkedHandle",
@@ -529,7 +536,7 @@ return {
],
"storageKey": null
},
(v10/*: any*/)
(v12/*: any*/)
],
"storageKey": null
},
@@ -541,25 +548,60 @@ return {
"name": "pageInfo",
"plural": false,
"selections": [
(v12/*: any*/),
(v11/*: any*/),
(v14/*: any*/),
(v13/*: any*/),
(v14/*: any*/)
(v15/*: any*/),
(v16/*: any*/)
],
"storageKey": null
},
(v15/*: any*/)
(v17/*: any*/)
],
"storageKey": "riskAssessments(first:50)"
},
{
"alias": null,
"args": (v9/*: any*/),
"filters": (v16/*: any*/),
"filters": (v18/*: any*/),
"handle": "connection",
"key": "VendorRiskAssessmentTabFragment_riskAssessments",
"kind": "LinkedHandle",
"name": "riskAssessments"
},
{
"alias": null,
"args": null,
"concreteType": "VendorBusinessAssociateAgreement",
"kind": "LinkedField",
"name": "businessAssociateAgreement",
"plural": false,
"selections": [
(v3/*: any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileName",
"storageKey": null
},
(v11/*: any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validFrom",
"storageKey": null
},
(v10/*: any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "createdAt",
"storageKey": null
}
],
"storageKey": null
}
],
"type": "Vendor",
@@ -596,16 +638,16 @@ return {
]
},
"params": {
"cacheID": "a57eb59eb17a2ad6d4f72f9174665561",
"cacheID": "95f9f21af1253d08c97dfd7d2f65f2e3",
"id": null,
"metadata": {},
"name": "VendorGraphNodeQuery",
"operationKind": "query",
"text": "query VendorGraphNodeQuery(\n $vendorId: ID!\n $organizationId: ID!\n) {\n node(id: $vendorId) {\n __typename\n ... on Vendor {\n id\n name\n websiteUrl\n ...useVendorFormFragment\n ...VendorComplianceTabFragment\n ...VendorRiskAssessmentTabFragment\n }\n id\n }\n viewer {\n user {\n people(organizationId: $organizationId) {\n id\n }\n id\n }\n id\n }\n}\n\nfragment VendorComplianceTabFragment on Vendor {\n complianceReports(first: 50) {\n edges {\n node {\n id\n ...VendorComplianceTabFragment_report\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n\nfragment VendorComplianceTabFragment_report on VendorComplianceReport {\n id\n reportDate\n validUntil\n reportName\n fileUrl\n fileSize\n}\n\nfragment VendorRiskAssessmentTabFragment on Vendor {\n id\n riskAssessments(first: 50) {\n edges {\n node {\n id\n ...VendorRiskAssessmentTabFragment_assessment\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n hasPreviousPage\n startCursor\n }\n }\n}\n\nfragment VendorRiskAssessmentTabFragment_assessment on VendorRiskAssessment {\n id\n assessedAt\n assessedBy {\n id\n fullName\n }\n expiresAt\n dataSensitivity\n businessImpact\n notes\n}\n\nfragment useVendorFormFragment on Vendor {\n id\n name\n description\n statusPageUrl\n termsOfServiceUrl\n privacyPolicyUrl\n serviceLevelAgreementUrl\n dataProcessingAgreementUrl\n websiteUrl\n legalName\n headquarterAddress\n certifications\n securityPageUrl\n trustPageUrl\n businessOwner {\n id\n }\n securityOwner {\n id\n }\n}\n"
"text": "query VendorGraphNodeQuery(\n $vendorId: ID!\n $organizationId: ID!\n) {\n node(id: $vendorId) {\n __typename\n ... on Vendor {\n id\n name\n websiteUrl\n ...useVendorFormFragment\n ...VendorComplianceTabFragment\n ...VendorRiskAssessmentTabFragment\n ...VendorOverviewTabBusinessAssociateAgreementFragment\n }\n id\n }\n viewer {\n user {\n people(organizationId: $organizationId) {\n id\n }\n id\n }\n id\n }\n}\n\nfragment VendorComplianceTabFragment on Vendor {\n complianceReports(first: 50) {\n edges {\n node {\n id\n ...VendorComplianceTabFragment_report\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n\nfragment VendorComplianceTabFragment_report on VendorComplianceReport {\n id\n reportDate\n validUntil\n reportName\n fileUrl\n fileSize\n}\n\nfragment VendorOverviewTabBusinessAssociateAgreementFragment on Vendor {\n businessAssociateAgreement {\n id\n fileName\n fileUrl\n validFrom\n validUntil\n createdAt\n }\n}\n\nfragment VendorRiskAssessmentTabFragment on Vendor {\n id\n riskAssessments(first: 50) {\n edges {\n node {\n id\n ...VendorRiskAssessmentTabFragment_assessment\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n hasPreviousPage\n startCursor\n }\n }\n}\n\nfragment VendorRiskAssessmentTabFragment_assessment on VendorRiskAssessment {\n id\n assessedAt\n assessedBy {\n id\n fullName\n }\n expiresAt\n dataSensitivity\n businessImpact\n notes\n}\n\nfragment useVendorFormFragment on Vendor {\n id\n name\n description\n statusPageUrl\n termsOfServiceUrl\n privacyPolicyUrl\n serviceLevelAgreementUrl\n dataProcessingAgreementUrl\n websiteUrl\n legalName\n headquarterAddress\n certifications\n securityPageUrl\n trustPageUrl\n businessOwner {\n id\n }\n securityOwner {\n id\n }\n}\n"
}
};
})();
(node as any).hash = "a4d080fd9c239011fa78c812153ed8da";
(node as any).hash = "c80a167ea096212995f1d3261bc2bf57";
export default node;

View File

@@ -0,0 +1,89 @@
import {
Button,
Dialog,
DialogContent,
DialogFooter,
Spinner,
useDialogRef,
} from "@probo/ui";
import { useTranslate } from "@probo/i18n";
import { sprintf } from "@probo/helpers";
import { graphql } from "react-relay";
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
const deleteBusinessAssociateAgreementMutation = graphql`
mutation DeleteBusinessAssociateAgreementDialogMutation(
$input: DeleteVendorBusinessAssociateAgreementInput!
) {
deleteVendorBusinessAssociateAgreement(input: $input) {
deletedVendorId
}
}
`;
type Props = {
children: React.ReactNode;
vendorId: string;
fileName: string;
onSuccess?: () => void;
};
export function DeleteBusinessAssociateAgreementDialog({
children,
vendorId,
fileName,
onSuccess,
}: Props) {
const { __ } = useTranslate();
const ref = useDialogRef();
const [mutate, isDeleting] = useMutationWithToasts(deleteBusinessAssociateAgreementMutation, {
successMessage: __("Business Associate Agreement deleted successfully"),
errorMessage: __("Failed to delete Business Associate Agreement"),
});
const handleDelete = async () => {
await mutate({
variables: {
input: {
vendorId,
},
},
});
onSuccess?.();
ref.current?.close();
};
return (
<Dialog
ref={ref}
trigger={children}
title={__("Delete Business Associate Agreement")}
className="max-w-md"
>
<DialogContent padded>
<p className="text-txt-secondary">
{sprintf(
__("Are you sure you want to delete the Business Associate Agreement \"%s\"?"),
fileName
)}
</p>
<p className="text-txt-secondary mt-2">
{__("This action cannot be undone.")}
</p>
</DialogContent>
<DialogFooter>
<Button
variant="danger"
onClick={handleDelete}
disabled={isDeleting}
icon={isDeleting ? Spinner : undefined}
>
{__("Delete")}
</Button>
</DialogFooter>
</Dialog>
);
}

View File

@@ -0,0 +1,135 @@
import {
Button,
Dialog,
DialogContent,
DialogFooter,
Field,
Input,
Spinner,
useDialogRef,
} from "@probo/ui";
import { useTranslate } from "@probo/i18n";
import { graphql } from "react-relay";
import { z } from "zod";
import { useFormWithSchema } from "/hooks/useFormWithSchema";
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
const updateBusinessAssociateAgreementMutation = graphql`
mutation EditBusinessAssociateAgreementDialogMutation(
$input: UpdateVendorBusinessAssociateAgreementInput!
) {
updateVendorBusinessAssociateAgreement(input: $input) {
vendorBusinessAssociateAgreement {
id
fileUrl
validFrom
validUntil
createdAt
}
}
}
`;
const schema = z.object({
validFrom: z.string().optional(),
validUntil: z.string().optional(),
});
type Props = {
children: React.ReactNode;
vendorId: string;
agreement: {
validFrom?: string | null;
validUntil?: string | null;
};
onSuccess?: () => void;
};
export function EditBusinessAssociateAgreementDialog({
children,
vendorId,
agreement,
onSuccess,
}: Props) {
const { __ } = useTranslate();
const ref = useDialogRef();
const formatDateForForm = (datetime?: string | null) => {
if (!datetime) return "";
return datetime.split("T")[0];
};
const {
register,
handleSubmit,
formState: { isSubmitting },
reset,
} = useFormWithSchema(schema, {
defaultValues: {
validFrom: formatDateForForm(agreement.validFrom),
validUntil: formatDateForForm(agreement.validUntil),
},
});
const [mutate] = useMutationWithToasts(updateBusinessAssociateAgreementMutation, {
successMessage: __("Business Associate Agreement updated successfully"),
errorMessage: __("Failed to update Business Associate Agreement"),
});
const onSubmit = handleSubmit(async (data) => {
const formatDatetime = (dateString?: string) => {
if (!dateString) return null;
return `${dateString}T00:00:00Z`;
};
await mutate({
variables: {
input: {
vendorId,
validFrom: formatDatetime(data.validFrom),
validUntil: formatDatetime(data.validUntil),
},
},
});
onSuccess?.();
ref.current?.close();
});
const handleClose = () => {
reset();
};
return (
<Dialog
title={__("Edit Business Associate Agreement")}
ref={ref}
trigger={children}
className="max-w-lg"
onClose={handleClose}
>
<form onSubmit={onSubmit}>
<DialogContent padded className="space-y-4">
<div className="grid grid-cols-2 gap-4">
<Field label={__("Valid from")}>
<Input {...register("validFrom")} type="date" />
</Field>
<Field label={__("Valid until")}>
<Input {...register("validUntil")} type="date" />
</Field>
</div>
</DialogContent>
<DialogFooter>
<Button
type="submit"
disabled={isSubmitting}
icon={isSubmitting ? Spinner : undefined}
>
{__("Update")}
</Button>
</DialogFooter>
</form>
</Dialog>
);
}

View File

@@ -0,0 +1,178 @@
import {
Button,
Dialog,
DialogContent,
DialogFooter,
Dropzone,
Field,
Spinner,
Input,
useDialogRef,
} from "@probo/ui";
import { useTranslate } from "@probo/i18n";
import { graphql } from "react-relay";
import { z } from "zod";
import { useFormWithSchema } from "/hooks/useFormWithSchema";
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
import { useState } from "react";
const uploadBusinessAssociateAgreementMutation = graphql`
mutation UploadBusinessAssociateAgreementDialogMutation(
$input: UploadVendorBusinessAssociateAgreementInput!
) {
uploadVendorBusinessAssociateAgreement(input: $input) {
vendorBusinessAssociateAgreement {
id
fileName
fileUrl
validFrom
validUntil
createdAt
}
}
}
`;
const schema = z.object({
fileName: z.string().min(1, "File name is required"),
validFrom: z.string().optional(),
validUntil: z.string().optional(),
});
type Props = {
children: React.ReactNode;
vendorId: string;
onSuccess?: () => void;
};
export function UploadBusinessAssociateAgreementDialog({
children,
vendorId,
onSuccess,
}: Props) {
const { __ } = useTranslate();
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
const ref = useDialogRef();
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
reset,
setValue,
} = useFormWithSchema(schema, {
defaultValues: {
fileName: "",
validFrom: "",
validUntil: "",
},
});
const [mutate] = useMutationWithToasts(uploadBusinessAssociateAgreementMutation, {
successMessage: __("Business Associate Agreement uploaded successfully"),
errorMessage: __("Failed to upload Business Associate Agreement"),
});
const handleDrop = (files: File[]) => {
if (files.length > 0) {
const file = files[0];
setUploadedFile(file);
setValue("fileName", file.name);
}
};
const onSubmit = handleSubmit(async (data) => {
if (!uploadedFile) {
return;
}
const formatDatetime = (dateString?: string) => {
if (!dateString) return null;
return `${dateString}T00:00:00Z`;
};
await mutate({
variables: {
input: {
vendorId,
fileName: data.fileName,
validFrom: formatDatetime(data.validFrom),
validUntil: formatDatetime(data.validUntil),
file: null,
},
},
uploadables: {
"input.file": uploadedFile,
},
});
reset();
setUploadedFile(null);
onSuccess?.();
ref.current?.close();
});
const handleClose = () => {
reset();
setUploadedFile(null);
};
return (
<Dialog
title={__("Upload Business Associate Agreement")}
ref={ref}
trigger={children}
className="max-w-lg"
onClose={handleClose}
>
<form onSubmit={onSubmit}>
<DialogContent padded className="space-y-4">
<Dropzone
description={__("Only PDF files up to 10MB are allowed")}
isUploading={isSubmitting}
onDrop={handleDrop}
accept={{
"application/pdf": [".pdf"],
}}
maxSize={10}
/>
{uploadedFile && (
<div className="p-3 bg-tertiary-subtle rounded-lg">
<p className="text-sm font-medium">{__("Selected file")}:</p>
<p className="text-sm text-txt-secondary">{uploadedFile.name}</p>
</div>
)}
<Field
{...register("fileName")}
label={__("File name")}
type="text"
required
error={errors.fileName?.message}
placeholder={__("Business Associate Agreement")}
/>
<div className="grid grid-cols-2 gap-4">
<Field label={__("Valid from")}>
<Input {...register("validFrom")} type="date" />
</Field>
<Field label={__("Valid until")}>
<Input {...register("validUntil")} type="date" />
</Field>
</div>
</DialogContent>
<DialogFooter>
<Button
type="submit"
disabled={isSubmitting || !uploadedFile}
icon={isSubmitting ? Spinner : undefined}
>
{__("Upload")}
</Button>
</DialogFooter>
</form>
</Dialog>
);
}

View File

@@ -0,0 +1,92 @@
/**
* @generated SignedSource<<26343418dbdd4baf63f2846470e2d3ab>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type DeleteVendorBusinessAssociateAgreementInput = {
vendorId: string;
};
export type DeleteBusinessAssociateAgreementDialogMutation$variables = {
input: DeleteVendorBusinessAssociateAgreementInput;
};
export type DeleteBusinessAssociateAgreementDialogMutation$data = {
readonly deleteVendorBusinessAssociateAgreement: {
readonly deletedVendorId: string;
};
};
export type DeleteBusinessAssociateAgreementDialogMutation = {
response: DeleteBusinessAssociateAgreementDialogMutation$data;
variables: DeleteBusinessAssociateAgreementDialogMutation$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
v1 = [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "DeleteVendorBusinessAssociateAgreementPayload",
"kind": "LinkedField",
"name": "deleteVendorBusinessAssociateAgreement",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "deletedVendorId",
"storageKey": null
}
],
"storageKey": null
}
];
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "DeleteBusinessAssociateAgreementDialogMutation",
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "DeleteBusinessAssociateAgreementDialogMutation",
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "c8aa903ee410ee9e591c82f7f75e044c",
"id": null,
"metadata": {},
"name": "DeleteBusinessAssociateAgreementDialogMutation",
"operationKind": "mutation",
"text": "mutation DeleteBusinessAssociateAgreementDialogMutation(\n $input: DeleteVendorBusinessAssociateAgreementInput!\n) {\n deleteVendorBusinessAssociateAgreement(input: $input) {\n deletedVendorId\n }\n}\n"
}
};
})();
(node as any).hash = "39106d060e4e1da4eaa78a8205fe7cf8";
export default node;

View File

@@ -0,0 +1,139 @@
/**
* @generated SignedSource<<8d5961820ccfa705a899582a9a8ca953>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type UpdateVendorBusinessAssociateAgreementInput = {
validFrom?: any | null | undefined;
validUntil?: any | null | undefined;
vendorId: string;
};
export type EditBusinessAssociateAgreementDialogMutation$variables = {
input: UpdateVendorBusinessAssociateAgreementInput;
};
export type EditBusinessAssociateAgreementDialogMutation$data = {
readonly updateVendorBusinessAssociateAgreement: {
readonly vendorBusinessAssociateAgreement: {
readonly createdAt: any;
readonly fileUrl: string;
readonly id: string;
readonly validFrom: any | null | undefined;
readonly validUntil: any | null | undefined;
};
};
};
export type EditBusinessAssociateAgreementDialogMutation = {
response: EditBusinessAssociateAgreementDialogMutation$data;
variables: EditBusinessAssociateAgreementDialogMutation$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
v1 = [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "UpdateVendorBusinessAssociateAgreementPayload",
"kind": "LinkedField",
"name": "updateVendorBusinessAssociateAgreement",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "VendorBusinessAssociateAgreement",
"kind": "LinkedField",
"name": "vendorBusinessAssociateAgreement",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileUrl",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validFrom",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validUntil",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "createdAt",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
];
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "EditBusinessAssociateAgreementDialogMutation",
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "EditBusinessAssociateAgreementDialogMutation",
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "2e50e54d255a9bea661d82188913ed9c",
"id": null,
"metadata": {},
"name": "EditBusinessAssociateAgreementDialogMutation",
"operationKind": "mutation",
"text": "mutation EditBusinessAssociateAgreementDialogMutation(\n $input: UpdateVendorBusinessAssociateAgreementInput!\n) {\n updateVendorBusinessAssociateAgreement(input: $input) {\n vendorBusinessAssociateAgreement {\n id\n fileUrl\n validFrom\n validUntil\n createdAt\n }\n }\n}\n"
}
};
})();
(node as any).hash = "10b614dbbdee430ed650b94051be4bbc";
export default node;

View File

@@ -0,0 +1,149 @@
/**
* @generated SignedSource<<e815dea06fd48ec50789f2fedfd1beb5>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type UploadVendorBusinessAssociateAgreementInput = {
file: any;
fileName: string;
validFrom?: any | null | undefined;
validUntil?: any | null | undefined;
vendorId: string;
};
export type UploadBusinessAssociateAgreementDialogMutation$variables = {
input: UploadVendorBusinessAssociateAgreementInput;
};
export type UploadBusinessAssociateAgreementDialogMutation$data = {
readonly uploadVendorBusinessAssociateAgreement: {
readonly vendorBusinessAssociateAgreement: {
readonly createdAt: any;
readonly fileName: string;
readonly fileUrl: string;
readonly id: string;
readonly validFrom: any | null | undefined;
readonly validUntil: any | null | undefined;
};
};
};
export type UploadBusinessAssociateAgreementDialogMutation = {
response: UploadBusinessAssociateAgreementDialogMutation$data;
variables: UploadBusinessAssociateAgreementDialogMutation$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
}
],
v1 = [
{
"alias": null,
"args": [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
"concreteType": "UploadVendorBusinessAssociateAgreementPayload",
"kind": "LinkedField",
"name": "uploadVendorBusinessAssociateAgreement",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "VendorBusinessAssociateAgreement",
"kind": "LinkedField",
"name": "vendorBusinessAssociateAgreement",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileName",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileUrl",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validFrom",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validUntil",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "createdAt",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
];
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "UploadBusinessAssociateAgreementDialogMutation",
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "UploadBusinessAssociateAgreementDialogMutation",
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "bb7a0f67773da5b3916d08fdeaa2dc8d",
"id": null,
"metadata": {},
"name": "UploadBusinessAssociateAgreementDialogMutation",
"operationKind": "mutation",
"text": "mutation UploadBusinessAssociateAgreementDialogMutation(\n $input: UploadVendorBusinessAssociateAgreementInput!\n) {\n uploadVendorBusinessAssociateAgreement(input: $input) {\n vendorBusinessAssociateAgreement {\n id\n fileName\n fileUrl\n validFrom\n validUntil\n createdAt\n }\n }\n}\n"
}
};
})();
(node as any).hash = "e3fce209e1a4006a31996903e4c6cbae";
export default node;

View File

@@ -1,19 +1,44 @@
import { useTranslate } from "@probo/i18n";
import { useVendorForm } from "/hooks/forms/useVendorForm";
import type { useVendorFormFragment$key } from "/hooks/forms/__generated__/useVendorFormFragment.graphql";
import { useOutletContext } from "react-router";
import { Button, Card, Field, Input } from "@probo/ui";
import { Button, Card, Field, Input, IconPlusLarge, IconTrashCan, IconPencil } from "@probo/ui";
import { PeopleSelectField } from "/components/form/PeopleSelectField";
import { useOrganizationId } from "/hooks/useOrganizationId";
import { useMemo } from "react";
import { usePageTitle } from "@probo/hooks";
import { downloadFile } from "@probo/helpers";
import { useFragment, graphql } from "react-relay";
import { UploadBusinessAssociateAgreementDialog } from "../dialogs/UploadBusinessAssociateAgreementDialog";
import { DeleteBusinessAssociateAgreementDialog } from "../dialogs/DeleteBusinessAssociateAgreementDialog";
import { EditBusinessAssociateAgreementDialog } from "../dialogs/EditBusinessAssociateAgreementDialog";
import type { useVendorFormFragment$key } from "/hooks/forms/__generated__/useVendorFormFragment.graphql";
import type { VendorOverviewTabBusinessAssociateAgreementFragment$key } from "./__generated__/VendorOverviewTabBusinessAssociateAgreementFragment.graphql";
const vendorBusinessAssociateAgreementFragment = graphql`
fragment VendorOverviewTabBusinessAssociateAgreementFragment on Vendor {
businessAssociateAgreement {
id
fileName
fileUrl
validFrom
validUntil
createdAt
}
}
`;
export default function VendorOverviewTab() {
const { vendor } = useOutletContext<{
vendor: useVendorFormFragment$key & { name: string };
vendor: useVendorFormFragment$key & { id: string; name: string };
}>();
const { vendor: vendorForBAA } = useOutletContext<{
vendor: VendorOverviewTabBusinessAssociateAgreementFragment$key;
}>();
const { __ } = useTranslate();
const organizationId = useOrganizationId();
const {
control,
register,
@@ -21,6 +46,12 @@ export default function VendorOverviewTab() {
formState: { errors, isSubmitting },
} = useVendorForm(vendor);
const vendorWithBAA = useFragment<VendorOverviewTabBusinessAssociateAgreementFragment$key>(
vendorBusinessAssociateAgreementFragment,
vendorForBAA
);
const businessAssociateAgreement = vendorWithBAA.businessAssociateAgreement;
const urls = useMemo(
() =>
[
@@ -132,6 +163,73 @@ export default function VendorOverviewTab() {
</Card>
</div>
{/* Data agreements */}
<div className="space-y-4">
<h2 className="text-base font-medium">{__("Data agreements")}</h2>
<Card className="space-y-4" padded>
<div className="flex items-center justify-between p-4 border border-border-low rounded-lg">
<div className="flex-1">
<h3 className="font-medium text-txt-primary">
{__("Business Associate Agreement")}
</h3>
<p className="text-sm text-txt-secondary mt-1">
{businessAssociateAgreement ? businessAssociateAgreement.fileName : __("No business associate agreement available")}
</p>
{(businessAssociateAgreement?.validFrom || businessAssociateAgreement?.validUntil) && (
<p className="text-xs text-txt-secondary mt-1">
{__("Valid")}
{businessAssociateAgreement.validFrom &&
` ${__("from")} ${new Date(businessAssociateAgreement.validFrom).toLocaleDateString()}`
}
{businessAssociateAgreement.validUntil &&
` ${__("until")} ${new Date(businessAssociateAgreement.validUntil).toLocaleDateString()}`
}
</p>
)}
</div>
<div className="flex items-center gap-2">
{businessAssociateAgreement ? (
<>
<Button
type="button"
variant="secondary"
onClick={() => downloadFile(businessAssociateAgreement.fileUrl, businessAssociateAgreement.fileName)}
>
{__("Download PDF")}
</Button>
<EditBusinessAssociateAgreementDialog
vendorId={vendor.id}
agreement={{
validFrom: businessAssociateAgreement.validFrom,
validUntil: businessAssociateAgreement.validUntil,
}}
onSuccess={() => window.location.reload()}
>
<Button variant="quaternary" icon={IconPencil} />
</EditBusinessAssociateAgreementDialog>
<DeleteBusinessAssociateAgreementDialog
vendorId={vendor.id}
fileName={businessAssociateAgreement.fileName}
onSuccess={() => window.location.reload()}
>
<Button variant="quaternary" icon={IconTrashCan} />
</DeleteBusinessAssociateAgreementDialog>
</>
) : (
<UploadBusinessAssociateAgreementDialog
vendorId={vendor.id}
onSuccess={() => window.location.reload()}
>
<Button variant="secondary" icon={IconPlusLarge}>
{__("Upload")}
</Button>
</UploadBusinessAssociateAgreementDialog>
)}
</div>
</div>
</Card>
</div>
{/* Submit */}
<div className="flex justify-end">
<Button type="submit" disabled={isSubmitting}>

View File

@@ -0,0 +1,95 @@
/**
* @generated SignedSource<<ff109a0e0313323fe9b81a4c22bde7ff>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ReaderFragment } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type VendorOverviewTabBusinessAssociateAgreementFragment$data = {
readonly businessAssociateAgreement: {
readonly createdAt: any;
readonly fileName: string;
readonly fileUrl: string;
readonly id: string;
readonly validFrom: any | null | undefined;
readonly validUntil: any | null | undefined;
} | null | undefined;
readonly " $fragmentType": "VendorOverviewTabBusinessAssociateAgreementFragment";
};
export type VendorOverviewTabBusinessAssociateAgreementFragment$key = {
readonly " $data"?: VendorOverviewTabBusinessAssociateAgreementFragment$data;
readonly " $fragmentSpreads": FragmentRefs<"VendorOverviewTabBusinessAssociateAgreementFragment">;
};
const node: ReaderFragment = {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "VendorOverviewTabBusinessAssociateAgreementFragment",
"selections": [
{
"alias": null,
"args": null,
"concreteType": "VendorBusinessAssociateAgreement",
"kind": "LinkedField",
"name": "businessAssociateAgreement",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileName",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "fileUrl",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validFrom",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "validUntil",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "createdAt",
"storageKey": null
}
],
"storageKey": null
}
],
"type": "Vendor",
"abstractKey": null
};
(node as any).hash = "5f45b3392cbce2a58d3d68932ec68f88";
export default node;

View File

@@ -39,4 +39,6 @@ const (
ReportEntityType
TrustCenterEntityType
TrustCenterAccessEntityType
VendorBusinessAssociateAgreementEntityType
FileEntityType
)

176
pkg/coredata/file.go Normal file
View File

@@ -0,0 +1,176 @@
// 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/jackc/pgx/v5"
"go.gearno.de/kit/pg"
)
type (
File struct {
ID gid.GID `db:"id"`
BucketName string `db:"bucket_name"`
MimeType string `db:"mime_type"`
FileName string `db:"file_name"`
FileKey string `db:"file_key"`
FileSize int `db:"file_size"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
DeletedAt *time.Time `db:"deleted_at"`
}
Files []*File
)
func (f *File) LoadByID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
fileID gid.GID,
) error {
q := `
SELECT
id,
bucket_name,
mime_type,
file_name,
file_key,
file_size,
created_at,
updated_at,
deleted_at
FROM
files
WHERE
%s
AND id = @file_id
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"file_id": fileID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query file: %w", err)
}
defer rows.Close()
file, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[File])
if err != nil {
return fmt.Errorf("cannot collect file: %w", err)
}
*f = file
return nil
}
func (f File) Insert(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
INSERT INTO
files (
id,
tenant_id,
bucket_name,
mime_type,
file_name,
file_key,
file_size,
created_at,
updated_at,
deleted_at
)
VALUES (
@file_id,
@tenant_id,
@bucket_name,
@mime_type,
@file_name,
@file_key,
@file_size,
@created_at,
@updated_at,
@deleted_at
)
`
args := pgx.StrictNamedArgs{
"file_id": f.ID,
"tenant_id": scope.GetTenantID(),
"bucket_name": f.BucketName,
"mime_type": f.MimeType,
"file_name": f.FileName,
"file_key": f.FileKey,
"file_size": f.FileSize,
"created_at": f.CreatedAt,
"updated_at": f.UpdatedAt,
"deleted_at": f.DeletedAt,
}
_, err := conn.Exec(ctx, q, args)
return err
}
func (f File) Delete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
DELETE FROM files WHERE %s AND id = @file_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"file_id": f.ID}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
return err
}
func (f File) SoftDelete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
UPDATE files SET deleted_at = @deleted_at, updated_at = @updated_at WHERE %s AND id = @file_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"file_id": f.ID,
"updated_at": time.Now(),
"deleted_at": time.Now(),
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
return err
}

View File

@@ -0,0 +1,42 @@
CREATE TABLE files (
id TEXT PRIMARY KEY,
tenant_id TEXT NOT NULL,
bucket_name TEXT NOT NULL,
mime_type TEXT NOT NULL,
file_name TEXT NOT NULL,
file_key UUID NOT NULL UNIQUE,
file_size INTEGER NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
deleted_at TIMESTAMP WITH TIME ZONE
);
CREATE TABLE vendor_business_associate_agreements (
id TEXT PRIMARY KEY,
organization_id TEXT NOT NULL,
tenant_id TEXT NOT NULL,
vendor_id TEXT NOT NULL,
valid_from DATE,
valid_until DATE,
file_id TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL,
CONSTRAINT vendor_business_associate_agreements_organization_vendor_unique
UNIQUE (organization_id, vendor_id),
CONSTRAINT vendor_business_associate_agreements_file_id_unique
UNIQUE (file_id),
CONSTRAINT vendor_business_associate_agreements_organization_id_fkey
FOREIGN KEY (organization_id)
REFERENCES organizations(id)
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT vendor_business_associate_agreements_file_id_fkey
FOREIGN KEY (file_id)
REFERENCES files(id)
ON UPDATE CASCADE
ON DELETE CASCADE
);

View File

@@ -0,0 +1,277 @@
// 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 (
VendorBusinessAssociateAgreement struct {
ID gid.GID `db:"id"`
OrganizationID gid.GID `db:"organization_id"`
VendorID gid.GID `db:"vendor_id"`
ValidFrom *time.Time `db:"valid_from"`
ValidUntil *time.Time `db:"valid_until"`
FileID gid.GID `db:"file_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
VendorBusinessAssociateAgreements []*VendorBusinessAssociateAgreement
)
func (v VendorBusinessAssociateAgreement) CursorKey(orderBy VendorBusinessAssociateAgreementOrderField) page.CursorKey {
switch orderBy {
case VendorBusinessAssociateAgreementOrderFieldValidFrom:
return page.NewCursorKey(v.ID, v.ValidFrom)
case VendorBusinessAssociateAgreementOrderFieldCreatedAt:
return page.NewCursorKey(v.ID, v.CreatedAt)
}
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
}
func (vbaa *VendorBusinessAssociateAgreement) LoadByVendorID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
vendorID gid.GID,
) error {
q := `
SELECT
id,
organization_id,
vendor_id,
valid_from,
valid_until,
file_id,
created_at,
updated_at
FROM
vendor_business_associate_agreements
WHERE
%s
AND vendor_id = @vendor_id
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"vendor_id": vendorID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query vendor business associate agreement: %w", err)
}
vendorBusinessAssociateAgreement, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[VendorBusinessAssociateAgreement])
if err != nil {
return fmt.Errorf("cannot collect vendor business associate agreement: %w", err)
}
*vbaa = vendorBusinessAssociateAgreement
return nil
}
func (vbaa *VendorBusinessAssociateAgreement) LoadByID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
vendorBusinessAssociateAgreementID gid.GID,
) error {
q := `
SELECT
id,
organization_id,
vendor_id,
valid_from,
valid_until,
file_id,
created_at,
updated_at
FROM
vendor_business_associate_agreements
WHERE
%s
AND id = @id
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"id": vendorBusinessAssociateAgreementID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query vendor business associate agreement: %w", err)
}
vendorBusinessAssociateAgreement, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[VendorBusinessAssociateAgreement])
if err != nil {
return fmt.Errorf("cannot collect vendor business associate agreement: %w", err)
}
*vbaa = vendorBusinessAssociateAgreement
return nil
}
func (vbaa *VendorBusinessAssociateAgreement) Update(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
UPDATE
vendor_business_associate_agreements
SET
valid_from = @valid_from,
valid_until = @valid_until,
file_id = @file_id,
updated_at = @updated_at
WHERE
%s
AND id = @id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"id": vbaa.ID,
"valid_from": vbaa.ValidFrom,
"valid_until": vbaa.ValidUntil,
"file_id": vbaa.FileID,
"updated_at": vbaa.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot update vendor business associate agreement: %w", err)
}
return nil
}
func (vbaa *VendorBusinessAssociateAgreement) Upsert(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
INSERT INTO
vendor_business_associate_agreements (
id,
tenant_id,
organization_id,
vendor_id,
valid_from,
valid_until,
file_id,
created_at,
updated_at
)
VALUES (
@id,
@tenant_id,
@organization_id,
@vendor_id,
@valid_from,
@valid_until,
@file_id,
@created_at,
@updated_at
)
ON CONFLICT (organization_id, vendor_id) DO UPDATE SET
id = EXCLUDED.id,
valid_from = EXCLUDED.valid_from,
valid_until = EXCLUDED.valid_until,
file_id = EXCLUDED.file_id,
updated_at = EXCLUDED.updated_at
`
args := pgx.StrictNamedArgs{
"id": vbaa.ID,
"tenant_id": scope.GetTenantID(),
"vendor_id": vbaa.VendorID,
"organization_id": vbaa.OrganizationID,
"valid_from": vbaa.ValidFrom,
"valid_until": vbaa.ValidUntil,
"file_id": vbaa.FileID,
"created_at": vbaa.CreatedAt,
"updated_at": vbaa.UpdatedAt,
}
_, err := conn.Exec(ctx, q, args)
return err
}
func (vbaa *VendorBusinessAssociateAgreement) Delete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
DELETE
FROM
vendor_business_associate_agreements
WHERE
%s
AND id = @id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"id": vbaa.ID}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
return err
}
func (vbaa *VendorBusinessAssociateAgreement) DeleteByVendorID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
vendorID gid.GID,
) error {
q := `
DELETE
FROM
vendor_business_associate_agreements
WHERE
%s
AND vendor_id = @vendor_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"vendor_id": vendorID}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, q, args)
return err
}

View File

@@ -0,0 +1,41 @@
// 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 (
VendorBusinessAssociateAgreementOrderField string
)
const (
VendorBusinessAssociateAgreementOrderFieldValidFrom VendorBusinessAssociateAgreementOrderField = "VALID_FROM"
VendorBusinessAssociateAgreementOrderFieldCreatedAt VendorBusinessAssociateAgreementOrderField = "CREATED_AT"
)
func (p VendorBusinessAssociateAgreementOrderField) Column() string {
return string(p)
}
func (p VendorBusinessAssociateAgreementOrderField) String() string {
return string(p)
}
func (p VendorBusinessAssociateAgreementOrderField) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
func (p *VendorBusinessAssociateAgreementOrderField) UnmarshalText(text []byte) error {
*p = VendorBusinessAssociateAgreementOrderField(text)
return nil
}

View File

@@ -51,33 +51,34 @@ type (
}
TenantService struct {
pg *pg.Client
s3 *s3.Client
bucket string
encryptionKey cipher.EncryptionKey
scope coredata.Scoper
hostname string
tokenSecret string
trustConfig TrustConfig
agent *agents.Agent
Frameworks *FrameworkService
Measures *MeasureService
Tasks *TaskService
Evidences *EvidenceService
Organizations *OrganizationService
Vendors *VendorService
Peoples *PeopleService
Documents *DocumentService
Controls *ControlService
Risks *RiskService
VendorComplianceReports *VendorComplianceReportService
Connectors *ConnectorService
Assets *AssetService
Data *DatumService
Audits *AuditService
Reports *ReportService
TrustCenters *TrustCenterService
TrustCenterAccesses *TrustCenterAccessService
pg *pg.Client
s3 *s3.Client
bucket string
encryptionKey cipher.EncryptionKey
scope coredata.Scoper
hostname string
tokenSecret string
trustConfig TrustConfig
agent *agents.Agent
Frameworks *FrameworkService
Measures *MeasureService
Tasks *TaskService
Evidences *EvidenceService
Organizations *OrganizationService
Vendors *VendorService
Peoples *PeopleService
Documents *DocumentService
Controls *ControlService
Risks *RiskService
VendorComplianceReports *VendorComplianceReportService
VendorBusinessAssociateAgreements *VendorBusinessAssociateAgreementService
Connectors *ConnectorService
Assets *AssetService
Data *DatumService
Audits *AuditService
Reports *ReportService
TrustCenters *TrustCenterService
TrustCenterAccesses *TrustCenterAccessService
}
)
@@ -157,6 +158,7 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
tenantService.Controls = &ControlService{svc: tenantService}
tenantService.Risks = &RiskService{svc: tenantService}
tenantService.VendorComplianceReports = &VendorComplianceReportService{svc: tenantService}
tenantService.VendorBusinessAssociateAgreements = &VendorBusinessAssociateAgreementService{svc: tenantService}
tenantService.Connectors = &ConnectorService{svc: tenantService}
tenantService.Assets = &AssetService{svc: tenantService}
tenantService.Data = &DatumService{svc: tenantService}

View File

@@ -0,0 +1,349 @@
// 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 (
"context"
"fmt"
"io"
"mime"
"net/url"
"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/gid"
"go.gearno.de/crypto/uuid"
"go.gearno.de/kit/pg"
)
type (
VendorBusinessAssociateAgreementService struct {
svc *TenantService
}
VendorBusinessAssociateAgreementCreateRequest struct {
File io.Reader
ValidFrom *time.Time
ValidUntil *time.Time
FileName string
}
VendorBusinessAssociateAgreementUpdateRequest struct {
ValidFrom **time.Time
ValidUntil **time.Time
}
)
func (s VendorBusinessAssociateAgreementService) GetByVendorID(
ctx context.Context,
vendorID gid.GID,
) (*coredata.VendorBusinessAssociateAgreement, *coredata.File, error) {
var vendorBusinessAssociateAgreement *coredata.VendorBusinessAssociateAgreement
var file *coredata.File
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
vendorBusinessAssociateAgreement = &coredata.VendorBusinessAssociateAgreement{}
if err := vendorBusinessAssociateAgreement.LoadByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
return fmt.Errorf("cannot load vendor business associate agreement: %w", err)
}
file = &coredata.File{}
if err := file.LoadByID(ctx, conn, s.svc.scope, vendorBusinessAssociateAgreement.FileID); err != nil {
return fmt.Errorf("cannot load file: %w", err)
}
return nil
},
)
if err != nil {
return nil, nil, err
}
return vendorBusinessAssociateAgreement, file, nil
}
func (s VendorBusinessAssociateAgreementService) Upload(
ctx context.Context,
vendorID gid.GID,
req *VendorBusinessAssociateAgreementCreateRequest,
) (*coredata.VendorBusinessAssociateAgreement, *coredata.File, error) {
objectKey, err := uuid.NewV7()
if err != nil {
return nil, nil, fmt.Errorf("cannot generate object key: %w", err)
}
mimeType := mime.TypeByExtension(filepath.Ext(req.FileName))
_, err = s.svc.s3.PutObject(ctx, &s3.PutObjectInput{
Bucket: &s.svc.bucket,
Key: aws.String(objectKey.String()),
Body: req.File,
ContentType: &mimeType,
})
if err != nil {
return nil, nil, fmt.Errorf("cannot upload file to S3: %w", err)
}
headOutput, err := s.svc.s3.HeadObject(ctx, &s3.HeadObjectInput{
Bucket: aws.String(s.svc.bucket),
Key: aws.String(objectKey.String()),
})
if err != nil {
return nil, nil, fmt.Errorf("cannot get object metadata: %w", err)
}
now := time.Now()
fileID := gid.New(s.svc.scope.GetTenantID(), coredata.FileEntityType)
vendorBusinessAssociateAgreementID := gid.New(s.svc.scope.GetTenantID(), coredata.VendorBusinessAssociateAgreementEntityType)
var vendorBusinessAssociateAgreement *coredata.VendorBusinessAssociateAgreement
var file *coredata.File
err = s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
vendor := &coredata.Vendor{}
if err := vendor.LoadByID(ctx, conn, s.svc.scope, vendorID); err != nil {
return fmt.Errorf("cannot load vendor: %w", err)
}
file = &coredata.File{
ID: fileID,
BucketName: s.svc.bucket,
MimeType: mimeType,
FileName: req.FileName,
FileKey: objectKey.String(),
FileSize: int(*headOutput.ContentLength),
CreatedAt: now,
UpdatedAt: now,
}
vendorBusinessAssociateAgreement = &coredata.VendorBusinessAssociateAgreement{
ID: vendorBusinessAssociateAgreementID,
OrganizationID: vendor.OrganizationID,
VendorID: vendorID,
ValidFrom: req.ValidFrom,
ValidUntil: req.ValidUntil,
FileID: fileID,
CreatedAt: now,
UpdatedAt: now,
}
if err := file.Insert(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot insert file: %w", err)
}
if err := vendorBusinessAssociateAgreement.Upsert(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot insert vendor business associate agreement: %w", err)
}
return nil
},
)
if err != nil {
return nil, nil, err
}
return vendorBusinessAssociateAgreement, file, nil
}
func (s VendorBusinessAssociateAgreementService) Get(
ctx context.Context,
vendorBusinessAssociateAgreementID gid.GID,
) (*coredata.VendorBusinessAssociateAgreement, *coredata.File, error) {
var vendorBusinessAssociateAgreement *coredata.VendorBusinessAssociateAgreement
var file *coredata.File
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
vendorBusinessAssociateAgreement = &coredata.VendorBusinessAssociateAgreement{}
if err := vendorBusinessAssociateAgreement.LoadByID(ctx, conn, s.svc.scope, vendorBusinessAssociateAgreementID); err != nil {
return fmt.Errorf("cannot load vendor business associate agreement: %w", err)
}
file = &coredata.File{}
if err := file.LoadByID(ctx, conn, s.svc.scope, vendorBusinessAssociateAgreement.FileID); err != nil {
return fmt.Errorf("cannot load file: %w", err)
}
return nil
},
)
if err != nil {
return nil, nil, fmt.Errorf("cannot load vendor business associate agreement: %w", err)
}
return vendorBusinessAssociateAgreement, file, nil
}
func (s VendorBusinessAssociateAgreementService) GenerateFileURL(
ctx context.Context,
vendorBusinessAssociateAgreementID gid.GID,
expiresIn time.Duration,
) (string, error) {
var file *coredata.File
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
vendorBusinessAssociateAgreement := &coredata.VendorBusinessAssociateAgreement{}
if err := vendorBusinessAssociateAgreement.LoadByID(ctx, conn, s.svc.scope, vendorBusinessAssociateAgreementID); err != nil {
return fmt.Errorf("cannot load vendor business associate agreement: %w", err)
}
file = &coredata.File{}
if err := file.LoadByID(ctx, conn, s.svc.scope, vendorBusinessAssociateAgreement.FileID); err != nil {
return fmt.Errorf("cannot load file: %w", err)
}
return nil
},
)
if err != nil {
return "", err
}
presignClient := s3.NewPresignClient(s.svc.s3)
encodedFilename := url.QueryEscape(file.FileName)
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
encodedFilename, encodedFilename)
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(s.svc.bucket),
Key: aws.String(file.FileKey),
ResponseCacheControl: aws.String("max-age=3600, public"),
ResponseContentDisposition: aws.String(contentDisposition),
}, func(opts *s3.PresignOptions) {
opts.Expires = expiresIn
})
if err != nil {
return "", fmt.Errorf("cannot presign GetObject request: %w", err)
}
return presignedReq.URL, nil
}
func (s VendorBusinessAssociateAgreementService) Update(
ctx context.Context,
vendorID gid.GID,
req *VendorBusinessAssociateAgreementUpdateRequest,
) (*coredata.VendorBusinessAssociateAgreement, *coredata.File, error) {
existingAgreement := &coredata.VendorBusinessAssociateAgreement{}
file := &coredata.File{}
err := s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
if err := existingAgreement.LoadByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
return fmt.Errorf("cannot load existing vendor business associate agreement: %w", err)
}
if err := file.LoadByID(ctx, conn, s.svc.scope, existingAgreement.FileID); err != nil {
return fmt.Errorf("cannot load file: %w", err)
}
now := time.Now()
if req.ValidFrom != nil {
existingAgreement.ValidFrom = *req.ValidFrom
}
if req.ValidUntil != nil {
existingAgreement.ValidUntil = *req.ValidUntil
}
existingAgreement.UpdatedAt = now
if err := file.LoadByID(ctx, conn, s.svc.scope, existingAgreement.FileID); err != nil {
return fmt.Errorf("cannot load file: %w", err)
}
if err := existingAgreement.Update(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot update vendor business associate agreement: %w", err)
}
return nil
},
)
if err != nil {
return nil, nil, err
}
return existingAgreement, file, nil
}
func (s VendorBusinessAssociateAgreementService) Delete(
ctx context.Context,
vendorBusinessAssociateAgreementID gid.GID,
) error {
return s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
vendorBusinessAssociateAgreement := &coredata.VendorBusinessAssociateAgreement{}
if err := vendorBusinessAssociateAgreement.LoadByID(ctx, conn, s.svc.scope, vendorBusinessAssociateAgreementID); err != nil {
return fmt.Errorf("cannot load vendor business associate agreement: %w", err)
}
file := &coredata.File{ID: vendorBusinessAssociateAgreement.FileID}
if err := vendorBusinessAssociateAgreement.Delete(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot delete vendor business associate agreement: %w", err)
}
if err := file.SoftDelete(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot soft delete file: %w", err)
}
return nil
},
)
}
func (s VendorBusinessAssociateAgreementService) DeleteByVendorID(
ctx context.Context,
vendorID gid.GID,
) error {
return s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
vendorBusinessAssociateAgreement := &coredata.VendorBusinessAssociateAgreement{}
if err := vendorBusinessAssociateAgreement.LoadByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
return fmt.Errorf("cannot load vendor business associate agreement: %w", err)
}
file := &coredata.File{ID: vendorBusinessAssociateAgreement.FileID}
if err := vendorBusinessAssociateAgreement.DeleteByVendorID(ctx, conn, s.svc.scope, vendorID); err != nil {
return fmt.Errorf("cannot delete vendor business associate agreement: %w", err)
}
if err := file.SoftDelete(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot soft delete file: %w", err)
}
return nil
},
)
}

View File

@@ -915,6 +915,8 @@ type Vendor implements Node {
orderBy: VendorComplianceReportOrder
): VendorComplianceReportConnection! @goField(forceResolver: true)
businessAssociateAgreement: VendorBusinessAssociateAgreement @goField(forceResolver: true)
riskAssessments(
first: Int
after: CursorKey
@@ -956,6 +958,18 @@ type VendorComplianceReport implements Node {
updatedAt: Datetime!
}
type VendorBusinessAssociateAgreement implements Node {
id: ID!
vendor: Vendor! @goField(forceResolver: true)
validFrom: Datetime
validUntil: Datetime
fileName: String!
fileUrl: String! @goField(forceResolver: true)
fileSize: Int!
createdAt: Datetime!
updatedAt: Datetime!
}
type Framework implements Node {
id: ID!
name: String!
@@ -1593,6 +1607,17 @@ type Mutation {
input: DeleteVendorComplianceReportInput!
): DeleteVendorComplianceReportPayload!
# Vendor Business Associate Agreement mutations
uploadVendorBusinessAssociateAgreement(
input: UploadVendorBusinessAssociateAgreementInput!
): UploadVendorBusinessAssociateAgreementPayload!
updateVendorBusinessAssociateAgreement(
input: UpdateVendorBusinessAssociateAgreementInput!
): UpdateVendorBusinessAssociateAgreementPayload!
deleteVendorBusinessAssociateAgreement(
input: DeleteVendorBusinessAssociateAgreementInput!
): DeleteVendorBusinessAssociateAgreementPayload!
# Document mutations
createDocument(input: CreateDocumentInput!): CreateDocumentPayload!
updateDocument(input: UpdateDocumentInput!): UpdateDocumentPayload!
@@ -1948,6 +1973,24 @@ input DeleteVendorComplianceReportInput {
reportId: ID!
}
input UploadVendorBusinessAssociateAgreementInput {
vendorId: ID!
validFrom: Datetime
validUntil: Datetime
fileName: String!
file: Upload!
}
input UpdateVendorBusinessAssociateAgreementInput {
vendorId: ID!
validFrom: Datetime
validUntil: Datetime
}
input DeleteVendorBusinessAssociateAgreementInput {
vendorId: ID!
}
input CreateDocumentInput {
organizationId: ID!
title: String!
@@ -2228,6 +2271,18 @@ type DeleteVendorComplianceReportPayload {
deletedVendorComplianceReportId: ID!
}
type UploadVendorBusinessAssociateAgreementPayload {
vendorBusinessAssociateAgreement: VendorBusinessAssociateAgreement!
}
type UpdateVendorBusinessAssociateAgreementPayload {
vendorBusinessAssociateAgreement: VendorBusinessAssociateAgreement!
}
type DeleteVendorBusinessAssociateAgreementPayload {
deletedVendorId: ID!
}
type CreateDocumentPayload {
documentEdge: DocumentEdge!
documentVersionEdge: DocumentVersionEdge!

File diff suppressed because it is too large Load Diff

View File

@@ -595,6 +595,14 @@ type DeleteTrustCenterAccessPayload struct {
DeletedTrustCenterAccessID gid.GID `json:"deletedTrustCenterAccessId"`
}
type DeleteVendorBusinessAssociateAgreementInput struct {
VendorID gid.GID `json:"vendorId"`
}
type DeleteVendorBusinessAssociateAgreementPayload struct {
DeletedVendorID gid.GID `json:"deletedVendorId"`
}
type DeleteVendorComplianceReportInput struct {
ReportID gid.GID `json:"reportId"`
}
@@ -1256,6 +1264,16 @@ type UpdateTrustCenterPayload struct {
TrustCenter *TrustCenter `json:"trustCenter"`
}
type UpdateVendorBusinessAssociateAgreementInput struct {
VendorID gid.GID `json:"vendorId"`
ValidFrom *time.Time `json:"validFrom,omitempty"`
ValidUntil *time.Time `json:"validUntil,omitempty"`
}
type UpdateVendorBusinessAssociateAgreementPayload struct {
VendorBusinessAssociateAgreement *VendorBusinessAssociateAgreement `json:"vendorBusinessAssociateAgreement"`
}
type UpdateVendorInput struct {
ID gid.GID `json:"id"`
Name *string `json:"name,omitempty"`
@@ -1310,6 +1328,18 @@ type UploadTaskEvidencePayload struct {
EvidenceEdge *EvidenceEdge `json:"evidenceEdge"`
}
type UploadVendorBusinessAssociateAgreementInput struct {
VendorID gid.GID `json:"vendorId"`
ValidFrom *time.Time `json:"validFrom,omitempty"`
ValidUntil *time.Time `json:"validUntil,omitempty"`
FileName string `json:"fileName"`
File graphql.Upload `json:"file"`
}
type UploadVendorBusinessAssociateAgreementPayload struct {
VendorBusinessAssociateAgreement *VendorBusinessAssociateAgreement `json:"vendorBusinessAssociateAgreement"`
}
type UploadVendorComplianceReportInput struct {
VendorID gid.GID `json:"vendorId"`
ReportDate time.Time `json:"reportDate"`
@@ -1351,6 +1381,7 @@ type Vendor struct {
Description *string `json:"description,omitempty"`
Organization *Organization `json:"organization"`
ComplianceReports *VendorComplianceReportConnection `json:"complianceReports"`
BusinessAssociateAgreement *VendorBusinessAssociateAgreement `json:"businessAssociateAgreement,omitempty"`
RiskAssessments *VendorRiskAssessmentConnection `json:"riskAssessments"`
BusinessOwner *People `json:"businessOwner,omitempty"`
SecurityOwner *People `json:"securityOwner,omitempty"`
@@ -1375,6 +1406,21 @@ type Vendor struct {
func (Vendor) IsNode() {}
func (this Vendor) GetID() gid.GID { return this.ID }
type VendorBusinessAssociateAgreement struct {
ID gid.GID `json:"id"`
Vendor *Vendor `json:"vendor"`
ValidFrom *time.Time `json:"validFrom,omitempty"`
ValidUntil *time.Time `json:"validUntil,omitempty"`
FileName string `json:"fileName"`
FileURL string `json:"fileUrl"`
FileSize int `json:"fileSize"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (VendorBusinessAssociateAgreement) IsNode() {}
func (this VendorBusinessAssociateAgreement) GetID() gid.GID { return this.ID }
type VendorComplianceReport struct {
ID gid.GID `json:"id"`
Vendor *Vendor `json:"vendor"`

View File

@@ -0,0 +1,31 @@
// 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"
)
func NewVendorBusinessAssociateAgreement(v *coredata.VendorBusinessAssociateAgreement, file *coredata.File) *VendorBusinessAssociateAgreement {
return &VendorBusinessAssociateAgreement{
ID: v.ID,
ValidFrom: v.ValidFrom,
ValidUntil: v.ValidUntil,
FileName: file.FileName,
FileSize: file.FileSize,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
}

View File

@@ -18,6 +18,7 @@ import (
"github.com/getprobo/probo/pkg/probo"
"github.com/getprobo/probo/pkg/server/api/console/v1/schema"
"github.com/getprobo/probo/pkg/server/api/console/v1/types"
pgx "github.com/jackc/pgx/v5"
"github.com/vektah/gqlparser/v2/gqlerror"
)
@@ -1905,6 +1906,64 @@ func (r *mutationResolver) DeleteVendorComplianceReport(ctx context.Context, inp
}, nil
}
// UploadVendorBusinessAssociateAgreement is the resolver for the uploadVendorBusinessAssociateAgreement field.
func (r *mutationResolver) UploadVendorBusinessAssociateAgreement(ctx context.Context, input types.UploadVendorBusinessAssociateAgreementInput) (*types.UploadVendorBusinessAssociateAgreementPayload, error) {
prb := r.ProboService(ctx, input.VendorID.TenantID())
vendorBusinessAssociateAgreement, file, err := prb.VendorBusinessAssociateAgreements.Upload(
ctx,
input.VendorID,
&probo.VendorBusinessAssociateAgreementCreateRequest{
File: input.File.File,
ValidFrom: input.ValidFrom,
ValidUntil: input.ValidUntil,
FileName: input.FileName,
},
)
if err != nil {
return nil, fmt.Errorf("failed to upload vendor business associate agreement: %w", err)
}
return &types.UploadVendorBusinessAssociateAgreementPayload{
VendorBusinessAssociateAgreement: types.NewVendorBusinessAssociateAgreement(vendorBusinessAssociateAgreement, file),
}, nil
}
// UpdateVendorBusinessAssociateAgreement is the resolver for the updateVendorBusinessAssociateAgreement field.
func (r *mutationResolver) UpdateVendorBusinessAssociateAgreement(ctx context.Context, input types.UpdateVendorBusinessAssociateAgreementInput) (*types.UpdateVendorBusinessAssociateAgreementPayload, error) {
prb := r.ProboService(ctx, input.VendorID.TenantID())
vendorBusinessAssociateAgreement, file, err := prb.VendorBusinessAssociateAgreements.Update(
ctx,
input.VendorID,
&probo.VendorBusinessAssociateAgreementUpdateRequest{
ValidFrom: &input.ValidFrom,
ValidUntil: &input.ValidUntil,
},
)
if err != nil {
return nil, fmt.Errorf("failed to update vendor business associate agreement: %w", err)
}
return &types.UpdateVendorBusinessAssociateAgreementPayload{
VendorBusinessAssociateAgreement: types.NewVendorBusinessAssociateAgreement(vendorBusinessAssociateAgreement, file),
}, nil
}
// DeleteVendorBusinessAssociateAgreement is the resolver for the deleteVendorBusinessAssociateAgreement field.
func (r *mutationResolver) DeleteVendorBusinessAssociateAgreement(ctx context.Context, input types.DeleteVendorBusinessAssociateAgreementInput) (*types.DeleteVendorBusinessAssociateAgreementPayload, error) {
prb := r.ProboService(ctx, input.VendorID.TenantID())
err := prb.VendorBusinessAssociateAgreements.DeleteByVendorID(ctx, input.VendorID)
if err != nil {
return nil, fmt.Errorf("failed to delete vendor business associate agreement: %w", err)
}
return &types.DeleteVendorBusinessAssociateAgreementPayload{
DeletedVendorID: input.VendorID,
}, nil
}
// CreateDocument is the resolver for the createDocument field.
func (r *mutationResolver) CreateDocument(ctx context.Context, input types.CreateDocumentInput) (*types.CreateDocumentPayload, error) {
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
@@ -3330,6 +3389,22 @@ func (r *vendorResolver) ComplianceReports(ctx context.Context, obj *types.Vendo
return types.NewVendorComplianceReportConnection(page), nil
}
// BusinessAssociateAgreement is the resolver for the businessAssociateAgreement field.
func (r *vendorResolver) BusinessAssociateAgreement(ctx context.Context, obj *types.Vendor) (*types.VendorBusinessAssociateAgreement, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
vendorBusinessAssociateAgreement, file, err := prb.VendorBusinessAssociateAgreements.GetByVendorID(ctx, obj.ID)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, nil
}
return nil, fmt.Errorf("failed to get vendor business associate agreement: %w", err)
}
return types.NewVendorBusinessAssociateAgreement(vendorBusinessAssociateAgreement, file), nil
}
// RiskAssessments is the resolver for the riskAssessments field.
func (r *vendorResolver) RiskAssessments(ctx context.Context, obj *types.Vendor, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.VendorRiskAssessmentOrder) (*types.VendorRiskAssessmentConnection, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
@@ -3396,6 +3471,30 @@ func (r *vendorResolver) SecurityOwner(ctx context.Context, obj *types.Vendor) (
return types.NewPeople(people), nil
}
// Vendor is the resolver for the vendor field.
func (r *vendorBusinessAssociateAgreementResolver) Vendor(ctx context.Context, obj *types.VendorBusinessAssociateAgreement) (*types.Vendor, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
vendor, err := prb.Vendors.Get(ctx, obj.ID)
if err != nil {
return nil, fmt.Errorf("failed to get vendor: %w", err)
}
return types.NewVendor(vendor), nil
}
// FileURL is the resolver for the fileUrl field.
func (r *vendorBusinessAssociateAgreementResolver) FileURL(ctx context.Context, obj *types.VendorBusinessAssociateAgreement) (string, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
fileURL, err := prb.VendorBusinessAssociateAgreements.GenerateFileURL(ctx, obj.ID, 1*time.Hour)
if err != nil {
return "", fmt.Errorf("failed to generate file URL: %w", err)
}
return fileURL, nil
}
// Vendor is the resolver for the vendor field.
func (r *vendorComplianceReportResolver) Vendor(ctx context.Context, obj *types.VendorComplianceReport) (*types.Vendor, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
@@ -3614,6 +3713,11 @@ func (r *Resolver) User() schema.UserResolver { return &userResolver{r} }
// Vendor returns schema.VendorResolver implementation.
func (r *Resolver) Vendor() schema.VendorResolver { return &vendorResolver{r} }
// VendorBusinessAssociateAgreement returns schema.VendorBusinessAssociateAgreementResolver implementation.
func (r *Resolver) VendorBusinessAssociateAgreement() schema.VendorBusinessAssociateAgreementResolver {
return &vendorBusinessAssociateAgreementResolver{r}
}
// VendorComplianceReport returns schema.VendorComplianceReportResolver implementation.
func (r *Resolver) VendorComplianceReport() schema.VendorComplianceReportResolver {
return &vendorComplianceReportResolver{r}
@@ -3662,6 +3766,7 @@ type taskConnectionResolver struct{ *Resolver }
type trustCenterResolver struct{ *Resolver }
type userResolver struct{ *Resolver }
type vendorResolver struct{ *Resolver }
type vendorBusinessAssociateAgreementResolver struct{ *Resolver }
type vendorComplianceReportResolver struct{ *Resolver }
type vendorConnectionResolver struct{ *Resolver }
type vendorRiskAssessmentResolver struct{ *Resolver }