From f44205b90d4099be77de840bfa26bdfc6975b9c9 Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Mon, 4 Nov 2024 15:20:03 +0530 Subject: [PATCH] fix: invalid template id error in while opening opening public template --- apps/OpenSign/src/pages/DraftTemplate.js | 18 +++++++++--------- .../parsefunction/updateToPublicTemplate.js | 12 +++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/OpenSign/src/pages/DraftTemplate.js b/apps/OpenSign/src/pages/DraftTemplate.js index dccb2c94a..c84978d04 100644 --- a/apps/OpenSign/src/pages/DraftTemplate.js +++ b/apps/OpenSign/src/pages/DraftTemplate.js @@ -654,21 +654,20 @@ const DraftTemplate = () => { // `saveTemplate` is used to update template on server using savetemplate endpoint const saveTemplate = async () => { if (signersdata?.length) { - const loadObj = { isLoad: true, message: t("loading-mssg") }; - setIsLoading(loadObj); + setIsLoading({ isLoad: true, message: t("loading-mssg") }); setIsSendAlert(false); let signers = []; if (signersdata?.length > 0) { - signersdata.forEach((x) => { + signers = signersdata?.reduce((acc, x) => { if (x.objectId) { - const obj = { + acc.push({ __type: "Pointer", className: "contracts_Contactbook", objectId: x.objectId - }; - signers.push(obj); + }); } - }); + return acc; + }, []); } let pdfUrl = pdfDetails[0]?.URL; if (pdfRotateBase64) { @@ -1277,10 +1276,11 @@ const DraftTemplate = () => { }; const handleGeneratePublic = async () => { const unlinkSignerIndex = signerPos?.findIndex((x) => !x?.signerObjId); - const unlinkSigners = signerPos?.filter((x) => !x?.signerObjId)?.length; // unLink with role + const unlinkSigners = signerPos?.filter((x) => !x?.signerObjId)?.length; // count of total unlink roles if (unlinkSignerIndex === 0 && unlinkSigners === 1) { try { - const data = { templateId: templateId, IsPublic: true }; + const role = signerPos[unlinkSignerIndex]?.Role; + const data = { templateId: templateId, IsPublic: true, Role: role }; const baseURL = localStorage.getItem("baseUrl"); const url = `${baseURL}functions/updatetopublictemplate`; const headers = { diff --git a/apps/OpenSignServer/cloud/parsefunction/updateToPublicTemplate.js b/apps/OpenSignServer/cloud/parsefunction/updateToPublicTemplate.js index 40af4f876..e44599e4e 100644 --- a/apps/OpenSignServer/cloud/parsefunction/updateToPublicTemplate.js +++ b/apps/OpenSignServer/cloud/parsefunction/updateToPublicTemplate.js @@ -10,6 +10,7 @@ async function updateTemplate(template, isJwt = false) { const isPublic = template?.IsPublic !== undefined ? template?.IsPublic : false; if (template?.IsPublic !== undefined) { updateTemplate.set('IsPublic', isPublic); + updateTemplate.set('PublicRole', template.PublicRole); } let updateTemplateRes; @@ -29,7 +30,16 @@ async function updateTemplate(template, isJwt = false) { } export default async function updateToPublicTemplate(request) { const jwttoken = request.headers.jwttoken || ''; - const template = { Id: request.params.templateId, IsPublic: request.params?.IsPublic }; + const Role = request.params.Role; + if (!Role) { + throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Please provide public role.'); + } + const PublicRole = [Role]; + const template = { + Id: request.params.templateId, + IsPublic: request.params?.IsPublic, + PublicRole: PublicRole, + }; try { if (request.user) {