Skip to content

mastilver/sails-hook-parametized-policies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sails-hook-parametized-policies Build Status Coverage Status

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

Usage

in your config/policies.js

{
    ProfileController: {
        edit: 'isLoggedIn'
        create: ['or(is(\'Admin\'), is(\'SubAdmin\'))', 'isLoggedIn'],
        delete: ['is(\'Admin\')', 'isLoggedIn'],
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published