Skip to content

Commit f1268c1

Browse files
fixes
1 parent e58912a commit f1268c1

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

lib/admin/controllers/eg008UpdateUserProductPermissionProfile.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
const path = require('path')
8+
const validator = require('validator');
89
const { updateUserProductPermissionProfile, getProductPermissionProfiles } = require('../examples/updateUserProductPermissionProfile');
910
const dsConfig = require('../../../config/index.js').config;
10-
const validator = require('validator');
1111
const { getOrganizationId } = require("../getOrganizationId.js");
1212

1313
const eg008UpdateUserProductPermissionProfile = exports;
@@ -23,15 +23,15 @@ const minimumBufferMin = 3;
2323
eg008UpdateUserProductPermissionProfile.createController = async (req, res) => {
2424
// At this point we should have a good token. But we
2525
// double-check here to enable a better UX to the user.
26-
let isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
26+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
2727
if (!isTokenOK) {
2828
req.flash("info", "Sorry, you need to re-authenticate.");
2929
// Save the current operation so it will be resumed after authentication
3030
req.dsAuth.setEg(req, eg);
3131
return res.redirect(mustAuthenticate);
3232
}
3333

34-
if(!req.session.clmEmail) {
34+
if (!req.session.clmEmail) {
3535
return res.render("pages/admin-examples/eg008UpdateUserProductPermissionProfile", {
3636
eg: eg, csrfToken: req.csrfToken(),
3737
title: "Update user product permission profiles using an email address",
@@ -43,7 +43,6 @@ eg008UpdateUserProductPermissionProfile.createController = async (req, res) => {
4343
});
4444
}
4545

46-
let results = null;
4746
const { body } = req;
4847

4948
const productId = validator.escape(body.productId);
@@ -58,14 +57,13 @@ eg008UpdateUserProductPermissionProfile.createController = async (req, res) => {
5857

5958
const { clmProductId } = await getProductPermissionProfiles(args);
6059

61-
if(productId === clmProductId) {
62-
args.permissionProfileId = validator.escape(body.clmPermissionProfileId);
63-
} else {
64-
args.permissionProfileId = validator.escape(body.eSignPermissionProfileId);
65-
}
60+
args.permissionProfileId = productId === clmProductId
61+
? validator.escape(body.clmPermissionProfileId)
62+
: validator.escape(body.eSignPermissionProfileId)
6663

64+
let results = null;
6765
try {
68-
results = await updateUserProductPermissionProfile(args)
66+
results = await updateUserProductPermissionProfile(args);
6967
}
7068
catch (error) {
7169
const errorBody = error && error.response && error.response.body;
@@ -94,15 +92,15 @@ eg008UpdateUserProductPermissionProfile.getController = async (req, res) => {
9492
// Check that the authentication token is ok with a long buffer time.
9593
// If needed, now is the best time to ask the user to authenticate
9694
// since they have not yet entered any information into the form.
97-
let isTokenOK = req.dsAuth.checkToken();
95+
const isTokenOK = req.dsAuth.checkToken();
9896
if (!isTokenOK) {
9997
// Save the current operation so it will be resumed after authentication
10098
req.dsAuth.setEg(req, eg);
10199
return res.redirect(mustAuthenticate);
102100
}
103101

104102
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
105-
if(!req.session.clmEmail) {
103+
if (!req.session.clmEmail) {
106104
return res.render("pages/admin-examples/eg008UpdateUserProductPermissionProfile", {
107105
eg: eg, csrfToken: req.csrfToken(),
108106
title: "Update user product permission profiles using an email address",
@@ -115,7 +113,7 @@ eg008UpdateUserProductPermissionProfile.getController = async (req, res) => {
115113
}
116114

117115
try {
118-
await getOrganizationId(req)
116+
await getOrganizationId(req);
119117
const args = {
120118
accessToken: req.user.accessToken,
121119
basePath: dsConfig.adminAPIUrl,

lib/admin/controllers/eg009DeleteUserProductPermissionProfile.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
const path = require('path')
8+
const validator = require('validator');
89
const { deleteUserProductPermissionProfile, getProductPermissionProfilesByEmail } = require('../examples/deleteUserProductPermissionProfile');
910
const dsConfig = require('../../../config/index.js').config;
10-
const validator = require('validator');
1111
const { getOrganizationId } = require("../getOrganizationId.js");
1212

1313
const eg009DeleteUserProductPermissionProfile = exports;
@@ -23,15 +23,15 @@ const minimumBufferMin = 3;
2323
eg009DeleteUserProductPermissionProfile.createController = async (req, res) => {
2424
// At this point we should have a good token. But we
2525
// double-check here to enable a better UX to the user.
26-
let isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
26+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
2727
if (!isTokenOK) {
2828
req.flash("info", "Sorry, you need to re-authenticate.");
2929
// Save the current operation so it will be resumed after authentication
3030
req.dsAuth.setEg(req, eg);
3131
return res.redirect(mustAuthenticate);
3232
}
3333

34-
if(!req.session.clmEmail) {
34+
if (!req.session.clmEmail) {
3535
return res.render("pages/admin-examples/eg009DeleteUserProductPermissionProfile", {
3636
eg: eg, csrfToken: req.csrfToken(),
3737
title: "Delete user product permission profiles using an email address",
@@ -43,7 +43,6 @@ eg009DeleteUserProductPermissionProfile.createController = async (req, res) => {
4343
});
4444
}
4545

46-
let results = null;
4746
const body = req.body;
4847
const args = {
4948
accessToken: req.user.accessToken,
@@ -53,9 +52,10 @@ eg009DeleteUserProductPermissionProfile.createController = async (req, res) => {
5352
email: req.session.clmEmail,
5453
productId: validator.escape(body.productId)
5554
}
56-
55+
56+
let results = null;
5757
try {
58-
results = await deleteUserProductPermissionProfile(args)
58+
results = await deleteUserProductPermissionProfile(args);
5959
}
6060
catch (error) {
6161
const errorBody = error && error.response && error.response.body;
@@ -84,7 +84,7 @@ eg009DeleteUserProductPermissionProfile.getController = async (req, res) => {
8484
// Check that the authentication token is ok with a long buffer time.
8585
// If needed, now is the best time to ask the user to authenticate
8686
// since they have not yet entered any information into the form.
87-
let isTokenOK = req.dsAuth.checkToken();
87+
const isTokenOK = req.dsAuth.checkToken();
8888
if (!isTokenOK) {
8989
req.flash("info", "Sorry, you need to re-authenticate.");
9090
// Save the current operation so it will be resumed after authentication
@@ -93,7 +93,7 @@ eg009DeleteUserProductPermissionProfile.getController = async (req, res) => {
9393
}
9494

9595
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
96-
if(!req.session.clmEmail) {
96+
if (!req.session.clmEmail) {
9797
return res.render("pages/admin-examples/eg009DeleteUserProductPermissionProfile", {
9898
eg: eg, csrfToken: req.csrfToken(),
9999
title: "Delete user product permission profiles using an email address",
@@ -106,7 +106,7 @@ eg009DeleteUserProductPermissionProfile.getController = async (req, res) => {
106106
}
107107

108108
try {
109-
await getOrganizationId(req)
109+
await getOrganizationId(req);
110110
const args = {
111111
accessToken: req.user.accessToken,
112112
basePath: dsConfig.adminAPIUrl,
@@ -119,19 +119,19 @@ eg009DeleteUserProductPermissionProfile.getController = async (req, res) => {
119119
let permissionProfileList = [];
120120
let permissionName;
121121

122-
if(productPermissionProfiles && productPermissionProfiles.length > 0) {
122+
// Create the permission profile list that will be used on example page
123+
if (productPermissionProfiles && productPermissionProfiles.length > 0) {
123124
productPermissionProfiles.forEach(product => {
124125
let permissionProfiles = product["permission_profiles"];
125126

126127
permissionProfiles.forEach(profile => {
127-
if(product["product_name"].includes("CLM")) {
128-
permissionName = `CLM - ${profile["permission_profile_name"]}`;
129-
} else {
130-
permissionName = `eSignature - ${profile["permission_profile_name"]}`;
131-
}
128+
permissionName = product["product_name"].includes("CLM")
129+
? `CLM - ${profile["permission_profile_name"]}`
130+
: `eSignature - ${profile["permission_profile_name"]}`;
132131

133-
if(permissionProfileList.filter(prof => prof["productId"] === product["product_id"]).length === 0) {
134-
permissionProfileList.push({ productId: product["product_id"], permissionName})
132+
// Add current permission profile data to the list if it was not added yet
133+
if (permissionProfileList.filter(prof => prof["productId"] === product["product_id"]).length === 0) {
134+
permissionProfileList.push({ productId: product["product_id"], permissionName });
135135
}
136136
});
137137
});

0 commit comments

Comments
 (0)