npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sails-generate-role

v0.2.6

Published

sails generate role

Downloads

9

Readme

sails-generate-role

A role generator for use with the Sails command-line interface.

Roles allow you to specify access restrictions based on roles. This includes normal controller access via policies as well as model restrictions.

See usage section for more details.

Installation

$ npm install sails-generate-role

Usage

On the command line

The plugin (via a Sails hook) is initialized when the first role is generated. For example, to start with an admin role, do the following:

$ sails generate role Admin

Concepts

Please note that this is work in progress. Some of the options described below may not work yet. Todo: Detail 'readonly' and 'restrict' behaviour.

In your code

The role restrictions can be defined in two different ways. The first is to use the policies.js, located in the sails project (config/policies.js). It's recommended to use this if you already have a lot of policies and don't want to migrate to the role based layout.

In addition, it is necessary to implement the method 'resolveRoles' of the api/roles/RoleContext.js. This will allow the role framework to look up all roles for a given request.

Via policies.js

config/policies.js

var rolePolicy = require('sails-generate-role').rolePolicy;

module.exports = {
    //Restrict partnerId attribute on model app to read-only for users with role partner
    // This would remove the partnerId from all update/create calls to blueprint REST services
    // If you want more control (e.g. overwrite a value), use 'restrict'
    App: rolePolicy({
        'partner': {
            'partnerId': 'readonly'
        }
    }),

    //Controller policies can be combined with standard policies:
    // Only allow logged in users with admin OR partner role to access the find action
    AppController: {
        find: ['isLoggedIn', rolePolicy(['admin', 'partner'])]
    }
};
Via *Role.js

The other possibility is to specify all policies and model restrictions in the role itself (e.g. api/roles/AdminRole.js).

config/policies.js

var rolePolicy = require('sails-generate-role').rolePolicy;
module.exports = {    
    '*': ['isLoggedIn', rolePolicy('admin')] //Disallow for everyone except admin
}

api/roles/PartnerRole.js

module.exports = {    
    
    //Allow access to specific actions
    controllers: {
        AppController: {
            find: true,
            findOne: true
        }
    },

    models: {
        App: {
            'partnerId': 'restrict'
        }
    },

    restrictCriteria: function(request, model, roleValues, criteria, next) {
        //No additional restrictions, modify criteria as necessary
        next(null, criteria);
    },

    restrictValues: function(request, model, valueObj, next) {
        //No additional restrictions, modify values as necessary
        next(null, valueObj);
    }
}

License

MIT © 2014 yasoon & contributors