🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
refactor: add restriction foe default signature type
prafull-opensignlabs508b2e43d369
diff --git a/apps/OpenSign/src/components/pdf/WidgetNameModal.js b/apps/OpenSign/src/components/pdf/WidgetNameModal.jsindex 383a3f044..c6000505b 100644--- a/apps/OpenSign/src/components/pdf/WidgetNameModal.js+++ b/apps/OpenSign/src/components/pdf/WidgetNameModal.js@@ -57,8 +57,18 @@ const WidgetNameModal = (props) => {e.preventDefault();if (props.handleData) {if (["signature", "initials"].includes(props.defaultdata?.type)) {- const data = { ...formdata, signatureType };- props.handleData(data, props.defaultdata?.type);+ const enabledSignTypes = signatureType?.filter((x) => x.enabled);+ const isDefaultSignTypeOnly =+ enabledSignTypes?.length === 1 &&+ enabledSignTypes[0]?.name === "default";+ if (enabledSignTypes.length === 0) {+ alert("Please enable at least one signature type");+ } else if (isDefaultSignTypeOnly) {+ alert("Please enable one more signature type other than default");+ } else {+ const data = { ...formdata, signatureType };+ props.handleData(data, props.defaultdata?.type);+ }} else {props.handleData(formdata);}@@ -287,7 +297,7 @@ const WidgetNameModal = (props) => {</div></div>)}- {props.defaultdata?.type === "signature" && (+ {["signature", "initials"].includes(props.defaultdata?.type) && (<div className="mb-[0.75rem]"><label htmlFor="signaturetype" className="text-[14px] mb-[0.7rem]">{t("allowed-signature-types")}diff --git a/apps/OpenSign/src/pages/Preferences.js b/apps/OpenSign/src/pages/Preferences.jsindex 3d098d4d0..9c2438228 100644--- a/apps/OpenSign/src/pages/Preferences.js+++ b/apps/OpenSign/src/pages/Preferences.js@@ -55,7 +55,8 @@ const Preferences = () => {setIsTopLoader(false);}};- console.log("sign", signatureType);++ // `handleCheckboxChange` is trigger when user enable/disable checkbox of respective typeconst handleCheckboxChange = (index) => {// Create a copy of the signatureType arrayconst updatedSignatureType = [...signatureType];@@ -64,31 +65,38 @@ const Preferences = () => {// Update the state with the modified arraysetSignatureType(updatedSignatureType);};++ // `handleSave` is used save updated value signature typeconst handleSave = async () => {- console.log("submit", signatureType);setIsLoader(true);- const isEnabled = signatureType.some((x) => x.enabled === true);- if (isEnabled) {+ const enabledSignTypes = signatureType?.filter((x) => x.enabled);+ const isDefaultSignTypeOnly =+ enabledSignTypes?.length === 1 && enabledSignTypes[0]?.name === "default";+ if (enabledSignTypes.length === 0) {+ setIsAlert({+ type: "danger",+ msg: "Please enable at least one signature type"+ });+ } else if (isDefaultSignTypeOnly) {+ setIsAlert({+ type: "danger",+ msg: "Please enable one more signature type other than default"+ });+ } else {try {- const params = { SignatureType: signatureType };- const updateRes = await Parse.Cloud.run("updatesignaturetype", params);+ const updateRes = await Parse.Cloud.run("updatesignaturetype", {+ SignatureType: signatureType+ });if (updateRes) {setIsAlert({ type: "success", msg: "Saved successfully." });- setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);}} catch (err) {- console.log("err while updating signtype", err);- } finally {- setIsLoader(false);+ console.log("Error updating signature type", err);+ setIsAlert({ type: "danger", msg: err.message });}- } else {- setIsAlert({- type: "danger",- msg: "Please enable at least one signature type"- });- setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);- setIsLoader(false);}+ setTimeout(() => setIsAlert({ type: "success", msg: "" }), 1500);+ setIsLoader(false);};return (diff --git a/apps/OpenSignServer/cloud/parsefunction/PublicUserLinkContactToDoc.js b/apps/OpenSignServer/cloud/parsefunction/PublicUserLinkContactToDoc.jsindex dedfd33c7..9e55e3a3b 100644--- a/apps/OpenSignServer/cloud/parsefunction/PublicUserLinkContactToDoc.js+++ b/apps/OpenSignServer/cloud/parsefunction/PublicUserLinkContactToDoc.js@@ -71,6 +71,9 @@ const createDocumentFromTemplate = async (template, existContact, index) => {object.set('IsEnableOTP', template?.IsEnableOTP || false);object.set('IsTourEnabled', template?.IsTourEnabled || false);object.set('FileAdapterId', template?.FileAdapterId || '');+ if (template?.SignatureType?.length > 0) {+ object.set('SignatureType', template?.SignatureType);+ }let signers = template?.Signers || [];const signerobj = {__type: 'Pointer',@@ -254,6 +257,7 @@ const deductcount = async _resSub => {export default async function PublicUserLinkContactToDoc(req) {const email = req.params.email;const templateid = req.params.templateid;+ const signatureType = req.params.signatureType;const name = req.params.name;const phone = req.params.phone;const role = req.params.role;@@ -301,8 +305,11 @@ export default async function PublicUserLinkContactToDoc(req) {const existContact = await contactCls.first({ useMasterKey: true });if (existContact) {const template_json = JSON.parse(JSON.stringify(tempRes));+ const _template_json = template_json;+ _template_json.SignatureType =+ signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;//update contact in placeholder, signers and update ACl in provide document- const docRes = await createDocumentFromTemplate(template_json, existContact, index);+ const docRes = await createDocumentFromTemplate(_template_json, existContact, index);if (docRes) {await deductcount(_resSub);//condition will execute only if sendInOrder will be false for send email to all signers at a time.@@ -327,9 +334,12 @@ export default async function PublicUserLinkContactToDoc(req) {TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,};const template_json = JSON.parse(JSON.stringify(tempRes));+ const _template_json = template_json;+ _template_json.SignatureType =+ signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;// if user present on platform create contact on the basis of extended user detailsconst contactRes = await saveRoleContact(contact);- const docRes = await createDocumentFromTemplate(template_json, contactRes, index);+ const docRes = await createDocumentFromTemplate(_template_json, contactRes, index);if (docRes) {await deductcount(_resSub);//condition will execute only if sendInOrder will be false for send email to all signers at a time.@@ -354,11 +364,14 @@ export default async function PublicUserLinkContactToDoc(req) {TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,};const template_json = JSON.parse(JSON.stringify(tempRes));+ const _template_json = template_json;+ _template_json.SignatureType =+ signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;// Create new contract on the basis provided contact details by user and userId from _User classconst contactRes = await saveRoleContact(contact);//update contact in placeholder, signers and update ACl in provide documentconst docRes = await createDocumentFromTemplate(- template_json,+ _template_json,contactRes,index);@@ -391,11 +404,14 @@ export default async function PublicUserLinkContactToDoc(req) {TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,};const template_json = JSON.parse(JSON.stringify(tempRes));+ const _template_json = template_json;+ _template_json.SignatureType =+ signatureType?.length > 0 ? signatureType : _template_json?.SignatureType;// Create new contract on the basis provided contact details by user and userId from _User classconst contactRes = await saveRoleContact(contact);//update contact in placeholder, signers and update ACl in provide documentconst docRes = await createDocumentFromTemplate(- template_json,+ _template_json,contactRes,index);diff --git a/apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.js b/apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.jsindex 1d72706e6..0f53706aa 100644--- a/apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.js+++ b/apps/OpenSignServer/cloud/parsefunction/updatesignaturetype.js@@ -4,8 +4,21 @@ export default async function updateSignatureType(request) {}const SignatureType = request.params.SignatureType || [];if (SignatureType.length > 0) {- const isEnabled = SignatureType.some(x => x.enabled === true);- if (isEnabled) {+ const enabledSignTypes = SignatureType?.filter(x => x.enabled);+ const isDefaultSignTypeOnly =+ enabledSignTypes?.length === 1 && enabledSignTypes[0]?.name === 'default';++ if (enabledSignTypes.length === 0) {+ throw new Parse.Error(+ Parse.Error.INVALID_QUERY,+ 'At least one signature type should be enabled.'+ );+ } else if (isDefaultSignTypeOnly) {+ throw new Parse.Error(+ Parse.Error.INVALID_QUERY,+ 'Please enable one more signature type other than default.'+ );+ } else {try {const orgQuery = new Parse.Query('contracts_Users');orgQuery.equalTo('UserId', {@@ -32,11 +45,6 @@ export default async function updateSignatureType(request) {const msg = err?.message || 'Something went wrong.';throw new Parse.Error(code, msg);}- } else {- throw new Parse.Error(- Parse.Error.INVALID_QUERY,- 'At least one signature type should be enabled.'- );}} else {throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Please provide signature types.');