mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-22 07:32:31 +02:00
Merge pull request #536 from OpenSignLabs/doc_load_drive
refactor: remove protected fields migration
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Escapes special characters in a string so it can safely be used in a RegExp.
|
||||
*/
|
||||
function escapeRegExp(str) {
|
||||
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches contracts_Document objects whose Name matches searchTerm
|
||||
* and whose CreatedBy pointer is the current user.
|
||||
*
|
||||
* @param {Parse.User} user – the logged-in Parse.User (e.g. request.user)
|
||||
* @param {string} searchTerm – substring (or full name) to match
|
||||
* @param {object} [options]
|
||||
* @param {number} [options.limit=100] – max results
|
||||
* @param {number} [options.skip=0] – offset for pagination
|
||||
* @param {boolean} [options.caseSensitive=false] – regex case sensitivity
|
||||
*/
|
||||
async function fetchDocumentsByName(
|
||||
user,
|
||||
searchTerm,
|
||||
{ limit = 300, skip = 0, caseSensitive = false } = {}
|
||||
) {
|
||||
const query = new Parse.Query('contracts_Document');
|
||||
|
||||
// 1) Filter by Name substring (case-insensitive by default)
|
||||
if (searchTerm) {
|
||||
const escaped = escapeRegExp(searchTerm);
|
||||
const pattern = `.*${escaped}.*`;
|
||||
query.matches('Name', pattern, caseSensitive ? undefined : 'i');
|
||||
}
|
||||
|
||||
// 2) Filter by CreatedBy pointer
|
||||
query.equalTo('CreatedBy', user);
|
||||
|
||||
// 3) Pagination & sorting
|
||||
query.limit(limit);
|
||||
query.skip(skip);
|
||||
// query.ascending('Name'); //sort alphabetically:
|
||||
query.include('ExtUserPtr');
|
||||
query.include('ExtUserPtr.TenantId');
|
||||
query.include('Signers');
|
||||
query.notEqualTo('IsArchive', true);
|
||||
query.descending('updatedAt');
|
||||
query.exclude('AuditTrail');
|
||||
query.notEqualTo('Type', 'Folder');
|
||||
try {
|
||||
return await query.find({ useMasterKey: true });
|
||||
} catch (err) {
|
||||
console.error('Error fetching contracts_Document by Name:', err);
|
||||
// Wrap low-level or network errors in a script-level error
|
||||
throw new Parse.Error(
|
||||
Parse.Error.SCRIPT_FAILED,
|
||||
'Unable to retrieve your documents at this time'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default async function filterDocs(request) {
|
||||
const { searchTerm = '', limit, skip, caseSensitive } = request.params;
|
||||
if (!request.user) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.');
|
||||
}
|
||||
if (typeof searchTerm !== 'string') {
|
||||
throw new Parse.Error(Parse.Error.INVALID_PARAMETER, 'searchTerm must be a string');
|
||||
}
|
||||
|
||||
try {
|
||||
const docs = await fetchDocumentsByName(request.user, searchTerm, {
|
||||
limit,
|
||||
skip,
|
||||
caseSensitive,
|
||||
});
|
||||
return docs;
|
||||
} catch (error) {
|
||||
// handle error
|
||||
console.log('err while filtering doc', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ export default async function generateCertificatebydocId(req) {
|
||||
location: 'n/a',
|
||||
name: eSignName,
|
||||
contactInfo: eSigncontact,
|
||||
signatureLength: 15000,
|
||||
signatureLength: 16000,
|
||||
});
|
||||
const pdfWithPlaceholderBytes = await certificatePdf.save();
|
||||
const CertificateBuffer = Buffer.from(pdfWithPlaceholderBytes);
|
||||
|
||||
@@ -5,7 +5,6 @@ export default async function getDrive(request) {
|
||||
const appId = process.env.APP_ID;
|
||||
const limit = request.params.limit;
|
||||
const skip = request.params.skip;
|
||||
const classUrl = serverUrl + '/classes/contracts_Document';
|
||||
const docId = request.params.docId;
|
||||
try {
|
||||
const userRes = await axios.get(serverUrl + '/users/me', {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import crypto from 'node:crypto';
|
||||
export default async function loginUser(request) {
|
||||
const username = request.params.email;
|
||||
const password = request.params.password;
|
||||
|
||||
if (username && password) {
|
||||
try {
|
||||
// Pass the username and password to logIn function
|
||||
const user = await Parse.User.logIn(username, password);
|
||||
// console.log('user ', user);
|
||||
if (user) {
|
||||
const _user = user?.toJSON();
|
||||
return {
|
||||
..._user,
|
||||
};
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'user not found.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err in login user', err);
|
||||
throw err;
|
||||
}
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.PASSWORD_MISSING, 'username/password is missing.');
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ async function sendMailsaveCertifcate(doc, pfx, isCustomMail, mailProvider, file
|
||||
location: 'n/a',
|
||||
name: eSignName,
|
||||
contactInfo: eSigncontact,
|
||||
signatureLength: 15000,
|
||||
signatureLength: 16000,
|
||||
});
|
||||
const pdfWithPlaceholderBytes = await certificatePdf.save();
|
||||
const CertificateBuffer = Buffer.from(pdfWithPlaceholderBytes);
|
||||
@@ -408,7 +408,7 @@ async function PDF(req) {
|
||||
location: 'n/a',
|
||||
name: eSignName,
|
||||
contactInfo: eSigncontact,
|
||||
signatureLength: 15000,
|
||||
signatureLength: 16000,
|
||||
});
|
||||
const pdfWithPlaceholderBytes = await pdfDoc.save();
|
||||
PdfBuffer = Buffer.from(pdfWithPlaceholderBytes);
|
||||
|
||||
@@ -96,6 +96,10 @@ export default function reportJson(id, userId) {
|
||||
'Placeholders',
|
||||
'SignedUrl',
|
||||
'TemplateId',
|
||||
'RequestBody',
|
||||
'RequestSubject',
|
||||
'ExtUserPtr.TenantId.RequestBody',
|
||||
'ExtUserPtr.TenantId.RequestSubject',
|
||||
],
|
||||
};
|
||||
// completed documents report
|
||||
@@ -227,6 +231,10 @@ export default function reportJson(id, userId) {
|
||||
'Placeholders',
|
||||
'SignedUrl',
|
||||
'TemplateId',
|
||||
'RequestBody',
|
||||
'RequestSubject',
|
||||
'ExtUserPtr.TenantId.RequestBody',
|
||||
'ExtUserPtr.TenantId.RequestSubject',
|
||||
],
|
||||
};
|
||||
// Recent signature requests report show on dashboard
|
||||
|
||||
@@ -54,6 +54,9 @@ export default async function updatePreferences(request) {
|
||||
if (request.params.Is12HourTime !== undefined) {
|
||||
newOrg.set('Is12HourTime', request.params.Is12HourTime);
|
||||
}
|
||||
if (request.params.IsLTVEnabled !== undefined) {
|
||||
newOrg.set('IsLTVEnabled', request.params.IsLTVEnabled);
|
||||
}
|
||||
const updateUserRes = await newOrg.save(null, { useMasterKey: true });
|
||||
if (updateUserRes) {
|
||||
const _updateUserRes = JSON.parse(JSON.stringify(updateUserRes));
|
||||
|
||||
Reference in New Issue
Block a user