/** * beforeBlueprint * * @module :: Policy * @description :: Simple policy to enable hooks into the model which can act upon req, res objects. * @docs :: http://sailsjs.org/#!documentation/policies * */ var actionUtil = require( 'sails/lib/hooks/blueprints/actionUtil' ); capitaliseFirstLetter = function ( string ) { return string.charAt( 0 ).toUpperCase() + string.slice( 1 ); }; module.exports = function ( req, res, next ) { var Model = actionUtil.parseModel( req ); var blueprint = capitaliseFirstLetter( req.options.action ); // we actually enable this for all actions, not only blueprints if ( typeof Model[ "controlBefore" + blueprint ] === "function" ) { var result = Model[ "controlBefore" + blueprint ]( req, res, next ); //next(); } else { sails.log.debug( 'Policy beforeBlueprint: Model "' + Model.identity + '" has no method controlBefore' + blueprint + '.' ); next(); } };