From 76b90f9bc052ea0811b7786f0b826df38639c9a4 Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Wed, 7 Aug 2024 13:45:49 +0530 Subject: [PATCH] fix: something went wrong error in signpdf --- apps/OpenSign/src/components/AddTeam.js | 4 +- apps/OpenSign/src/components/AddUser.js | 4 +- .../src/components/dashboard/DashboardCard.js | 16 ++----- apps/OpenSign/src/constant/Utils.js | 48 ++++++------------- apps/OpenSign/src/json/plansArr.js | 8 ++++ apps/OpenSign/src/layout/HomeLayout.js | 5 +- apps/OpenSign/src/pages/AddAdmin.js | 5 +- apps/OpenSign/src/pages/GuestLogin.js | 3 +- apps/OpenSign/src/pages/Login.js | 14 ++---- apps/OpenSign/src/pages/Opensigndrive.js | 5 +- apps/OpenSign/src/pages/PdfRequestFiles.js | 15 ++---- apps/OpenSign/src/pages/Pgsignup.js | 9 +--- apps/OpenSign/src/pages/PlaceHolderSign.js | 3 +- apps/OpenSign/src/pages/SSOVerify.js | 5 +- apps/OpenSign/src/pages/Signup.js | 5 +- apps/OpenSign/src/pages/SignyourselfPdf.js | 2 +- .../OpenSign/src/pages/TemplatePlaceholder.js | 14 ++---- apps/OpenSign/src/pages/UserList.js | 6 +-- apps/OpenSign/src/pages/UserProfile.js | 4 +- apps/OpenSign/src/pages/Webhook.js | 4 +- .../src/primitives/GetReportDisplay.js | 5 +- .../cloud/parsefunction/GetPublicTemplate.js | 15 ++++-- .../cloud/parsefunction/getUserDetails.js | 48 +++++++++++++------ apps/OpenSignServer/index.js | 10 ++-- apps/OpenSignServer/runmigrate.js | 37 -------------- 25 files changed, 106 insertions(+), 188 deletions(-) delete mode 100644 apps/OpenSignServer/runmigrate.js diff --git a/apps/OpenSign/src/components/AddTeam.js b/apps/OpenSign/src/components/AddTeam.js index a76ac98f5..d5f205285 100644 --- a/apps/OpenSign/src/components/AddTeam.js +++ b/apps/OpenSign/src/components/AddTeam.js @@ -125,10 +125,10 @@ const AddTeam = (props) => { }; return ( -
+
{isLoader && ( - <div className="fixed inset-0 flex justify-center items-center bg-black bg-opacity-30 z-50 rounded-box"> + <div className="absolute w-full h-full inset-0 flex justify-center items-center bg-base-content/30 z-50"> <Loader /> </div> )} diff --git a/apps/OpenSign/src/components/AddUser.js b/apps/OpenSign/src/components/AddUser.js index 2413ad30f..b74110c26 100644 --- a/apps/OpenSign/src/components/AddUser.js +++ b/apps/OpenSign/src/components/AddUser.js @@ -48,9 +48,7 @@ const AddUser = (props) => { }; const checkUserExist = async () => { try { - const res = await Parse.Cloud.run("getUserDetails", { - email: formdata.email - }); + const res = await Parse.Cloud.run("getUserDetails"); if (res) { return true; } else { diff --git a/apps/OpenSign/src/components/dashboard/DashboardCard.js b/apps/OpenSign/src/components/dashboard/DashboardCard.js index f8017ac91..fce726af0 100644 --- a/apps/OpenSign/src/components/dashboard/DashboardCard.js +++ b/apps/OpenSign/src/components/dashboard/DashboardCard.js @@ -23,17 +23,12 @@ const DashboardCard = (props) => { sessionToken: localStorage.getItem("accesstoken") }; let body = {}; - let currentUser; - let currentUser1 = Parse.User.current(); - currentUser = currentUser1.id; let res; if (localStorage.getItem("Extand_Class")) { let data = JSON.parse(localStorage.getItem("Extand_Class")); res = data[0]; } else { - res = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + res = await Parse.Cloud.run("getUserDetails"); if (res) res = res.toJSON(); } if (res) { @@ -94,9 +89,7 @@ const DashboardCard = (props) => { let data = JSON.parse(localStorage.getItem("Extand_Class")); resr = data[0]; } else { - resr = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + resr = await Parse.Cloud.run("getUserDetails"); if (resr) resr = resr.toJSON(); } @@ -218,15 +211,12 @@ const DashboardCard = (props) => { if (restr.includes("#")) { try { - const currentUser = Parse.User.current(); let res; if (localStorage.getItem("Extand_Class")) { let data = JSON.parse(localStorage.getItem("Extand_Class")); res = data[0]; } else { - let resr = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + let resr = await Parse.Cloud.run("getUserDetails"); if (res) res = resr.toJSON(); } diff --git a/apps/OpenSign/src/constant/Utils.js b/apps/OpenSign/src/constant/Utils.js index da49cf199..5453c4461 100644 --- a/apps/OpenSign/src/constant/Utils.js +++ b/apps/OpenSign/src/constant/Utils.js @@ -6,6 +6,7 @@ import Parse from "parse"; import { appInfo } from "./appinfo"; import { saveAs } from "file-saver"; import printModule from "print-js"; +import { validplan } from "../json/plansArr"; export const fontsizeArr = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]; export const fontColorArr = ["red", "black", "blue", "yellow"]; @@ -90,13 +91,7 @@ export async function checkIsSubscribedTeam() { if (res.plan === "freeplan") { return false; } else if (res.billingDate) { - const plan = - res.plan === "team-weekly" || - res.plan === "team-yearly" || - res.plan === "teams-monthly" || - res.plan === "teams-yearly" || - res.plan === "enterprise-monthly" || - res.plan === "enterprise-yearly"; + const plan = validplan[res.plan] || false; if (plan && new Date(res.billingDate) > new Date()) { return true; } else { @@ -192,32 +187,19 @@ export const pdfNewWidthFun = (divRef) => { }; //`contractUsers` function is used to get contract_User details -export const contractUsers = async (email) => { - const data = { - email: email - }; - const userDetails = await axios - .post(`${localStorage.getItem("baseUrl")}functions/getUserDetails`, data, { - headers: { - "Content-Type": "application/json", - "X-Parse-Application-Id": localStorage.getItem("parseAppId"), - sessionToken: localStorage.getItem("accesstoken") - } - }) - .then((Listdata) => { - const json = Listdata.data; - let data = []; - if (json && json.result) { - data.push(json.result); - } - return data; - }) - .catch((err) => { - console.log("Err in getUserDetails cloud function", err); - return "Error: Something went wrong!"; - }); - - return userDetails; +export const contractUsers = async () => { + try { + const userDetails = await Parse.Cloud.run("getUserDetails"); + let data = []; + if (userDetails) { + const json = JSON.parse(JSON.stringify(userDetails)); + data.push(json); + } + return data; + } catch (err) { + console.log("Err in getUserDetails cloud function", err); + return "Error: Something went wrong!"; + } }; //function for resize image and update width and height for mulitisigners diff --git a/apps/OpenSign/src/json/plansArr.js b/apps/OpenSign/src/json/plansArr.js index e3f8d7691..77a573e8a 100644 --- a/apps/OpenSign/src/json/plansArr.js +++ b/apps/OpenSign/src/json/plansArr.js @@ -163,4 +163,12 @@ const plans = [ } ]; +export const validplan = { + "team-weekly": true, + "team-yearly": true, + "teams-monthly": true, + "teams-yearly": true, + "enterprise-monthly": true, + "enterprise-yearly": true +}; export default plans; diff --git a/apps/OpenSign/src/layout/HomeLayout.js b/apps/OpenSign/src/layout/HomeLayout.js index 89f748c31..57c421e59 100644 --- a/apps/OpenSign/src/layout/HomeLayout.js +++ b/apps/OpenSign/src/layout/HomeLayout.js @@ -212,10 +212,7 @@ const HomeLayout = () => { }; async function checkTourStatus() { - const currentUser = Parse.User.current(); - const cloudRes = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + const cloudRes = await Parse.Cloud.run("getUserDetails"); const res = { data: cloudRes.toJSON() }; if (res.data && res.data.TourStatus && res.data.TourStatus.length > 0) { const tourStatus = res.data.TourStatus; diff --git a/apps/OpenSign/src/pages/AddAdmin.js b/apps/OpenSign/src/pages/AddAdmin.js index 7f65feadb..546057ec2 100644 --- a/apps/OpenSign/src/pages/AddAdmin.js +++ b/apps/OpenSign/src/pages/AddAdmin.js @@ -165,10 +165,7 @@ const AddAdmin = () => { // Check extended class user role and tenentId try { const userSettings = appInfo.settings; - const currentUser = Parse.User.current(); - const extUser = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + const extUser = await Parse.Cloud.run("getUserDetails"); if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; if (!IsDisabled) { diff --git a/apps/OpenSign/src/pages/GuestLogin.js b/apps/OpenSign/src/pages/GuestLogin.js index 7b34175df..bfc8f3391 100644 --- a/apps/OpenSign/src/pages/GuestLogin.js +++ b/apps/OpenSign/src/pages/GuestLogin.js @@ -124,8 +124,9 @@ function GuestLogin() { setLoading(false); } else { let _user = user.data.result; + await Parse.User.become(_user.sessionToken); const parseId = localStorage.getItem("parseAppId"); - const contractUserDetails = await contractUsers(_user.email); + const contractUserDetails = await contractUsers(); localStorage.setItem("UserInformation", JSON.stringify(_user)); localStorage.setItem( `Parse/${parseId}/currentUser`, diff --git a/apps/OpenSign/src/pages/Login.js b/apps/OpenSign/src/pages/Login.js index 1b03909e8..88408b6cf 100644 --- a/apps/OpenSign/src/pages/Login.js +++ b/apps/OpenSign/src/pages/Login.js @@ -93,10 +93,7 @@ function Login() { // Check extended class user role and tenentId try { const userSettings = appInfo.settings; - const currentUser = Parse.User.current(); - await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }) + await Parse.Cloud.run("getUserDetails") .then(async (extUser) => { if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; @@ -279,10 +276,7 @@ function Login() { // Check extended class user role and tenentId try { const userSettings = appInfo.settings; - const currentUser = Parse.User.current(); - await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }) + await Parse.Cloud.run("getUserDetails") .then(async (extUser) => { if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; @@ -408,9 +402,7 @@ function Login() { localStorage.setItem("profileImg", ""); } const userSettings = appInfo.settings; - await Parse.Cloud.run("getUserDetails", { - email: _user.email - }).then(async (extUser) => { + await Parse.Cloud.run("getUserDetails").then(async (extUser) => { if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; if (!IsDisabled) { diff --git a/apps/OpenSign/src/pages/Opensigndrive.js b/apps/OpenSign/src/pages/Opensigndrive.js index 1dc2a8de6..f675b0ea5 100644 --- a/apps/OpenSign/src/pages/Opensigndrive.js +++ b/apps/OpenSign/src/pages/Opensigndrive.js @@ -496,10 +496,7 @@ function Opensigndrive() { }; //function to use check tour status of open sign drive async function checkTourStatus() { - const currentUser = Parse.User.current(); - const cloudRes = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + const cloudRes = await Parse.Cloud.run("getUserDetails"); const res = { data: cloudRes.toJSON() }; if (res.data && res.data.TourStatus && res.data.TourStatus.length > 0) { const tourStatus = res.data.TourStatus; diff --git a/apps/OpenSign/src/pages/PdfRequestFiles.js b/apps/OpenSign/src/pages/PdfRequestFiles.js index ecde27342..48de2bcea 100644 --- a/apps/OpenSign/src/pages/PdfRequestFiles.js +++ b/apps/OpenSign/src/pages/PdfRequestFiles.js @@ -551,13 +551,8 @@ function PdfRequestFiles(props) { setRequestSignTour(true); } else { //else condition to check current user exist in contracts_Users class and check tour message status - //if not then check user exist in contracts_Contactbook class and check tour message status - const localuser = localStorage.getItem( - `Parse/${localStorage.getItem("parseAppId")}/currentUser` - ); - const currentUser = JSON.parse(localuser); - const currentUserEmail = currentUser.email; - const res = await contractUsers(currentUserEmail); + //if not then check user exist in contracts_Contactbook class and check tour message statu + const res = await contractUsers(); if (res === "Error: Something went wrong!") { setHandleError("Error: Something went wrong!"); } else if (res[0] && res?.length) { @@ -869,8 +864,7 @@ function PdfRequestFiles(props) { //get ExistUserPtr object id of user class to get tenantDetails const objectId = pdfDetails?.[0]?.ExtUserPtr?.UserId?.objectId; //get ExistUserPtr email to get userDetails - const currentUserEmail = pdfDetails?.[0]?.ExtUserPtr?.Email; - const res = await contractUsers(currentUserEmail); + const res = await contractUsers(); let activeMailAdapter = ""; if (res === "Error: Something went wrong!") { setHandleError("Error: Something went wrong!"); @@ -1546,7 +1540,8 @@ function PdfRequestFiles(props) { } else { let _user = user.data.result; const parseId = localStorage.getItem("parseAppId"); - const contractUserDetails = await contractUsers(_user.email); + await Parse.User.become(_user.sessionToken); + const contractUserDetails = await contractUsers(); localStorage.setItem("UserInformation", JSON.stringify(_user)); localStorage.setItem( `Parse/${parseId}/currentUser`, diff --git a/apps/OpenSign/src/pages/Pgsignup.js b/apps/OpenSign/src/pages/Pgsignup.js index 7e5c97637..e1ce4ef89 100644 --- a/apps/OpenSign/src/pages/Pgsignup.js +++ b/apps/OpenSign/src/pages/Pgsignup.js @@ -71,9 +71,7 @@ const PgSignUp = () => { if (res) { localStorage.removeItem("userDetails"); try { - const extUser = await Parse.Cloud.run("getUserDetails", { - email: userDetails.email - }); + const extUser = await Parse.Cloud.run("getUserDetails"); const userRole = extUser?.get("UserRole"); const _currentRole = userRole; const _role = _currentRole.replace("contracts_", ""); @@ -230,10 +228,7 @@ const PgSignUp = () => { // Check extended class user role and tenentId try { const userSettings = appInfo.settings; - const currentUser = Parse.User.current(); - const extUser = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + const extUser = await Parse.Cloud.run("getUserDetails"); if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; if (!IsDisabled) { diff --git a/apps/OpenSign/src/pages/PlaceHolderSign.js b/apps/OpenSign/src/pages/PlaceHolderSign.js index 675868847..dd2a50de2 100644 --- a/apps/OpenSign/src/pages/PlaceHolderSign.js +++ b/apps/OpenSign/src/pages/PlaceHolderSign.js @@ -404,8 +404,7 @@ function PlaceHolderSign() { }; setIsLoading(loadObj); } - const currentUserEmail = documentData[0]?.ExtUserPtr?.Email; - const res = await contractUsers(currentUserEmail); + const res = await contractUsers(); if (res === "Error: Something went wrong!") { const loadObj = { isLoad: false diff --git a/apps/OpenSign/src/pages/SSOVerify.js b/apps/OpenSign/src/pages/SSOVerify.js index b2ab6701d..2e8311b3e 100644 --- a/apps/OpenSign/src/pages/SSOVerify.js +++ b/apps/OpenSign/src/pages/SSOVerify.js @@ -149,10 +149,7 @@ const SSOVerify = () => { // Check extended class user role and tenentId try { const userSettings = appInfo.settings; - const currentUser = Parse.User.current(); - await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }) + await Parse.Cloud.run("getUserDetails") .then(async (extUser) => { if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; diff --git a/apps/OpenSign/src/pages/Signup.js b/apps/OpenSign/src/pages/Signup.js index 916360548..a06026612 100644 --- a/apps/OpenSign/src/pages/Signup.js +++ b/apps/OpenSign/src/pages/Signup.js @@ -192,10 +192,7 @@ const Signup = () => { // Check extended class user role and tenentId try { const userSettings = appInfo.settings; - const currentUser = Parse.User.current(); - await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }) + await Parse.Cloud.run("getUserDetails") .then(async (extUser) => { if (extUser) { const IsDisabled = extUser?.get("IsDisabled") || false; diff --git a/apps/OpenSign/src/pages/SignyourselfPdf.js b/apps/OpenSign/src/pages/SignyourselfPdf.js index 93b9591e7..bc3c20383 100644 --- a/apps/OpenSign/src/pages/SignyourselfPdf.js +++ b/apps/OpenSign/src/pages/SignyourselfPdf.js @@ -293,7 +293,7 @@ function SignYourSelf() { setHandleError("Error: Something went wrong!"); setIsLoading(loadObj); }); - const contractUsersRes = await contractUsers(jsonSender.email); + const contractUsersRes = await contractUsers(); if (contractUsersRes === "Error: Something went wrong!") { const loadObj = { isLoad: false diff --git a/apps/OpenSign/src/pages/TemplatePlaceholder.js b/apps/OpenSign/src/pages/TemplatePlaceholder.js index 68e39dfc7..36da3b58f 100644 --- a/apps/OpenSign/src/pages/TemplatePlaceholder.js +++ b/apps/OpenSign/src/pages/TemplatePlaceholder.js @@ -153,14 +153,6 @@ const TemplatePlaceholder = () => { const [fontColor, setFontColor] = useState(); const [zoomPercent, setZoomPercent] = useState(0); const [scale, setScale] = useState(1); - const senderUser = - localStorage.getItem( - `Parse/${localStorage.getItem("parseAppId")}/currentUser` - ) && - localStorage.getItem( - `Parse/${localStorage.getItem("parseAppId")}/currentUser` - ); - const jsonSender = JSON.parse(senderUser); useEffect(() => { fetchTemplate(); @@ -317,7 +309,7 @@ const TemplatePlaceholder = () => { setHandleError("Error: Something went wrong!"); } } - const res = await contractUsers(jsonSender.email); + const res = await contractUsers(); if (res[0] && res.length) { setSignerUserId(res[0].objectId); setCurrentEmail(res[0].Email); @@ -1544,8 +1536,8 @@ const TemplatePlaceholder = () => { /> </div> ) : ( - <div className="w-[23%] bg-[#FFFFFF] min-h-screen overflow-y-auto hide-scrollbar"> - <div className={`max-h-screen`}> + <div className="w-[23%] bg-base-100 min-h-screen overflow-y-auto hide-scrollbar"> + <div className="max-h-screen"> <SignerListPlace isMailSend={isMailSend} signerPos={signerPos} diff --git a/apps/OpenSign/src/pages/UserList.js b/apps/OpenSign/src/pages/UserList.js index c0351acc3..2df84f6ae 100644 --- a/apps/OpenSign/src/pages/UserList.js +++ b/apps/OpenSign/src/pages/UserList.js @@ -221,9 +221,9 @@ const UserList = () => { <thead className="text-[14px]"> <tr className="border-y-[1px]"> {heading?.map((item, index) => ( - <React.Fragment key={index}> - <th className="px-4 py-2">{item}</th> - </React.Fragment> + <th key={index} className="px-4 py-2"> + {item} + </th> ))} </tr> </thead> diff --git a/apps/OpenSign/src/pages/UserProfile.js b/apps/OpenSign/src/pages/UserProfile.js index df48555cf..578ad5bd2 100644 --- a/apps/OpenSign/src/pages/UserProfile.js +++ b/apps/OpenSign/src/pages/UserProfile.js @@ -313,9 +313,7 @@ function UserProfile() { ) : ( <div className="flex justify-center items-center w-full relative"> {userNameError && ( - <div - className={`z-[1000] fixed top-[50%] transform border-[1px] text-sm border-[#f0a8a8] bg-[#f4bebe] text-[#c42121] rounded py-[.75rem] px-[1.25rem]`} - > + <div className="z-[1000] fixed top-[50%] transform border-[1px] text-sm border-[#f0a8a8] bg-[#f4bebe] text-[#c42121] rounded py-[.75rem] px-[1.25rem]"> {userNameError} </div> )} diff --git a/apps/OpenSign/src/pages/Webhook.js b/apps/OpenSign/src/pages/Webhook.js index 9b6668dad..92a2f3d5a 100644 --- a/apps/OpenSign/src/pages/Webhook.js +++ b/apps/OpenSign/src/pages/Webhook.js @@ -32,14 +32,12 @@ function Webhook() { }, []); const fetchWebhook = async () => { - const email = Parse.User.current().getEmail(); if (isEnableSubscription) { const getIsSubscribe = await checkIsSubscribed(); setIsSubscribe(getIsSubscribe); } - const params = { email: email }; try { - const extRes = await Parse.Cloud.run("getUserDetails", params); + const extRes = await Parse.Cloud.run("getUserDetails"); if (extRes) { setWebhook(extRes.get("Webhook")); } diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.js index 533fbc671..9d2ffc9c4 100644 --- a/apps/OpenSign/src/primitives/GetReportDisplay.js +++ b/apps/OpenSign/src/primitives/GetReportDisplay.js @@ -526,10 +526,7 @@ const ReportTable = (props) => { }; async function checkTourStatus() { - const currentUser = Parse.User.current(); - const cloudRes = await Parse.Cloud.run("getUserDetails", { - email: currentUser.get("email") - }); + const cloudRes = await Parse.Cloud.run("getUserDetails"); const res = { data: cloudRes.toJSON() }; if (res.data && res.data.TourStatus && res.data.TourStatus.length > 0) { const tourStatus = res.data.TourStatus; diff --git a/apps/OpenSignServer/cloud/parsefunction/GetPublicTemplate.js b/apps/OpenSignServer/cloud/parsefunction/GetPublicTemplate.js index 684bd39e6..a33d04bc0 100644 --- a/apps/OpenSignServer/cloud/parsefunction/GetPublicTemplate.js +++ b/apps/OpenSignServer/cloud/parsefunction/GetPublicTemplate.js @@ -22,11 +22,16 @@ async function GetPublicTemplate(request) { templatQuery.notEqualTo('IsArchive', true); const getTemplate = await templatQuery.find({ useMasterKey: true }); - const extend_Res = await Parse.Cloud.run('getUserDetails', { - email: user.get('email'), - }); - if (extend_Res) { - return { template: getTemplate, user: user, extend_User: extend_Res }; + const extcls = new Parse.Query('contracts_Users'); + extcls.equalTo('email', user.get('email')); + const res = await extcls.first({ useMasterKey: true }); + if (res) { + const _res = JSON.parse(JSON.stringify(_res)); + return { + template: getTemplate, + user: user, + extend_User: { Tagline: _res?.Tagline || '', SearchIndex: _res?.SearchIndex || '' }, + }; } else { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Template not found'); } diff --git a/apps/OpenSignServer/cloud/parsefunction/getUserDetails.js b/apps/OpenSignServer/cloud/parsefunction/getUserDetails.js index 286a18c6e..39eb19c5f 100644 --- a/apps/OpenSignServer/cloud/parsefunction/getUserDetails.js +++ b/apps/OpenSignServer/cloud/parsefunction/getUserDetails.js @@ -1,19 +1,39 @@ async function getUserDetails(request) { - try { - const userId = request.params.userId; - const userQuery = new Parse.Query('contracts_Users'); - userQuery.equalTo('Email', request.params.email); - userQuery.include('TenantId'); - userQuery.include('UserId'); - userQuery.exclude('google_refresh_token') - if (userId) { - userQuery.equalTo('CreatedBy', { __type: 'Pointer', className: '_User', objectId: userId }); + const reqEmail = request.params.email; + if (reqEmail || request.user) { + try { + const userId = request.params.userId; + const userQuery = new Parse.Query('contracts_Users'); + if (request?.user) { + const email = request.user.get('email'); + userQuery.equalTo('Email', email); + } else { + userQuery.equalTo('Email', reqEmail); + } + userQuery.include('TenantId'); + userQuery.include('UserId'); + userQuery.exclude('google_refresh_token'); + if (userId) { + userQuery.equalTo('CreatedBy', { __type: 'Pointer', className: '_User', objectId: userId }); + } + const res = await userQuery.first({ useMasterKey: true }); + if (res) { + if (reqEmail) { + return { objectId: res.id }; + } else { + return res; + } + } else { + return ''; + } + } catch (err) { + console.log('Err ', err); + const code = err?.code || 400; + const msg = err?.message || 'Something went wrong.'; + throw new Parse.Error(code, msg); } - const res = await userQuery.first({ useMasterKey: true }); - return res; - } catch (err) { - console.log('Err ', err); - return err; + } else { + throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User is not authenticated.'); } } export default getUserDetails; diff --git a/apps/OpenSignServer/index.js b/apps/OpenSignServer/index.js index 670b7d64c..2f4208db2 100644 --- a/apps/OpenSignServer/index.js +++ b/apps/OpenSignServer/index.js @@ -17,7 +17,7 @@ import { exec } from 'child_process'; import { createTransport } from 'nodemailer'; import { app as v1 } from './cloud/customRoute/v1/apiV1.js'; import { PostHog } from 'posthog-node'; -import { smtpenable, smtpsecure, useLocal } from './Utils.js'; +import { cloudServerUrl, smtpenable, smtpsecure, useLocal } from './Utils.js'; import { SSOAuth } from './auth/authadapter.js'; let fsAdapter; if (useLocal !== 'true') { @@ -98,9 +98,9 @@ export const config = { maxUploadSize: '30mb', masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret! masterKeyIps: ['0.0.0.0/0', '::/0'], // '::1' - serverURL: 'http://localhost:8080/app', // Don't forget to change to https if needed + serverURL: cloudServerUrl, // Don't forget to change to https if needed verifyUserEmails: false, - publicServerURL: process.env.SERVER_URL || 'http://localhost:8080/app', + publicServerURL: process.env.SERVER_URL || cloudServerUrl, // Your apps name. This will appear in the subject and body of the emails that are sent. appName: 'Opensign', allowClientClassCreation: false, @@ -219,8 +219,8 @@ if (!process.env.TESTING) { // console.log('isWindows', isWindows); const migrate = isWindows - ? `set APPLICATION_ID=${process.env.APP_ID}&& set SERVER_URL=http://localhost:8080/app&& set MASTER_KEY=${process.env.MASTER_KEY}&& npx parse-dbtool migrate` - : `APPLICATION_ID=${process.env.APP_ID} SERVER_URL=http://localhost:8080/app MASTER_KEY=${process.env.MASTER_KEY} npx parse-dbtool migrate`; + ? `set APPLICATION_ID=${process.env.APP_ID}&& set SERVER_URL=${cloudServerUrl}&& set MASTER_KEY=${process.env.MASTER_KEY}&& npx parse-dbtool migrate` + : `APPLICATION_ID=${process.env.APP_ID} SERVER_URL=${cloudServerUrl} MASTER_KEY=${process.env.MASTER_KEY} npx parse-dbtool migrate`; exec(migrate, (error, stdout, stderr) => { if (error) { console.error(`Error: ${error.message}`); diff --git a/apps/OpenSignServer/runmigrate.js b/apps/OpenSignServer/runmigrate.js deleted file mode 100644 index 1757b0e1b..000000000 --- a/apps/OpenSignServer/runmigrate.js +++ /dev/null @@ -1,37 +0,0 @@ -// const { exec } = require('child_process'); -import { exec } from 'child_process'; - -const migrate = - 'APPLICATION_ID=legadranaxn SERVER_URL=http://localhost:8080/app MASTER_KEY=XnAwPDRQQyMr npx parse-dbtool migrate'; -// `APPLICATION_ID=${process.env.APP_ID} SERVER_URL=${process.env.SERVER_URL} MASTER_KEY=${process.env.MASTER_KEY} npx parse-dbtool migrate`; - -exec(migrate, (error, stdout, stderr) => { - if (error) { - console.error(`Error: ${error.message}`); - return; - } - - if (stderr) { - console.error(`Error: ${stderr}`); - return; - } - - console.log(`Command output: ${stdout}`); -}); - -// const seeder = -// 'APPLICATION_ID=legadranaxn SERVER_URL=http://localhost:8080/app MASTER_KEY=XnAwPDRQQyMr npx parse-dbtool seed'; - -// exec(seeder, (error, stdout, stderr) => { -// if (error) { -// console.error(`Error: ${error.message}`); -// return; -// } - -// if (stderr) { -// console.error(`Error: ${stderr}`); -// return; -// } - -// console.log(`Command output: ${stdout}`); -// });