sails-hook-annotation-policy

0.1.3 • Public • Published

Sails hook annotation policy

This hook wouldn't supported more. All functionality moved here: sails-hook-annotations.

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:

module.exports = {
 
  UserController: {
    actionWithPolicyConfigured: "configuredPolicy"
  }
};

api/controllers/UserController.js:

 
module.exports = {
 
  /**
   * Description of someAction
   *
   * Only one policy "isAuthorized" will be applyed
   *
   * @Policy("isAuthorized")
   * @param  {IncommingMessage} req 
   * @param  {OutcommintMessage} res 
   */
  someAction: function(req, res) {
    return res.ok();
  },
 
  /**
   * Another action description
   *
   * Two policies: "somepolicy", "anotherPolicy" will be applyed
   *
   * @Policy(["somepolicy", "anotherPolicy"])
   * @param  {IncommingMessage} req 
   * @param  {OutcommingMessage} res 
   */
  anotherAction: function(req, res) {
    // ...
    return res.ok();
  },
 
  /**
   * Description of someAction
   *
   * Two policies "isAuthorized" and "configuredPolicy" will be applyed
   *
   * @Policy("isAuthorized")
   * @param  {IncommingMessage} req 
   * @param  {OutcommintMessage} res 
   */
  actionWithPolicyConfigured: function(req, res) {
    return res.ok();
  }
};

Package Sidebar

Install

npm i sails-hook-annotation-policy

Weekly Downloads

0

Version

0.1.3

License

MIT

Last publish

Collaborators

  • kos