Split employee document policy from core document actions
Introduce dedicated employee-scoped IAM actions and update all resolvers and frontend mutations accordingly. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -46,7 +46,7 @@ import type { DocumentApprovePage_approveMutation } from "#/__generated__/core/D
|
||||
import type { DocumentApprovePage_rejectMutation } from "#/__generated__/core/DocumentApprovePage_rejectMutation.graphql";
|
||||
import type { DocumentApprovePageDecisionFragment$key } from "#/__generated__/core/DocumentApprovePageDecisionFragment.graphql";
|
||||
import type { DocumentApprovePageDocumentFragment$key } from "#/__generated__/core/DocumentApprovePageDocumentFragment.graphql";
|
||||
import type { DocumentApprovePageExportPDFMutation } from "#/__generated__/core/DocumentApprovePageExportPDFMutation.graphql";
|
||||
import type { DocumentApprovePageExportEmployeePDFMutation } from "#/__generated__/core/DocumentApprovePageExportEmployeePDFMutation.graphql";
|
||||
import type { DocumentApprovePageQuery } from "#/__generated__/core/DocumentApprovePageQuery.graphql";
|
||||
import type { DocumentApprovePageVersionRowFragment$key } from "#/__generated__/core/DocumentApprovePageVersionRowFragment.graphql";
|
||||
import { PDFPreview } from "#/components/documents/PDFPreview";
|
||||
@@ -100,9 +100,6 @@ const decisionFragment = graphql`
|
||||
state
|
||||
canApprove: permission(action: "core:document-version:approve")
|
||||
canReject: permission(action: "core:document-version:reject")
|
||||
documentVersion {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -131,10 +128,10 @@ const rejectDocumentVersionMutation = graphql`
|
||||
`;
|
||||
|
||||
const exportPDFMutation = graphql`
|
||||
mutation DocumentApprovePageExportPDFMutation(
|
||||
$input: ExportDocumentVersionPDFInput!
|
||||
mutation DocumentApprovePageExportEmployeePDFMutation(
|
||||
$input: ExportEmployeeDocumentVersionPDFInput!
|
||||
) {
|
||||
exportDocumentVersionPDF(input: $input) {
|
||||
exportEmployeeDocumentVersionPDF(input: $input) {
|
||||
data
|
||||
}
|
||||
}
|
||||
@@ -227,9 +224,10 @@ function VersionRow({
|
||||
|
||||
function ViewerDecision(props: {
|
||||
fragmentRef: DocumentApprovePageDecisionFragment$key;
|
||||
versionId: string;
|
||||
onBack: () => void;
|
||||
}) {
|
||||
const { fragmentRef, onBack } = props;
|
||||
const { fragmentRef, versionId, onBack } = props;
|
||||
const { __ } = useTranslate();
|
||||
const decision = useFragment(decisionFragment, fragmentRef);
|
||||
const rejectDialogRef = useDialogRef();
|
||||
@@ -311,7 +309,7 @@ function ViewerDecision(props: {
|
||||
approveVersion({
|
||||
variables: {
|
||||
input: {
|
||||
documentVersionId: decision.documentVersion.id,
|
||||
documentVersionId: versionId,
|
||||
},
|
||||
},
|
||||
onCompleted(_, errors) {
|
||||
@@ -372,7 +370,7 @@ function ViewerDecision(props: {
|
||||
rejectVersion({
|
||||
variables: {
|
||||
input: {
|
||||
documentVersionId: decision.documentVersion.id,
|
||||
documentVersionId: versionId,
|
||||
comment: rejectComment || undefined,
|
||||
},
|
||||
},
|
||||
@@ -434,7 +432,7 @@ function DocumentApproveContent({
|
||||
|
||||
usePageTitle(__("Review and Approve Document"));
|
||||
|
||||
const [exportPDF] = useMutation<DocumentApprovePageExportPDFMutation>(
|
||||
const [exportPDF] = useMutation<DocumentApprovePageExportEmployeePDFMutation>(
|
||||
exportPDFMutation,
|
||||
);
|
||||
|
||||
@@ -448,8 +446,6 @@ function DocumentApproveContent({
|
||||
variables: {
|
||||
input: {
|
||||
documentVersionId: selectedVersion.id,
|
||||
withWatermark: true,
|
||||
withSignatures: false,
|
||||
},
|
||||
},
|
||||
onCompleted: (data, errors): void => {
|
||||
@@ -464,8 +460,8 @@ function DocumentApproveContent({
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (data.exportDocumentVersionPDF?.data) {
|
||||
const dataUrl = data.exportDocumentVersionPDF.data;
|
||||
if (data.exportEmployeeDocumentVersionPDF?.data) {
|
||||
const dataUrl = data.exportEmployeeDocumentVersionPDF.data;
|
||||
pdfUrlRef.current = dataUrl;
|
||||
setPdfUrl(dataUrl);
|
||||
}
|
||||
@@ -522,6 +518,7 @@ function DocumentApproveContent({
|
||||
? (
|
||||
<ViewerDecision
|
||||
fragmentRef={decision}
|
||||
versionId={selectedVersion.id}
|
||||
onBack={() =>
|
||||
void navigate(`/organizations/${organizationId}/employee/approvals`)}
|
||||
/>
|
||||
|
||||
@@ -28,7 +28,7 @@ import { useNavigate } from "react-router";
|
||||
import { useWindowSize } from "usehooks-ts";
|
||||
|
||||
import type { EmployeeDocumentSignaturePageDocumentFragment$key } from "#/__generated__/core/EmployeeDocumentSignaturePageDocumentFragment.graphql";
|
||||
import type { EmployeeDocumentSignaturePageExportSignablePDFMutation } from "#/__generated__/core/EmployeeDocumentSignaturePageExportSignablePDFMutation.graphql";
|
||||
import type { EmployeeDocumentSignaturePageExportEmployeePDFMutation } from "#/__generated__/core/EmployeeDocumentSignaturePageExportEmployeePDFMutation.graphql";
|
||||
import type { EmployeeDocumentSignaturePageQuery } from "#/__generated__/core/EmployeeDocumentSignaturePageQuery.graphql";
|
||||
import type { EmployeeDocumentSignaturePageSignMutation } from "#/__generated__/core/EmployeeDocumentSignaturePageSignMutation.graphql";
|
||||
import { PDFPreview } from "#/components/documents/PDFPreview";
|
||||
@@ -80,11 +80,11 @@ const signDocumentMutation = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
const exportSignableVersionDocumentPDFMutation = graphql`
|
||||
mutation EmployeeDocumentSignaturePageExportSignablePDFMutation(
|
||||
$input: ExportSignableDocumentVersionPDFInput!
|
||||
const exportEmployeeDocumentVersionPDFMutation = graphql`
|
||||
mutation EmployeeDocumentSignaturePageExportEmployeePDFMutation(
|
||||
$input: ExportEmployeeDocumentVersionPDFInput!
|
||||
) {
|
||||
exportSignableVersionDocumentPDF(input: $input) {
|
||||
exportEmployeeDocumentVersionPDF(input: $input) {
|
||||
data
|
||||
}
|
||||
}
|
||||
@@ -145,9 +145,9 @@ function DocumentSignatureContent({
|
||||
signDocumentMutation,
|
||||
);
|
||||
|
||||
const [exportSignableVersionDocumentPDF]
|
||||
= useMutation<EmployeeDocumentSignaturePageExportSignablePDFMutation>(
|
||||
exportSignableVersionDocumentPDFMutation,
|
||||
const [exportEmployeeDocumentVersionPDF]
|
||||
= useMutation<EmployeeDocumentSignaturePageExportEmployeePDFMutation>(
|
||||
exportEmployeeDocumentVersionPDFMutation,
|
||||
);
|
||||
|
||||
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
|
||||
@@ -191,7 +191,7 @@ function DocumentSignatureContent({
|
||||
useEffect(() => {
|
||||
if (!selectedVersion?.id) return;
|
||||
|
||||
exportSignableVersionDocumentPDF({
|
||||
exportEmployeeDocumentVersionPDF({
|
||||
variables: {
|
||||
input: {
|
||||
documentVersionId: selectedVersion.id,
|
||||
@@ -209,8 +209,8 @@ function DocumentSignatureContent({
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (data.exportSignableVersionDocumentPDF?.data) {
|
||||
const dataUrl = data.exportSignableVersionDocumentPDF.data;
|
||||
if (data.exportEmployeeDocumentVersionPDF?.data) {
|
||||
const dataUrl = data.exportEmployeeDocumentVersionPDF.data;
|
||||
pdfUrlRef.current = dataUrl;
|
||||
setPdfUrl(dataUrl);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ function DocumentSignatureContent({
|
||||
return () => {
|
||||
pdfUrlRef.current = null;
|
||||
};
|
||||
}, [selectedVersion?.id, exportSignableVersionDocumentPDF, toast, __]);
|
||||
}, [selectedVersion?.id, exportEmployeeDocumentVersionPDF, toast, __]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user