Static ACL support array of properties now
This commit is contained in:
parent
84c65de38a
commit
9f705139f8
|
@ -256,10 +256,14 @@ module.exports = function(ACL) {
|
||||||
var staticACLs = [];
|
var staticACLs = [];
|
||||||
if (modelClass && modelClass.settings.acls) {
|
if (modelClass && modelClass.settings.acls) {
|
||||||
modelClass.settings.acls.forEach(function(acl) {
|
modelClass.settings.acls.forEach(function(acl) {
|
||||||
if (!acl.property || acl.property === ACL.ALL || property === acl.property) {
|
var prop = acl.property;
|
||||||
|
// We support static ACL property with array of string values.
|
||||||
|
if (Array.isArray(prop) && prop.indexOf(property) >= 0)
|
||||||
|
prop = property;
|
||||||
|
if (!prop || prop === ACL.ALL || property === prop) {
|
||||||
staticACLs.push(new ACL({
|
staticACLs.push(new ACL({
|
||||||
model: model,
|
model: model,
|
||||||
property: acl.property || ACL.ALL,
|
property: prop || ACL.ALL,
|
||||||
principalType: acl.principalType,
|
principalType: acl.principalType,
|
||||||
principalId: acl.principalId, // TODO: Should it be a name?
|
principalId: acl.principalId, // TODO: Should it be a name?
|
||||||
accessType: acl.accessType || ACL.ALL,
|
accessType: acl.accessType || ACL.ALL,
|
||||||
|
|
|
@ -266,6 +266,8 @@ describe('security ACLs', function() {
|
||||||
{principalType: ACL.USER, principalId: 'u001', property: 'name',
|
{principalType: ACL.USER, principalId: 'u001', property: 'name',
|
||||||
accessType: ACL.ALL, permission: ACL.ALLOW},
|
accessType: ACL.ALL, permission: ACL.ALLOW},
|
||||||
{principalType: ACL.USER, principalId: 'u002', property: 'findOne',
|
{principalType: ACL.USER, principalId: 'u002', property: 'findOne',
|
||||||
|
accessType: ACL.ALL, permission: ACL.ALLOW},
|
||||||
|
{principalType: ACL.USER, principalId: 'u003', property: ['findOne', 'findById'],
|
||||||
accessType: ACL.ALL, permission: ACL.ALLOW}
|
accessType: ACL.ALL, permission: ACL.ALLOW}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -274,7 +276,11 @@ describe('security ACLs', function() {
|
||||||
assert(staticACLs.length === 3);
|
assert(staticACLs.length === 3);
|
||||||
|
|
||||||
staticACLs = ACL.getStaticACLs('Model1', 'findOne');
|
staticACLs = ACL.getStaticACLs('Model1', 'findOne');
|
||||||
|
assert(staticACLs.length === 2);
|
||||||
|
|
||||||
|
staticACLs = ACL.getStaticACLs('Model1', 'findById');
|
||||||
assert(staticACLs.length === 1);
|
assert(staticACLs.length === 1);
|
||||||
|
assert(staticACLs[0].property === 'findById');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check access against LDL, ACL, and Role', function() {
|
it('should check access against LDL, ACL, and Role', function() {
|
||||||
|
|
Loading…
Reference in New Issue