mongoose-acl
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -29,2 +29,15 @@ module.exports = function(schema, options) { | ||
schema.methods.revokeAccess = function(key, perms) { | ||
if (perms && this[options.path][key]) { | ||
this[options.path][key] = this[options.path][key].filter(function(perm) { | ||
return perms.indexOf(perm) === -1; | ||
}); | ||
} else if (key) { | ||
delete this[options.path][key]; | ||
} else { | ||
this[options.path] = {}; | ||
} | ||
this.markModified(options.path); | ||
}; | ||
schema.methods.keysWithAccess = function(perms) { | ||
@@ -83,2 +96,2 @@ perms || (perms = []); | ||
}; | ||
}; | ||
}; |
{ | ||
"name": "mongoose-acl", | ||
"description": "Mongoose ACL", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"author": "Scott Nelson <scott@scttnlsn.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -109,2 +109,30 @@ var assert = require('assert'); | ||
}); | ||
describe('when revoking permissions', function() { | ||
beforeEach(function() { | ||
model.setAccess('foo', ['a', 'b']); | ||
model.setAccess('bar', ['a']); | ||
}); | ||
it('revokes all permissions in acl', function() { | ||
model.revokeAccess(); | ||
assert.deepEqual(model._acl, {}); | ||
assert.ok(model.isModified('_acl')); | ||
}); | ||
it('revokes permissions for key in acl', function() { | ||
model.revokeAccess('foo'); | ||
assert.ok(!model._acl.foo); | ||
assert.deepEqual(model.getAccess('bar'), ['a']); | ||
assert.ok(model.isModified('_acl')); | ||
}); | ||
it('revokes specific permission in acl', function() { | ||
model.revokeAccess('foo', 'a'); | ||
assert.deepEqual(model.getAccess('foo'), ['b']); | ||
assert.deepEqual(model.getAccess('bar'), ['a']); | ||
assert.ok(model.isModified('_acl')); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16558
358