From a6781c323a81c15767d7629e9cd8779762181b9e Mon Sep 17 00:00:00 2001 From: AmeenAhmed Date: Thu, 21 Mar 2013 22:01:14 +0530 Subject: [PATCH] Issue #221 implemented the *Controller syntax for defining a policy --- lib/policies.js | 12 +++++++++++- package.json | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/policies.js b/lib/policies.js index 607f03c01..5fdecad0e 100644 --- a/lib/policies.js +++ b/lib/policies.js @@ -28,7 +28,17 @@ function runPolicy(controllerName, actionName, req, res, next) { // Determine which policies apply directly to this request // policy for this controller - var cPolicy = sails.config.policies[controllerName]; + + var cPolicy = sails.config.policies[controllerName]; + + // Get the controllerName and camelize it + var camelController = require('inflection').camelize(controllerName) + 'Controller'; + + // If a policy exists for the route don't bother looking for *Controller + // if it doesn't then check for + cPolicy = (!!cPolicy) ? cPolicy : sails.config.policies[camelController]; + + if (!_.isUndefined(cPolicy)) { routePlan = cPolicy; diff --git a/package.json b/package.json index ac61ad7dc..1452c373c 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "clean-css": "0.10.1", "fs-watch-tree": "~0.2.2", "jade": "0.28.0", + "inflection": "1.2.5", "node-typescript": "0.1.3" }, "devDependencies": {