🔥 The free & Open Source DocuSign alternative
JavaScript digital-signaturedocument-signingdocusign-alternativedocusign-freee-signatureelectronic-signatureelectronic-signaturesesignesignaturehacktoberfestjavascriptlegaltechmongodbnodejsopen-sourcepdf-signpdf-signaturereactjsself-hostedsign-pdf-files
add getuserId cloud function, fix add signer err and change in start command
prafullnavkar-nxg71001efb932e
diff --git a/apps/OpenSign/package.json b/apps/OpenSign/package.jsonindex b43971733..01fadb8d2 100644--- a/apps/OpenSign/package.json+++ b/apps/OpenSign/package.json@@ -40,8 +40,7 @@"web-vitals": "^2.1.4"},"scripts": {- "start": "serve -s build",- "start-dev": "mf-cra start",+ "start": "mf-cra start","build": "CI=false && mf-cra build","test": "react-scripts test","eject": "react-scripts eject",diff --git a/apps/OpenSign/src/components/AppendFormInForm.js b/apps/OpenSign/src/components/AppendFormInForm.jsindex f9cd43d08..0522479bb 100644--- a/apps/OpenSign/src/components/AppendFormInForm.js+++ b/apps/OpenSign/src/components/AppendFormInForm.js@@ -604,123 +604,103 @@ class AppendFormInForm extends Component {});},async (error) => {- try {- Parse.serverURL = this.state.parseBaseUrl;- Parse.initialize(this.state.parseAppId);- var _users = Parse.Object.extend("_User");- var query = new Parse.Query(_users);+ if (error.code === 202) {+ let params;if (UserData.username) {- query.equalTo("username", UserData.username);+ params = { username: UserData.username };} else if (UserData.email) {- query.equalTo("email", UserData.email);+ params = { email: UserData.email };} else {- query.equalTo("username", UserData.phone);+ params = { username: UserData.phone };}- await query- .first()- .then(async (results) => {- if (results) {- let _emp = {- __type: "Pointer",- className: "_User",- objectId: results.id- };- let roleurl = `${this.state.parseBaseUrl}functions/AddUserToRole`;- const headers = {- "Content-Type": "application/json",- "X-Parse-Application-Id": this.state.parseAppId,- sessionToken: localStorage.getItem("accesstoken")- };- let body = {- appName: localStorage.getItem("_appName"),- roleName: RoleField,- userId: results.id- };- await axios- .post(roleurl, body, { headers: headers })- .then((res) => {- const currentUser = Parse.User.current();- let _fname = this.state.title;- var forms = Parse.Object.extend(_fname);- var form = new forms();- form.set(- "CreatedBy",- Parse.User.createWithoutData(currentUser.id)- );- if (localStorage.getItem("TenetId")) {- form.set("TenantId", {- __type: "Pointer",- className: "partners_Tenant",- objectId: localStorage.getItem("TenetId")- });+ const userRes = await Parse.Cloud.run("getUserId", params);++ try {+ let _emp = {+ __type: "Pointer",+ className: "_User",+ objectId: userRes.id+ };+ let roleurl = `${this.state.parseBaseUrl}functions/AddUserToRole`;+ const headers = {+ "Content-Type": "application/json",+ "X-Parse-Application-Id": this.state.parseAppId,+ sessionToken: localStorage.getItem("accesstoken")+ };+ let body = {+ appName: localStorage.getItem("_appName"),+ roleName: RoleField,+ userId: userRes.id+ };+ await axios+ .post(roleurl, body, { headers: headers })+ .then((res) => {+ const currentUser = Parse.User.current();+ let _fname = this.state.title;+ var forms = Parse.Object.extend(_fname);+ var form = new forms();+ form.set(+ "CreatedBy",+ Parse.User.createWithoutData(currentUser.id)+ );+ if (localStorage.getItem("TenetId")) {+ form.set("TenantId", {+ __type: "Pointer",+ className: "partners_Tenant",+ objectId: localStorage.getItem("TenetId")+ });+ }+ form.set("UserId", _emp);+ form.set("UserRole", RoleField);+ if (this.state["FormACL"]) {+ let ACL = {};+ for (let [key, value] of Object.entries(+ this.state["FormACL"]+ )) {+ if (key === "*") {+ ACL[key] = value;}- form.set("UserId", _emp);- form.set("UserRole", RoleField);- if (this.state["FormACL"]) {- let ACL = {};- for (let [key, value] of Object.entries(- this.state["FormACL"]- )) {- if (key === "*") {- ACL[key] = value;- }- if (key === "#currentUser#") {- ACL[Parse.User.current().id] = value;- }- if (key.startsWith("role")) {- ACL[key] = value;- }+ if (key === "#currentUser#") {+ ACL[Parse.User.current().id] = value;+ }+ if (key.startsWith("role")) {+ ACL[key] = value;+ }+ }+ form.setACL(new Parse.ACL(ACL));+ }+ form.save(RowData).then(+ (form) => {+ let filtered = {};+ if (this.state.redirect_type === "clearData") {+ if (+ this.state.persistentFields &&+ this.state.persistentFields.length+ ) {+ filtered = Object.keys(RowData)+ .filter((key) =>+ this.state.persistentFields.includes(key)+ )+ .reduce((obj, key) => {+ obj[key] = RowData[key];+ return obj;+ }, {});}- form.setACL(new Parse.ACL(ACL));+ } else {+ RowData = {};}- form.save(RowData).then(- (form) => {- let filtered = {};- if (this.state.redirect_type === "clearData") {- if (- this.state.persistentFields &&- this.state.persistentFields.length- ) {- filtered = Object.keys(RowData)- .filter((key) =>- this.state.persistentFields.includes(key)- )- .reduce((obj, key) => {- obj[key] = RowData[key];- return obj;- }, {});- }- } else {- RowData = {};- }- this.setState(- {- formData: filtered,- active: true,- loading: false,- toastColor: "#5cb85c",- toastDescription: this.state.successMassage- },- () => {- this.props.removeState();- this.props.removeLevel2State();- this.props.removeLevel3State();- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);- }- );+ this.setState(+ {+ formData: filtered,+ active: true,+ loading: false,+ toastColor: "#5cb85c",+ toastDescription: this.state.successMassage},- (error) => {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message- });-+ () => {+ this.props.removeState();+ this.props.removeLevel2State();+ this.props.removeLevel3State();var x = document.getElementById("snackbar");x.className = "show";setTimeout(function () {@@ -728,49 +708,43 @@ class AppendFormInForm extends Component {}, 2000);});- });- } else {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message- });+ },+ (error) => {+ this.setState({+ loading: false,+ active: true,+ toastColor: "#d9534f",+ toastDescription: error.message+ });- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);- }- })- .catch((error) => {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message+ var x = document.getElementById("snackbar");+ x.className = "show";+ setTimeout(function () {+ x.className = x.className.replace("show", "");+ }, 2000);+ }+ );});- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);+ const x = document.getElementById("snackbar");+ x.className = "show";+ setTimeout(function () {+ x.className = x.className.replace("show", "");+ }, 2000);+ } catch (error) {+ this.setState({+ loading: false,+ active: true,+ toastColor: "#d9534f",+ toastDescription: error.message});- } catch (error) {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message- });- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);+ const x = document.getElementById("snackbar");+ x.className = "show";+ setTimeout(function () {+ x.className = x.className.replace("show", "");+ }, 2000);+ }}});diff --git a/apps/OpenSign/src/json/ReportJson.js b/apps/OpenSign/src/json/ReportJson.jsindex 0f302bb7a..abdda66ca 100644--- a/apps/OpenSign/src/json/ReportJson.js+++ b/apps/OpenSign/src/json/ReportJson.js@@ -4,6 +4,7 @@ export default function reportJson(id) {// console.log("userId", currentUserId)switch (id) {+ // draft documents reportcase "ByHuevtCFY":return {reportName: "Draft Documents",@@ -40,6 +41,7 @@ export default function reportJson(id) {}]};+ // Need your sign reportcase "4Hhwbp482K":return {reportName: "Need your sign",@@ -94,6 +96,7 @@ export default function reportJson(id) {}]};+ // In progess reportcase "1MwEuxLEkF":return {reportName: "In-progress documents",@@ -133,6 +136,7 @@ export default function reportJson(id) {}]};+ // completed documents reportcase "kQUoW4hUXz":return {reportName: "Completed Documents",@@ -163,6 +167,7 @@ export default function reportJson(id) {}]};+ // OpenSignDriveâ„¢ documents Draftscase "VRFDmUmw5B":return {reportName: "OpenSignDriveâ„¢ Drafts",@@ -199,6 +204,7 @@ export default function reportJson(id) {}]};+ // declined documents reportcase "UPr2Fm5WY3":return {reportName: "Declined Documents",@@ -224,6 +230,7 @@ export default function reportJson(id) {}]};+ // Expired Documents reportcase "zNqBHXHsYH":return {reportName: "Expired Documents",@@ -271,6 +278,7 @@ export default function reportJson(id) {}]};+ // Recently sent for signatures report show on dashboardcase "d9k3UfYHBc":return {reportName: "Recently sent for signatures",@@ -310,6 +318,7 @@ export default function reportJson(id) {}]};+ // Recent signature requests report show on dashboardcase "5Go51Q7T8r":return {reportName: "Recent signature requests",@@ -364,6 +373,7 @@ export default function reportJson(id) {}]};+ // Drafts report show on dashboardcase "kC5mfynCi4":return {reportName: "Drafts",diff --git a/apps/OpenSign/src/routes/Form.js b/apps/OpenSign/src/routes/Form.jsindex f0f593dd3..95347ae1b 100644--- a/apps/OpenSign/src/routes/Form.js+++ b/apps/OpenSign/src/routes/Form.js@@ -587,7 +587,6 @@ class FormBuilder extends Component {() => {let redirect_type = this.state.redirect_type;let redirect_id = this.state.redirect_id;- let isApp = this.state.isAppRequest;this.props.removeState();this.props.removeLevel2State();this.props.removeLevel3State();@@ -629,192 +628,155 @@ class FormBuilder extends Component {});},async (error) => {- try {- Parse.serverURL = this.state.parseBaseUrl;- Parse.initialize(this.state.parseAppId);- var _users = Parse.Object.extend("_User");- var query = new Parse.Query(_users);+ if (error.code === 202) {+ let params;if (UserData.username) {- query.equalTo("username", UserData.username);+ params = { username: UserData.username };} else if (UserData.email) {- query.equalTo("email", UserData.email);+ params = { email: UserData.email };} else {- query.equalTo("username", UserData.phone);+ params = { username: UserData.phone };}- await query- .first()- .then(async (results) => {- if (results) {- let response = results.toJSON();- let _emp = {- __type: "Pointer",- className: "_User",- objectId: results.id- };- let roleurl = `${this.state.parseBaseUrl}functions/AddUserToRole`;- const headers = {- "Content-Type": "application/json",- "X-Parse-Application-Id": this.state.parseAppId,- sessionToken: localStorage.getItem("accesstoken")- };- let body = {- appName: localStorage.getItem("_appName"),- roleName: RoleField,- userId: results.id- };- await axios- .post(roleurl, body, { headers: headers })- .then((res) => {- const currentUser = Parse.User.current();- let _fname = this.state.title;- var forms = Parse.Object.extend(_fname);- var form = new forms();- form.set(- "CreatedBy",- Parse.User.createWithoutData(currentUser.id)- );- if (localStorage.getItem("TenetId")) {- form.set("TenantId", {- __type: "Pointer",- className: "partners_Tenant",- objectId: localStorage.getItem("TenetId")- });+ const userRes = await Parse.Cloud.run("getUserId", params);+ try {+ let _emp = {+ __type: "Pointer",+ className: "_User",+ objectId: userRes.id+ };+ let roleurl = `${this.state.parseBaseUrl}functions/AddUserToRole`;+ const headers = {+ "Content-Type": "application/json",+ "X-Parse-Application-Id": this.state.parseAppId,+ sessionToken: localStorage.getItem("accesstoken")+ };+ let body = {+ appName: localStorage.getItem("_appName"),+ roleName: RoleField,+ userId: userRes.id+ };+ await axios+ .post(roleurl, body, { headers: headers })+ .then((res) => {+ const currentUser = Parse.User.current();+ let _fname = this.state.title;+ var forms = Parse.Object.extend(_fname);+ var form = new forms();+ form.set(+ "CreatedBy",+ Parse.User.createWithoutData(currentUser.id)+ );+ if (localStorage.getItem("TenetId")) {+ form.set("TenantId", {+ __type: "Pointer",+ className: "partners_Tenant",+ objectId: localStorage.getItem("TenetId")+ });+ }+ form.set("UserId", _emp);+ form.set("UserRole", RoleField);+ if (this.state["FormACL"]) {+ let ACL = {};+ for (let [key, value] of Object.entries(+ this.state["FormACL"]+ )) {+ if (key === "*") {+ ACL[key] = value;}- form.set("UserId", _emp);- form.set("UserRole", RoleField);- if (this.state["FormACL"]) {- let ACL = {};- for (let [key, value] of Object.entries(- this.state["FormACL"]- )) {- if (key === "*") {- ACL[key] = value;- }- if (key === "#currentUser#") {- ACL[Parse.User.current().id] = value;- }- if (key.startsWith("role")) {- ACL[key] = value;- }+ if (key === "#currentUser#") {+ ACL[Parse.User.current().id] = value;+ }+ if (key.startsWith("role")) {+ ACL[key] = value;+ }+ }+ form.setACL(new Parse.ACL(ACL));+ }+ form.save(RowData).then(+ (form) => {+ let filtered = {};+ if (this.state.redirect_type === "clearData") {+ if (+ this.state.persistentFields &&+ this.state.persistentFields.length+ ) {+ filtered = Object.keys(RowData)+ .filter((key) =>+ this.state.persistentFields.includes(key)+ )+ .reduce((obj, key) => {+ obj[key] = RowData[key];+ return obj;+ }, {});}- form.setACL(new Parse.ACL(ACL));+ } else {+ RowData = {};}- form.save(RowData).then(- (form) => {- let filtered = {};- if (this.state.redirect_type === "clearData") {- if (- this.state.persistentFields &&- this.state.persistentFields.length- ) {- filtered = Object.keys(RowData)- .filter((key) =>- this.state.persistentFields.includes(key)- )- .reduce((obj, key) => {- obj[key] = RowData[key];- return obj;- }, {});- }- } else {- RowData = {};- }- this.setState(- {- formData: filtered,- active: true,- loading: false,- toastColor: "#5cb85c",- toastDescription: this.state.successMassage- },- () => {- let redirect_type = this.state.redirect_type;- let redirect_id = this.state.redirect_id;- let isApp = this.state.isAppRequest;- this.props.removeState();- this.props.removeLevel2State();- this.props.removeLevel3State();- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- if (redirect_type === "Form") {- this.props.navigate(`/form/${redirect_id}`);- } else if (redirect_type === "Report") {- this.props.navigate(- `/report/${redirect_id}`- );- } else if (redirect_type === "Dashboard") {- this.props.navigate(- `/dashboard/${redirect_id}`- );- } else if (redirect_type === "Url") {- window.location = redirect_id;- } else if (redirect_type === "Microapp") {- this.props.navigate(`/asmf/${redirect_id}`);- }- }, 2000);- }- );+ this.setState(+ {+ formData: filtered,+ active: true,+ loading: false,+ toastColor: "#5cb85c",+ toastDescription: this.state.successMassage},- (error) => {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message- });-+ () => {+ let redirect_type = this.state.redirect_type;+ let redirect_id = this.state.redirect_id;+ this.props.removeState();+ this.props.removeLevel2State();+ this.props.removeLevel3State();var x = document.getElementById("snackbar");x.className = "show";setTimeout(function () {x.className = x.className.replace("show", "");+ if (redirect_type === "Form") {+ this.props.navigate(`/form/${redirect_id}`);+ } else if (redirect_type === "Report") {+ this.props.navigate(`/report/${redirect_id}`);+ } else if (redirect_type === "Dashboard") {+ this.props.navigate(+ `/dashboard/${redirect_id}`+ );+ } else if (redirect_type === "Url") {+ window.location = redirect_id;+ } else if (redirect_type === "Microapp") {+ this.props.navigate(`/asmf/${redirect_id}`);+ }}, 2000);});- });- } else {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message- });+ },+ (error) => {+ this.setState({+ loading: false,+ active: true,+ toastColor: "#d9534f",+ toastDescription: error.message+ });- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);- }- })- .catch((error) => {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message+ var x = document.getElementById("snackbar");+ x.className = "show";+ setTimeout(function () {+ x.className = x.className.replace("show", "");+ }, 2000);+ }+ );});-- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);+ } catch (error) {+ this.setState({+ loading: false,+ active: true,+ toastColor: "#d9534f",+ toastDescription: error.message});- } catch (error) {- this.setState({- loading: false,- active: true,- toastColor: "#d9534f",- toastDescription: error.message- });- var x = document.getElementById("snackbar");- x.className = "show";- setTimeout(function () {- x.className = x.className.replace("show", "");- }, 2000);+ var x = document.getElementById("snackbar");+ x.className = "show";+ setTimeout(function () {+ x.className = x.className.replace("show", "");+ }, 2000);+ }}});@@ -1137,7 +1099,6 @@ class FormBuilder extends Component {() => {let redirect_type = this.state.redirect_type;let redirect_id = this.state.redirect_id;- let isApp = this.state.isAppRequest;var x = document.getElementById("snackbar");this.props.removeState();this.props.removeLevel2State();diff --git a/apps/OpenSignServer/cloud/main.js b/apps/OpenSignServer/cloud/main.jsindex e05c2649f..45cc0efae 100644--- a/apps/OpenSignServer/cloud/main.js+++ b/apps/OpenSignServer/cloud/main.js@@ -12,6 +12,7 @@ import ContractUsersAftersave from './parsefunction/ContractUsersAftersave.js';import sendMailOTPv1 from './parsefunction/SendMailOTPv1.js';import SendMailv1 from './parsefunction/SendMailv1.js';import AuthLoginAsMail from './parsefunction/AuthLoginAsMail.js';+import getUserId from './parsefunction/getUserId.js';Parse.Cloud.define('AddUserToRole', addUserToGroups);Parse.Cloud.define('UserGroups', getUserGroups);@@ -27,3 +28,4 @@ Parse.Cloud.afterSave('contracts_Users', ContractUsersAftersave);Parse.Cloud.define('SendOTPMailV1', sendMailOTPv1);Parse.Cloud.define('sendmail', SendMailv1);Parse.Cloud.define('AuthLoginAsMail', AuthLoginAsMail);+Parse.Cloud.define('getUserId', getUserId);diff --git a/apps/OpenSignServer/cloud/parsefunction/getUserId.js b/apps/OpenSignServer/cloud/parsefunction/getUserId.jsnew file mode 100644index 000000000..6331f4650--- /dev/null+++ b/apps/OpenSignServer/cloud/parsefunction/getUserId.js@@ -0,0 +1,18 @@+async function getUserId(request) {+ try {+ const username = request.params.username;+ const email = request.params.email;+ const query = new Parse.Query(Parse.User);+ if (username) {+ query.equalTo('username', username);+ } else {+ query.equalTo('email', email);+ }+ const user = await query.first({ useMasterKey: true });+ return { id: user.id };+ } catch (err) {+ console.log('err', err);+ return err;+ }+}+export default getUserId;