mangomodel-security

0.0.2 • Public • Published

MangoModel-Security

MangoModel-Security provides some simple security utility methods for the MangoModel MongoDB wrapper.

Installing

To install, use NPM:

 npm install mangomodel-security

Using

To add the MongoModel-Security functionality to a MangoModel model, do the following:

var MangoModel = require('mangomodel'),
    MangoModelSecurity = require('mangomodel-security'),
    ExampleModel = MangoModel.create('example');
    
ExampleModel.methods(MangoModelSecurity({
    // permission go here.. ie
    
    user: {
        read: ['name', 'description'],
        write: ['name']
    },
    
    manager: {
        includes: 'user', // include all the permissions of user
        read: ['secret_stuff'],
        write: ['description', 'secret_stuff']
    }
    
}));

Once this has been done, you can call the utility methods on the MangoModel object. Ie:

var record = {name: 'John Doe', description: 'A regular guy', secret_stuff: 'Likes brussel sprouts'};

// Return a copy of the record with fields a user should see
ExampleModel.restrict(record, 'user'); // Return name and description

// Get a copy of the record with only fields permissible by a user updated
ExampleModel.mix(record, { name: 'John Dean', description: 'Better than regular'}, 'user'); // Only updates name

ExampleModel.mix(record, { name: 'John Dean', description: 'Better than regular'}, 'manager'); // Update all

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    3
  • 0.0.1
    2

Package Sidebar

Install

npm i mangomodel-security

Weekly Downloads

5

Version

0.0.2

License

none

Last publish

Collaborators

  • nathanoehlman