Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-acl

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-acl - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

24

lib/object.js

@@ -17,6 +17,6 @@ module.exports = function(schema, options) {

schema.methods.setAccess = function(key, ops) {
ops || (ops = {});
schema.methods.setAccess = function(key, perms) {
perms || (perms = {});
this[options.path] || (this[options.path] = {});
this[options.path][key] = ops;
this[options.path][key] = perms;
this.markModified(options.path);

@@ -30,11 +30,23 @@ };

var toJSON = schema.methods.toJSON;
schema.methods.toJSON = function() {
var data = toJSON ? toJSON.call(this) : this.toObject();
delete data[options.path];
return data;
};
// Statics
schema.statics.withAccess = function(subject, op, callback) {
schema.statics.withAccess = function(subject, perms, callback) {
var keys = subject.getAccessKeys();
var or = keys.map(function(key) {
var path = [options.path, key, op].join('.');
var query = {};
query[path] = true;
for (var perm in perms) {
var path = [options.path, key, perm].join('.');
query[path] = perms[perm];
}
return query;

@@ -41,0 +53,0 @@ });

@@ -10,4 +10,4 @@ module.exports = function(schema, options) {

if (!options.allow) {
options.allow = function() {
if (!options.additionalKeys) {
options.additionalKeys = function() {
return [];

@@ -21,4 +21,4 @@ };

var key = options.key.call(this);
var allow = options.allow.call(this);
var keys = [key, options.public].concat(allow);
var additional = options.additionalKeys.call(this);
var keys = [key, options.public].concat(additional);

@@ -31,3 +31,3 @@ return keys.filter(function(key) {

schema.methods.getAccess = function(entity) {
var perms = this.getAccessKeys().map(function(key) {
var entries = this.getAccessKeys().map(function(key) {
return entity.getAccess(key);

@@ -38,5 +38,5 @@ });

perms.forEach(function(ops) {
for (var op in ops) {
result[op] = result[op] || ops[op];
entries.forEach(function(perms) {
for (var perm in perms) {
result[perm] = result[perm] || perms[perm];
}

@@ -43,0 +43,0 @@ });

{
"name": "mongoose-acl",
"version": "0.0.1",
"version": "0.1.0",
"description": "Mongoose ACL",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/scttnlsn/mongoose-acl",

@@ -41,3 +41,3 @@ mongoose-acl

```javascript
Widget.withAccess(user, 'read').exec(function(err, widgets) {
Widget.withAccess(user, { read: true }).exec(function(err, widgets) {
...

@@ -76,3 +76,3 @@ });

UserSchema.plugin(acl.subject, {
allow: function() {
additionalKeys: function() {
return this.roles.map(function(role) {

@@ -92,2 +92,7 @@ return 'role:' + role;

```
Install
---
npm install mongoose-acl

@@ -94,0 +99,0 @@ Tests

@@ -45,5 +45,5 @@ var assert = require('assert');

it('creates $or query for all access keys and op', function() {
it('creates $or query for all access keys and perms', function() {
var find = sinon.spy(Test, 'find');
var cursor = Test.withAccess(subject, 'baz');
var cursor = Test.withAccess(subject, { baz: true });

@@ -50,0 +50,0 @@ assert.ok(find.calledOnce);

@@ -17,3 +17,3 @@ var assert = require('assert');

allow: function() {
additionalKeys: function() {
return this.roles.map(function(role) {

@@ -20,0 +20,0 @@ return 'role:' + role;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc