resource-access-list
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -35,5 +35,5 @@ 'use strict'; | ||
this.superRoles = opts.superRoles || ['admin']; | ||
this.ownerField = opts.ownerFiled || 'userId'; | ||
this.memberField = opts.memberField || 'teamId'; | ||
this.userModleName = opts.userModelName || 'user'; | ||
this.memberField = opts.memberField || 'member'; | ||
acl = this; | ||
@@ -69,23 +69,44 @@ } | ||
}, { | ||
key: 'resourceToModelName', | ||
value: function resourceToModelName(resource) { | ||
return resource.charAt(0).toUpperCase() + resource.slice(1, -1); | ||
} | ||
}, { | ||
key: 'getDynamicRole', | ||
value: function getDynamicRole(_ref) { | ||
var _this = this; | ||
var models = _ref.models, | ||
resource = _ref.resource, | ||
resourceId = _ref.resourceId, | ||
userId = _ref.userId; | ||
userId = _ref.userId, | ||
memberId = _ref.memberId; | ||
var roles = []; | ||
return new Promise(function (resolve, reject) { | ||
models[resource].findById(resourceId).then(function (ModelInst) { | ||
models[_this.resourceToModelName(resource)].findById(resourceId).then(function (ModelInst) { | ||
// make user owner relationship is setting and type is belongsTo | ||
if (ModelInst.owner && ModelInst.owner() && Number(ModelInst.owner().id) === Number(userId)) { | ||
roles.push('$owner'); | ||
return resolve(roles); | ||
} else if (ModelInst.member && ModelInst.member()) { | ||
return models[acl.userModleName].findById(userId).then(function (userInst) { | ||
if (userInst.member && userInst.member() && Number(userInst.member().id) === Number(ModelInst.member().id)) { | ||
roles.push('$member'); | ||
if (ModelInst && ModelInst.owner) { | ||
ModelInst.owner(function (err, owner) { | ||
if (err) { | ||
return reject(err); | ||
} else if (Number(owner.id) === Number(userId)) { | ||
roles.push('$owner'); | ||
} | ||
return resolve(roles); | ||
}); | ||
} else if (ModelInst && ModelInst.member) { | ||
// return models[acl.userModleName].findById(userId) | ||
// .then(userInst => { | ||
if (ModelInst.member) { | ||
ModelInst.member(function (err, member) { | ||
if (err) { | ||
return reject(err); | ||
} else if (Number(memberId) === Number(member.id)) { | ||
roles.push('$member'); | ||
} | ||
return resolve(roles); | ||
}); | ||
} | ||
// }) | ||
} else { | ||
@@ -118,3 +139,4 @@ return resolve(roles); | ||
models: req.app.models, | ||
userId: req.user.id | ||
userId: req.user.id, | ||
memberId: req.user[acl.memberField] || '' | ||
}).then(function (dynamicRole) { | ||
@@ -121,0 +143,0 @@ roles = roles.concat(dynamicRole); |
{ | ||
"name": "resource-access-list", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "This is a awesome project", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
11420
190