66
77const path = require ( 'path' )
88const { createCLMESignUser, getProductPermissionProfiles, getDSAdminGroups } = require ( '../examples/createCLMESignUser' ) ;
9+ const { getExampleByNumber } = require ( "../../manifestService" ) ;
910const dsConfig = require ( '../../../config/index.js' ) . config ;
1011const validator = require ( 'validator' ) ;
1112const { getOrganizationId } = require ( "../getOrganizationId.js" ) ;
1213
1314const eg002CreateCLMESignUser = exports ;
14- const eg = 'eg002' // This example reference.;
15+ const exampleNumber = 2 ;
16+ const eg = `eg00${ exampleNumber } ` ; // This example reference.
1517const mustAuthenticate = '/ds/mustAuthenticate' ;
1618const minimumBufferMin = 3 ;
1719
@@ -23,12 +25,12 @@ const minimumBufferMin = 3;
2325eg002CreateCLMESignUser . createController = async ( req , res ) => {
2426 // At this point we should have a good token. But we
2527 // double-check here to enable a better UX to the user.
26- let tokenOK = req . dsAuth . checkToken ( minimumBufferMin ) ;
27- if ( ! tokenOK ) {
28+ let isTokenOK = req . dsAuth . checkToken ( minimumBufferMin ) ;
29+ if ( ! isTokenOK ) {
2830 req . flash ( "info" , "Sorry, you need to re-authenticate." ) ;
2931 // Save the current operation so it will be resumed after authentication
3032 req . dsAuth . setEg ( req , eg ) ;
31- res . redirect ( mustAuthenticate ) ;
33+ return res . redirect ( mustAuthenticate ) ;
3234 }
3335
3436 let results = null ;
@@ -51,8 +53,7 @@ eg002CreateCLMESignUser.createController = async (req, res) => {
5153
5254 try {
5355 results = await createCLMESignUser ( args )
54- }
55- catch ( error ) {
56+ } catch ( error ) {
5657 let errorBody = error && error . response && error . response . body
5758 // we can pull the DocuSign error code and message from the response body
5859 , errorCode = errorBody && errorBody . errorCode
@@ -65,10 +66,10 @@ eg002CreateCLMESignUser.createController = async (req, res) => {
6566 if ( results ) {
6667 req . session . clmEmail = validator . escape ( body . email ) ;
6768
69+ const example = getExampleByNumber ( res . locals . manifest , exampleNumber ) ;
6870 res . render ( "pages/example_done" , {
69- title : "Create active user for CLM and eSignature" ,
70- h1 : "Create active user for CLM and eSignature" ,
71- message : "Results from MultiProductUserManagement:addOrUpdateUser method:" ,
71+ title : example . ExampleName ,
72+ message : example . ResultsPageText ,
7273 json : JSON . stringify ( results ) . replace ( / ' / g, '' )
7374 } ) ;
7475 }
@@ -81,47 +82,47 @@ eg002CreateCLMESignUser.getController = async (req, res) => {
8182 // Check that the authentication token is ok with a long buffer time.
8283 // If needed, now is the best time to ask the user to authenticate
8384 // since they have not yet entered any information into the form.
84- let tokenOK = req . dsAuth . checkToken ( ) ;
85- if ( tokenOK ) {
86- try {
87- await getOrganizationId ( req )
88- const args = {
89- accessToken : req . user . accessToken ,
90- accountId : req . session . accountId ,
91- organizationId : req . session . organizationId
92- } ;
93-
94- let productPermissionProfiles = await getProductPermissionProfiles ( args ) ;
95- let dsGroups = await getDSAdminGroups ( args ) ;
96-
97- sourceFile = ( path . basename ( __filename ) ) [ 5 ] . toLowerCase ( ) + ( path . basename ( __filename ) ) . substr ( 6 ) ;
98- res . render ( "pages/admin-examples/eg002CreateCLMESignUser" , {
99- eg : eg , csrfToken : req . csrfToken ( ) ,
100- title : "Create active user for CLM and eSignature" ,
101- clmPermissionProfiles : productPermissionProfiles . clmPermissionProfiles ,
102- eSignPermissionProfiles : productPermissionProfiles . eSignPermissionProfiles ,
103- dsGroups,
104- clmProductId : productPermissionProfiles . clmProductId ,
105- eSignProductId : productPermissionProfiles . eSignProductId ,
106- sourceFile : sourceFile ,
107- sourceUrl : dsConfig . githubExampleUrl + 'admin/examples/' + sourceFile ,
108- documentation : dsConfig . documentation + eg ,
109- showDoc : dsConfig . documentation
110- } ) ;
111- }
112- catch ( error ) {
113- let errorBody = error && error . response && error . response . body
114- // we can pull the DocuSign error code and message from the response body
115- , errorCode = errorBody && errorBody . errorCode
116- , errorMessage = errorBody && errorBody . message
117- ;
118- // In production, may want to provide customized error messages and
119- // remediation advice to the user.
120- res . render ( "pages/error" , { err : error , errorCode : errorCode , errorMessage : errorMessage } ) ;
121- }
122- } else {
85+ let isTokenOK = req . dsAuth . checkToken ( ) ;
86+ if ( ! isTokenOK ) {
12387 // Save the current operation so it will be resumed after authentication
12488 req . dsAuth . setEg ( req , eg ) ;
125- res . redirect ( mustAuthenticate ) ;
89+ return res . redirect ( mustAuthenticate ) ;
90+ }
91+
92+ try {
93+ await getOrganizationId ( req )
94+ const args = {
95+ accessToken : req . user . accessToken ,
96+ accountId : req . session . accountId ,
97+ organizationId : req . session . organizationId
98+ } ;
99+
100+ let productPermissionProfiles = await getProductPermissionProfiles ( args ) ;
101+ let dsGroups = await getDSAdminGroups ( args ) ;
102+
103+ const example = getExampleByNumber ( res . locals . manifest , exampleNumber ) ;
104+ const sourceFile = ( path . basename ( __filename ) ) [ 5 ] . toLowerCase ( ) + ( path . basename ( __filename ) ) . substr ( 6 ) ;
105+ res . render ( "pages/admin-examples/eg002CreateCLMESignUser" , {
106+ eg : eg , csrfToken : req . csrfToken ( ) ,
107+ example : example ,
108+ clmPermissionProfiles : productPermissionProfiles . clmPermissionProfiles ,
109+ eSignPermissionProfiles : productPermissionProfiles . eSignPermissionProfiles ,
110+ dsGroups,
111+ clmProductId : productPermissionProfiles . clmProductId ,
112+ eSignProductId : productPermissionProfiles . eSignProductId ,
113+ sourceFile : sourceFile ,
114+ sourceUrl : dsConfig . githubExampleUrl + 'admin/examples/' + sourceFile ,
115+ documentation : dsConfig . documentation + eg ,
116+ showDoc : dsConfig . documentation
117+ } ) ;
118+ } catch ( error ) {
119+ let errorBody = error && error . response && error . response . body
120+ // we can pull the DocuSign error code and message from the response body
121+ , errorCode = errorBody && errorBody . errorCode
122+ , errorMessage = errorBody && errorBody . message
123+ ;
124+ // In production, may want to provide customized error messages and
125+ // remediation advice to the user.
126+ res . render ( "pages/error" , { err : error , errorCode : errorCode , errorMessage : errorMessage } ) ;
126127 }
127128}
0 commit comments