Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions apps/OpenSign/src/constant/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2980,34 +2980,34 @@ export const saveLanguageInLocal = (i18n) => {
const detectedLanguage = i18n.language || "en";
localStorage.setItem("i18nextLng", detectedLanguage);
};
//function to get default signatur eof current user from `contracts_Signature` class

// function to get default signature of current user from `contracts_Signature` class
export const getDefaultSignature = async (objectId) => {
try {
const query = new Parse.Query("contracts_Signature");
query.equalTo("UserId", {
__type: "Pointer",
className: "_User",
objectId: objectId
});

const result = await query.first();
if (result) {
const res = JSON.parse(JSON.stringify(result));
const defaultSignature = res?.ImageURL
? await getBase64FromUrl(res?.ImageURL, true)
: "";
const defaultInitial = res?.Initials
? await getBase64FromUrl(res?.Initials, true)
: "";
if (objectId) {
const result = await Parse.Cloud.run("getdefaultsignature", {
userId: objectId
});
if (result) {
const res = JSON.parse(JSON.stringify(result));
const defaultSignature = res?.ImageURL
? await getBase64FromUrl(res?.ImageURL, true)
: "";
const defaultInitial = res?.Initials
? await getBase64FromUrl(res?.Initials, true)
: "";

return {
status: "success",
res: {
id: result?.id,
defaultSignature: defaultSignature,
defaultInitial: defaultInitial
}
};
return {
status: "success",
res: {
id: result?.id,
defaultSignature: defaultSignature,
defaultInitial: defaultInitial
}
};
}
} else {
return { status: "error" };
}
} catch (err) {
console.log(
Expand Down
62 changes: 20 additions & 42 deletions apps/OpenSign/src/pages/Managesign.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ const ManageSign = () => {
objectId: User.id
};
try {
const signCls = "contracts_Signature";
const signQuery = new Parse.Query(signCls);
signQuery.equalTo("UserId", userId);
const signRes = await signQuery.first();
const signRes = await Parse.Cloud.run("getdefaultsignature", {
userId: User.id
});
if (signRes) {
const res = signRes.toJSON();
setId(res.objectId);
Expand Down Expand Up @@ -226,44 +225,23 @@ const ManageSign = () => {
};

const saveEntry = async (obj) => {
const signCls = "contracts_Signature";
const User = Parse?.User?.current()?.id;
const userId = { __type: "Pointer", className: "_User", objectId: User };
if (id) {
try {
const updateSign = new Parse.Object(signCls);
updateSign.id = id;
updateSign.set("Initials", obj.initialsUrl ? obj.initialsUrl : "");
updateSign.set("ImageURL", obj.url ? obj.url : "");
updateSign.set("SignatureName", obj.name);
updateSign.set("UserId", userId);
const res = await updateSign.save();
setIsAlert({ type: "success", message: t("signature-saved-alert") });
return res;
} catch (err) {
console.log(err);
setIsAlert({ type: "danger", message: `${err.message}` });
} finally {
setIsLoader(false);
setTimeout(() => setIsAlert({}), 2000);
}
} else {
try {
const updateSign = new Parse.Object(signCls);
updateSign.set("Initials", obj.initialsUrl ? obj.initialsUrl : "");
updateSign.set("ImageURL", obj.url);
updateSign.set("SignatureName", obj.name);
updateSign.set("UserId", userId);
const res = await updateSign.save();
setIsAlert({ type: "success", message: t("signature-saved-alert") });
return res;
} catch (err) {
console.log(err);
setIsAlert({ type: "success", message: `${err.message}` });
} finally {
setIsLoader(false);
setTimeout(() => setIsAlert({}), 2000);
}
try {
const User = Parse?.User?.current()?.id;
const res = await Parse.Cloud.run("managesign", {
signature: obj.url,
userId: User,
initials: obj.initialsUrl,
id: id,
title: obj.name
});
setIsAlert({ type: "success", message: t("signature-saved-alert") });
return res;
} catch (err) {
console.log(err);
setIsAlert({ type: "danger", message: `${err.message}` });
} finally {
setIsLoader(false);
setTimeout(() => setIsAlert({}), 2000);
}
};

Expand Down
18 changes: 8 additions & 10 deletions apps/OpenSign/src/utils/widgetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ export const saveToMySign = async (widget) => {
: `${replaceSpace}__initials`;
const file = base64StringtoFile(base64, fileName);
const fileUrl = await uploadFile(file, User?.id);
// below code is used to save or update default signature, initials, stamp
const signCls = new Parse.Object("contracts_Signature");
if (widget?.defaultSignId) {
signCls.id = widget.defaultSignId;
}
const params = {
id: widget?.defaultSignId, // pass id to update existing signature/initials
userId: User.id
};
if (widget?.type === "initials") {
signCls.set("Initials", fileUrl);
params.initials = fileUrl; // save initials image url
} else if (widget?.type === "signature") {
signCls.set("ImageURL", fileUrl);
params.signature = fileUrl; // save signature image url
}
signCls.set("UserId", Parse.User.createWithoutData(User.id));
const signRes = await signCls.save();
const signRes = await Parse.Cloud.run("savesignature", params);
return { base64File: base64, id: signRes?.id };
} catch (err) {
console.log("Err while saving signature", err);
return url;
return err;
}
}
};
Expand Down
6 changes: 6 additions & 0 deletions apps/OpenSignServer/cloud/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ import addUser from './parsefunction/addUser.js';
import filterDocs from './parsefunction/filterDocs.js';
import sendDeleteUserMail from './parsefunction/sendDeleteUserMail.js';
import resetPassword from './parsefunction/resetPassword.js';
import saveSignature from './parsefunction/saveSignature.js';
import manageSign from './parsefunction/manageSign.js';
import getSignature from './parsefunction/getSignature.js';

// This afterSave function triggers after an object is added or updated in the specified class, allowing for post-processing logic.
Parse.Cloud.afterSave('contracts_Document', DocumentAftersave);
Expand Down Expand Up @@ -124,3 +127,6 @@ Parse.Cloud.define('adduser', addUser);
Parse.Cloud.define('filterdocs', filterDocs);
Parse.Cloud.define('senddeleterequest', sendDeleteUserMail);
Parse.Cloud.define('resetpassword', resetPassword);
Parse.Cloud.define('savesignature', saveSignature);
Parse.Cloud.define('managesign', manageSign);
Parse.Cloud.define('getdefaultsignature', getSignature);
18 changes: 18 additions & 0 deletions apps/OpenSignServer/cloud/parsefunction/getSignature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default async function getSignature(request) {
const { userId } = request.params;
if (!userId) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing userId parameter.');
}
if (userId !== request.user?.id) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message 'Cannot save signature for the current user' is incorrect for a get operation. This function retrieves signatures, not saves them. The message should be 'Cannot retrieve signature for another user.' or 'You can only retrieve your own signatures.'

Suggested change
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot retrieve signature for another user.');

Copilot uses AI. Check for mistakes.
}
try {
const query = new Parse.Query('contracts_Signature');
query.equalTo('UserId', { __type: 'Pointer', className: '_User', objectId: userId });
const result = await query.first({ useMasterKey: true });
return result;
} catch (err) {
console.error('Error fetching signature:', err);
throw err;
}
}
28 changes: 28 additions & 0 deletions apps/OpenSignServer/cloud/parsefunction/manageSign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default async function manageSign(request) {
const { signature, userId, initials, id, title } = request.params;

if (!userId) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing userId parameter.');
}
if (userId !== request.user?.id) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message 'Cannot save signature for the current user' is misleading. When userId !== request.user?.id, the user is attempting to save a signature for a different user (not the current user), which should be prevented. The message should be 'Cannot save signature for another user.' or 'You can only save signatures for yourself.'

Suggested change
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'You can only save signatures for yourself.');

Copilot uses AI. Check for mistakes.
}
const userPtr = { __type: 'Pointer', className: '_User', objectId: userId };
try {
const signatureCls = new Parse.Object('contracts_Signature');
if (id) {
signatureCls.id = id;
}
signatureCls.set('Initials', initials ? initials : '');
signatureCls.set('ImageURL', signature ? signature : '');
signatureCls.set('SignatureName', title ? title : '');
if (userPtr) {
signatureCls.set('UserId', userPtr);
}
Comment on lines +19 to +21
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 'if (userPtr)' is unnecessary because userPtr is defined unconditionally on line 10. Since userId is already validated to be non-null on lines 4-6, userPtr will always exist. This check should be removed and 'UserId' should always be set.

Suggested change
if (userPtr) {
signatureCls.set('UserId', userPtr);
}
signatureCls.set('UserId', userPtr);

Copilot uses AI. Check for mistakes.
const signRes = await signatureCls.save(null, { useMasterKey: true });
return signRes;
} catch (err) {
console.error('Error saving signature:', err);
throw err;
}
}
33 changes: 33 additions & 0 deletions apps/OpenSignServer/cloud/parsefunction/saveSignature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default async function saveSignature(request) {
const { signature, userId, initials, id, title } = request.params;

if (!userId) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing userId parameter.');
}
if (userId !== request.user?.id) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message 'Cannot save signature for the current user' is misleading. When userId !== request.user?.id, the user is attempting to save a signature for a different user (not the current user), which should be prevented. The message should be 'Cannot save signature for another user.' or 'You can only save signatures for yourself.'

