modella-context

Context access control for Modella.

modella-context

context access control for modella.

Using npm:

npm install modella-context

Using component:

component install alexmingoia/modella-context
var access = require('modella-context')
  , modella = require('modella');
 
var User = modella('User');
 
User
  .attr('id')
  .attr('name')
  .attr('password')
  .use(access)
  .allow([ 'id', 'name' ], { role: 'guest' });
 
var user = new User({ name: 'alex', password: 'secret' });
 
user.context({ role: 'guest' });
 
user.toJSON();
// => { id: 1, name: 'alex' } 

Allow attrs for the given context.

Set the model instance's context. Model#toJSON() will only return attributes allowed for the context, if it has been set.

Returns only the attributes allowed by the model instance's current context, if it has been set.