Sails hook annotation policy
sails-hook-annotations.
This hook wouldn't supported more. All functionality moved here:But current version is fully working.
This hook allow developers to define Policies for actions using annotations.
For this you could use @Policy()
annotation. It works only with double quotes!
Parameters could be:
string
- Policy name.Array
- Array of policies
If you defined some policy for this action into config/policies.js
file. Policy from annotation will be added to existing one !
config/policies.js
:
moduleexports = UserController: actionWithPolicyConfigured: "configuredPolicy" ;
api/controllers/UserController.js
:
moduleexports = /** * Description of someAction * * Only one policy "isAuthorized" will be applyed * * @Policy("isAuthorized") * @param * @param */ { return res; } /** * Another action description * * Two policies: "somepolicy", "anotherPolicy" will be applyed * * @Policy(["somepolicy", "anotherPolicy"]) * @param * @param */ { // ... return res; } /** * Description of someAction * * Two policies "isAuthorized" and "configuredPolicy" will be applyed * * @Policy("isAuthorized") * @param * @param */ { return res; };