Suggested change
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Cannot save signature for the current user.');
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'You can only save signatures for yourself.');

Copilot uses AI. Check for mistakes.
}
const userPtr = { __type: 'Pointer', className: '_User', objectId: userId };
try {
const signatureCls = new Parse.Object('contracts_Signature');
if (id) {
signatureCls.id = id;
}
if (initials) {
signatureCls.set('Initials', initials);
}
if (signature) {
signatureCls.set('ImageURL', signature);
}
if (title) {
signatureCls.set('SignatureName', title);
}
if (userPtr) {
signatureCls.set('UserId', userPtr);
}
Comment on lines +25 to +27
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 'if (userPtr)' is unnecessary because userPtr is defined unconditionally on line 10. Since userId is already validated to be non-null on lines 4-6, userPtr will always exist. This check should be removed and 'UserId' should always be set.

Suggested change
if (userPtr) {
signatureCls.set('UserId', userPtr);
}
signatureCls.set('UserId', userPtr);

Copilot uses AI. Check for mistakes.
const signRes = await signatureCls.save(null, { useMasterKey: true });
return signRes;
} catch (err) {
throw err;
}
}
22 changes: 15 additions & 7 deletions apps/OpenSignServer/cloud/parsefunction/sendMailv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@ async function sendMailProvider(req, plan, monthchange) {
let mailgunClient;
let mailgunDomain;
if (smtpenable) {
transporterSMTP = createTransport({
let transporterConfig = {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT || 465,
secure: smtpsecure,
auth: {
};

// ✅ Add auth only if BOTH username & password exist
const smtpUser = process.env.SMTP_USERNAME;
const smtpPass = process.env.SMTP_PASS;

if (smtpUser && smtpPass) {
transporterConfig.auth = {
user: process.env.SMTP_USERNAME ? process.env.SMTP_USERNAME : process.env.SMTP_USER_EMAIL,
pass: process.env.SMTP_PASS,
},
});
pass: smtpPass,
};
}
transporterSMTP = createTransport(transporterConfig);
} else {
if (mailgunApiKey) {
const mailgun = new Mailgun(formData);
Expand Down Expand Up @@ -185,7 +193,7 @@ async function sendMailProvider(req, plan, monthchange) {
}
}
} catch (err) {
console.log('err in sendmailv3', err);
console.log(`Error in sendmailv3: ${err}`);
if (fs.existsSync(testPdf)) {
try {
fs.unlinkSync(testPdf);
Expand Down Expand Up @@ -236,7 +244,7 @@ async function sendMailProvider(req, plan, monthchange) {
}
}
} catch (err) {
console.log('err in sendmailv3', err);
console.log(`Error in sendmailv3: ${err}`);
if (err) {
return { status: 'error' };
}
Expand Down
20 changes: 14 additions & 6 deletions apps/OpenSignServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,28 @@ let mailgunDomain;
let isMailAdapter = false;
if (smtpenable) {
try {
transporterMail = createTransport({
let transporterConfig = {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT || 465,
secure: smtpsecure,
auth: {
};

// ✅ Add auth only if BOTH username & password exist
const smtpUser = process.env.SMTP_USERNAME;
const smtpPass = process.env.SMTP_PASS;

if (smtpUser && smtpPass) {
transporterConfig.auth = {
user: process.env.SMTP_USERNAME ? process.env.SMTP_USERNAME : process.env.SMTP_USER_EMAIL,
pass: process.env.SMTP_PASS,
},
});
pass: smtpPass,
};
}
transporterMail = createTransport(transporterConfig);
await transporterMail.verify();
isMailAdapter = true;
} catch (err) {
isMailAdapter = false;
console.log('Please provide valid SMTP credentials');
console.log(`Please provide valid SMTP credentials: ${err}`);
}
} else if (process.env.MAILGUN_API_KEY) {
try {
Expand Down
Loading