Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mastilver/sails-hook-parametized-policies
https://github.com/mastilver/sails-hook-parametized-policies
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/mastilver/sails-hook-parametized-policies
- Owner: mastilver
- License: mit
- Created: 2015-06-08T22:39:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-23T13:02:33.000Z (almost 8 years ago)
- Last Synced: 2024-09-19T20:47:26.392Z (about 2 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 3
- Watchers: 5
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sails-hook-parametized-policies [![Build Status](https://travis-ci.org/mastilver/sails-hook-parametized-policies.svg?branch=master)](https://travis-ci.org/mastilver/sails-hook-parametized-policies) [![Coverage Status](https://coveralls.io/repos/mastilver/sails-hook-parametized-policies/badge.svg?branch=master)](https://coveralls.io/r/mastilver/sails-hook-parametized-policies?branch=master)
## Install
`$ npm install --save sails-hook-parametized-policies`
## Setup
add your factories inside `api/policyFactories` or in the folder you defined on `sails.config.paths.policyFactories`
example: `is.js`
```
module.exports = function(userType){return function(req, res, next){
var roles = req.user.roles;
if(roles.indexOf(userType) > 0){
return next();
}res.forbidden('You must be an ' + userType + ' to access this resource');
};
};
```or a more complex one: `or.js`
[example of OR policy with a number of arguments](https://gist.github.com/1nstinct/12399f8adc4e5cfd6e88)
## Usage
in your `config/policies.js`
```
{
ProfileController: {
edit: 'isLoggedIn'
create: ['or(is(\'Admin\'), is(\'SubAdmin\'))', 'isLoggedIn'],
delete: ['is(\'Admin\')', 'isLoggedIn'],
}
}
```