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

resource-access-list

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resource-access-list - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

44

dist/index.js

@@ -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",

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