Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/konstantinzolotarev/sails-hook-annotation-policy
Sails.js hook that adds annotations support for policies
https://github.com/konstantinzolotarev/sails-hook-annotation-policy
Last synced: about 1 month ago
JSON representation
Sails.js hook that adds annotations support for policies
- Host: GitHub
- URL: https://github.com/konstantinzolotarev/sails-hook-annotation-policy
- Owner: konstantinzolotarev
- License: mit
- Created: 2015-06-17T05:14:25.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-26T11:48:22.000Z (over 9 years ago)
- Last Synced: 2024-04-24T19:05:04.502Z (8 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Sails hook annotation policy
# This hook wouldn't supported more. All functionality moved here: [sails-hook-annotations](https://github.com/konstantinzolotarev/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`:
```javascript
module.exports = {UserController: {
actionWithPolicyConfigured: "configuredPolicy"
}
};
````api/controllers/UserController.js`:
```javascript
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();
}
};
```