Skip to content

Commit bb69518

Browse files
authored
Merge branch 'OpenSignLabs:staging' into staging
2 parents dc1fab5 + fee53fb commit bb69518

File tree

5 files changed

+79
-20
lines changed

5 files changed

+79
-20
lines changed

apps/OpenSign/src/components/RenderDebugPdf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const RenderDebugPdf = (props) => {
2222
flex: 1,
2323
position: "relative",
2424
border: "1px solid grey",
25-
overflow: "auto"
25+
overflow: "auto",
26+
cursor: "crosshair"
2627
}}
2728
onMouseMove={props.handleMouseMoveDiv}
2829
>

apps/OpenSign/src/components/pdf/PdfHeader.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useNavigate } from "react-router-dom";
99
import { themeColor } from "../../constant/const";
1010
import axios from "axios";
1111
import ModalUi from "../../primitives/ModalUi";
12-
import Parse from "parse";
12+
import { appInfo } from "../../constant/appinfo";
1313

1414
function Header({
1515
isPdfRequestFiles,
@@ -64,7 +64,19 @@ function Header({
6464
event.preventDefault();
6565

6666
try {
67-
const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
67+
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
68+
const axiosRes = await axios.post(
69+
`${appInfo.baseUrl}/functions/getsignedurl`,
70+
{ url: pdfUrl },
71+
{
72+
headers: {
73+
"content-type": "Application/json",
74+
"X-Parse-Application-Id": appInfo.appId,
75+
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
76+
}
77+
}
78+
);
79+
const url = axiosRes.data.result;
6880
const pdf = await getBase64FromUrl(url);
6981
const isAndroidDevice = navigator.userAgent.match(/Android/i);
7082
const isAppleDevice =
@@ -94,7 +106,19 @@ function Header({
94106
const handleDownloadPdf = async () => {
95107
const pdfName = pdfDetails[0] && pdfDetails[0].Name;
96108
try {
97-
const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
109+
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
110+
const axiosRes = await axios.post(
111+
`${appInfo.baseUrl}/functions/getsignedurl`,
112+
{ url: pdfUrl },
113+
{
114+
headers: {
115+
"content-type": "Application/json",
116+
"X-Parse-Application-Id": appInfo.appId,
117+
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
118+
}
119+
}
120+
);
121+
const url = axiosRes.data.result;
98122
saveAs(url, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`);
99123
} catch (err) {
100124
console.log("err in getsignedurl", err);
@@ -577,8 +601,13 @@ function Header({
577601
handleClose={() => setIsCertificate(false)}
578602
>
579603
<div className="p-3 md:p-5 text-[13px] md:text-base text-center">
580-
<p>Your completion certificate is being generated. Please wait momentarily.</p>
581-
<p>If the download doesn&apos;t start shortly, click the button again.</p>
604+
<p>
605+
Your completion certificate is being generated. Please wait
606+
momentarily.
607+
</p>
608+
<p>
609+
If the download doesn&apos;t start shortly, click the button again.
610+
</p>
582611
</div>
583612
</ModalUi>
584613
</div>

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ function PdfRequestFiles() {
104104
const [currWidgetsDetails, setCurrWidgetsDetails] = useState({});
105105
const [isSubscriptionExpired, setIsSubscriptionExpired] = useState(false);
106106
const [extUserId, setExtUserId] = useState("");
107-
const [pdfArrayBuffer, setPdfArrayBuffer] = useState("");
108107
const [isEmailVerified, setIsEmailVerified] = useState(true);
109108
const [isVerifyModal, setIsVerifyModal] = useState(false);
110109
const [otp, setOtp] = useState("");
@@ -225,16 +224,6 @@ function PdfRequestFiles() {
225224
//getting document details
226225
const documentData = await contractDocument(documentId);
227226
if (documentData && documentData.length > 0) {
228-
const url =
229-
documentData[0] && (documentData[0]?.SignedUrl || documentData[0]?.URL);
230-
//convert document url in array buffer format to use embed widgets in pdf using pdf-lib
231-
const arrayBuffer = await convertPdfArrayBuffer(url);
232-
if (arrayBuffer === "Error") {
233-
setHandleError("Error: Something went wrong!");
234-
} else {
235-
setPdfArrayBuffer(arrayBuffer);
236-
}
237-
238227
setExtUserId(documentData[0]?.ExtUserPtr?.objectId);
239228
const isCompleted =
240229
documentData[0].IsCompleted && documentData[0].IsCompleted;
@@ -642,9 +631,32 @@ function PdfRequestFiles() {
642631
setWidgetsTour(true);
643632
} else {
644633
setIsUiLoading(true);
634+
645635
const pngUrl = checkUser[0].placeHolder;
636+
let pdfArrBuffer;
637+
//`contractDocument` function used to get updated SignedUrl
638+
//resolved issue of sign document by multiple signers simultaneously
639+
const documentData = await contractDocument(documentId);
640+
if (documentData && documentData.length > 0) {
641+
const url = documentData[0]?.SignedUrl || documentData[0]?.URL;
642+
//convert document url in array buffer format to use embed widgets in pdf using pdf-lib
643+
const arrayBuffer = await convertPdfArrayBuffer(url);
644+
if (arrayBuffer === "Error") {
645+
setHandleError("Error: invalid document!");
646+
} else {
647+
pdfArrBuffer = arrayBuffer;
648+
}
649+
} else if (
650+
documentData === "Error: Something went wrong!" ||
651+
(documentData.result && documentData.result.error)
652+
) {
653+
setHandleError("Error: Something went wrong!");
654+
} else {
655+
setHandleError("Document not Found!");
656+
}
657+
646658
// Load a PDFDocument from the existing PDF bytes
647-
const existingPdfBytes = pdfArrayBuffer;
659+
const existingPdfBytes = pdfArrBuffer;
648660
try {
649661
const pdfDoc = await PDFDocument.load(existingPdfBytes);
650662
const isSignYourSelfFlow = false;

apps/OpenSignServer/cloud/customRoute/v1/routes/CreateDocumentWithTemplate.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,20 @@ export default async function createDocumentWithTemplate(request, response) {
8888
const updateSigners = placeholder.every(y => signers?.some(x => x.role === y.Role));
8989
// console.log('isValid ', isValid);
9090
if (isValid && updateSigners) {
91+
//Check if every item's placeholders contain at least one placeholder with type 'signature'.
92+
let isSignature = template?.Placeholders?.every(item =>
93+
item?.placeHolder.some(x => x?.pos.some(data => data?.type === 'signature'))
94+
);
95+
if (!isSignature) {
96+
return response
97+
.status(400)
98+
.json({ error: 'Please add at least one signature widget for all signers' });
99+
}
91100
const folderPtr = {
92101
__type: 'Pointer',
93102
className: 'contracts_Document',
94103
objectId: folderId,
95104
};
96-
const template = JSON.parse(JSON.stringify(templateRes));
97105
const object = new Parse.Object('contracts_Document');
98106
object.set('Name', template.Name);
99107
if (template?.Note) {
@@ -169,7 +177,7 @@ export default async function createDocumentWithTemplate(request, response) {
169177
object.set('Signers', templateSigner);
170178
}
171179
object.set('URL', template.URL);
172-
object.set('SignedUrl', template.URL);
180+
object.set('SignedUrl', template.URL);
173181
object.set('CreatedBy', template.CreatedBy);
174182
object.set('ExtUserPtr', {
175183
__type: 'Pointer',

apps/OpenSignServer/cloud/customRoute/v1/routes/createDocumentwithCoordinate.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ export default async function createDocumentwithCoordinate(request, response) {
8888
objectId: parseUser.userId.objectId,
8989
};
9090
if (signers && signers.length > 0) {
91+
// Check if at least one signature exists among all items in the signers array
92+
let isSignExist = signers.every(item =>
93+
item.widgets.some(data => data?.type === 'signature')
94+
);
95+
if (!isSignExist) {
96+
return response
97+
.status(400)
98+
.json({ error: 'Please add at least one signature widget for all signers' });
99+
}
91100
let fileUrl;
92101
if (request.files?.[0]) {
93102
const base64 = fileData?.toString('base64');

0 commit comments

Comments
 (0)