Files
OpenSign/apps/OpenSignServer/cloud/parsefunction/createDuplicate.js
T
prafull-opensignlabs e299891174 v2.12.0
feat: create duplicate template functionality
feat: add support of csv and xlsx for bulk contacts import
feat: add info text for forms and dashboard button
feat: implement functionality to delete a PDF page while editing the document
feat: show completed documents in which signers included but not owner in completed reports
feat: add delete folder button in opensign drive
feat: introduce Bcc email support for sending completed documents
feat: allow merging multiple pdf while drafting document and template
feat: add 'My Initials' tab for auto-signing in request-sign flow
feat: add support for redirect URL to navigate after document completion
feat: introduce privacy policy and digital signature terms before signing documents.
feat: add feature to allow adding new pages to existing document
feat: add save signature, initials, stamp functionality in sign pad for logged in user
feat: add preferences menu
feat: add save custom email template, notifyonsignature, set timezone, allow signature types in preferences
feat: secure local url
feat: implement Italian language translation
feat: implement German language translation
feat: update menu name from report to documents and shift contactbook in main menu
feat: provide edit contact functionality

fix: unable to delete folder when all its documents are deleted
fix: fields.push is not function
fix: document loading issue in opensign drive
fix: adjust the guest signature flow to display the document in full screen, eliminating any blank space which is displayed below the place holder in mobile view
fix: resolve issue of instance of pdfdict or pdfstream but got undefined

build(deps): update dependencies

refactor: change note text from add contact form
2025-02-10 14:41:16 +00:00

113 lines
4.2 KiB
JavaScript

export default async function createDuplicate(request) {
const templateId = request.params.templateId;
if (!request.user) {
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
}
if (templateId) {
try {
const templateQuery = new Parse.Query('contracts_Template');
templateQuery.equalTo('objectId', templateId);
templateQuery.equalTo('CreatedBy', {
__type: 'Pointer',
className: '_User',
objectId: request.user.id,
});
templateQuery.notEqualTo('IsArchive', true);
const templateRes = await templateQuery.first({ useMasterKey: true });
if (templateRes?.id) {
const _templateRes = JSON.parse(JSON.stringify(templateRes));
const newTemplate = new Parse.Object('contracts_Template');
let signers = [];
if (_templateRes.Signers?.length > 0) {
_templateRes.Signers?.forEach(x => {
if (x.objectId) {
const obj = {
__type: 'Pointer',
className: 'contracts_Contactbook',
objectId: x.objectId,
};
signers.push(obj);
}
});
}
newTemplate.set('Name', _templateRes.Name);
newTemplate.set('URL', _templateRes.URL);
newTemplate.set('SignedUrl', _templateRes.SignedUrl);
newTemplate.set('SentToOthers', _templateRes?.SentToOthers || false);
newTemplate.set('SendinOrder', _templateRes?.SendinOrder || false);
newTemplate.set('AutomaticReminders', _templateRes?.AutomaticReminders || false);
newTemplate.set('RemindOnceInEvery', _templateRes?.RemindOnceInEvery || 5);
newTemplate.set('IsEnableOTP', _templateRes?.IsEnableOTP || false);
newTemplate.set('AllowModifications', _templateRes?.AllowModifications || false);
newTemplate.set('Signers', signers);
newTemplate.set('ExtUserPtr', {
__type: 'Pointer',
className: 'contracts_Users',
objectId: _templateRes.ExtUserPtr.objectId,
});
newTemplate.set('CreatedBy', {
__type: 'Pointer',
className: '_User',
objectId: _templateRes.CreatedBy.objectId,
});
if (_templateRes?.Note) {
newTemplate.set('Note', _templateRes?.Note);
}
if (_templateRes?.Description) {
newTemplate.set('Description', _templateRes?.Description);
}
if (_templateRes?.Placeholders?.length > 0) {
newTemplate.set('Placeholders', _templateRes.Placeholders);
}
if (_templateRes?.SignatureType?.length > 0) {
newTemplate.set('SignatureType', _templateRes?.SignatureType);
}
if (_templateRes?.NotifyOnSignatures !== undefined) {
newTemplate.set('NotifyOnSignatures', _templateRes.NotifyOnSignatures);
}
if (_templateRes?.SharedWith?.length > 0) {
newTemplate.set('SharedWith', _templateRes.SharedWith);
}
if (_templateRes?.IsPublic) {
newTemplate.set('IsPublic', _templateRes?.IsPublic);
}
if (_templateRes?.PublicRole?.length > 0) {
newTemplate.set('PublicRole', _templateRes?.PublicRole);
}
if (_templateRes?.IsTourEnabled) {
newTemplate.set('IsTourEnabled', _templateRes?.IsTourEnabled);
}
if (_templateRes?.Bcc?.length) {
newTemplate.set('Bcc', _templateRes?.Bcc);
}
const OriginIp = _templateRes?.OriginIp || request?.headers?.['x-real-ip'] || '';
if (OriginIp) {
newTemplate.set('OriginIp', OriginIp);
}
if (_templateRes?.RedirectUrl) {
newTemplate.set('RedirectUrl', _templateRes?.RedirectUrl);
}
const acl = templateRes.getACL();
if (acl) {
newTemplate.setACL(acl);
}
const newTemplateRes = await newTemplate.save(null, { useMasterKey: true });
const _newTemplateRes = JSON.parse(JSON.stringify(newTemplateRes));
return _newTemplateRes;
} else {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
'You cannot create duplicate of this template.'
);
}
} catch (err) {
console.log('err while creating duplicate', err);
throw err;
}
}
}