55 */
66
77const path = require ( 'path' )
8+ const validator = require ( 'validator' ) ;
89const { deleteUserProductPermissionProfile, getProductPermissionProfilesByEmail } = require ( '../examples/deleteUserProductPermissionProfile' ) ;
910const dsConfig = require ( '../../../config/index.js' ) . config ;
10- const validator = require ( 'validator' ) ;
1111const { getOrganizationId } = require ( "../getOrganizationId.js" ) ;
1212
1313const eg009DeleteUserProductPermissionProfile = exports ;
@@ -23,15 +23,15 @@ const minimumBufferMin = 3;
2323eg009DeleteUserProductPermissionProfile . 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