diff --git a/ExpressAPI/src/helpers/DojoValidators.ts b/ExpressAPI/src/helpers/DojoValidators.ts index fb538734e4a7207e434b3177027bd7fca5005db9..09b7c8253a66f99725ee9915bde0342c64429ee4 100644 --- a/ExpressAPI/src/helpers/DojoValidators.ts +++ b/ExpressAPI/src/helpers/DojoValidators.ts @@ -49,19 +49,19 @@ class DojoValidators { } }); - readonly arraySanitizer = this.toValidatorSchemaOptions({ - options: (value, { - req, - location, - path - }) => { - try { - return JSON.parse(value); - } catch ( e ) { - return value; - } - } - }); + readonly jsonSanitizer = this.toValidatorSchemaOptions({ + options: (value, { + req, + location, + path + }) => { + try { + return JSON.parse(value); + } catch ( e ) { + return value; + } + } + }); readonly templateUrlValidator = this.toValidatorSchemaOptions({ bail : true, @@ -101,6 +101,26 @@ class DojoValidators { return value; } }); + + readonly enonceValidator = this.toValidatorSchemaOptions({ + bail : true, + errorMessage: 'Template doesn\'t exist or you don\'t have access to it', + options : (value, { + req, + location, + path + }) => { + return new Promise((resolve, reject) => { + const template = this.getParamValue(req, path); + if ( template ) { + GitlabManager.checkTemplateAccess(template, req).then((templateAccess) => { + templateAccess !== StatusCodes.OK ? reject() : resolve(true); + }); + } + resolve(true); + }); + } + }); } diff --git a/ExpressAPI/src/routes/EnonceRoutes.ts b/ExpressAPI/src/routes/EnonceRoutes.ts index 0bda88abbd14b97f099017e87e0e9978eeb77763..dd6320d4b7c0ab8aff0fe244d2d722778362d1f2 100644 --- a/ExpressAPI/src/routes/EnonceRoutes.ts +++ b/ExpressAPI/src/routes/EnonceRoutes.ts @@ -43,7 +43,7 @@ class EnonceRoutes implements RoutesManager { members : { trim : true, notEmpty : true, - customSanitizer: DojoValidators.arraySanitizer + customSanitizer: DojoValidators.jsonSanitizer }, template: { trim : true,