@tipe/roles
Advanced tools
Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "@tipe/roles", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "", | ||
@@ -11,11 +11,11 @@ "main": "src/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/onespeed-io/tipe-roles.git" | ||
"url": "git+https://github.com/tipeio/tipe-roles.git" | ||
}, | ||
"author": "", | ||
"author": "Patrick <patrick@tipe.io>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/onespeed-io/tipe-roles/issues" | ||
"url": "https://github.com/tipeio/tipe-roles/issues" | ||
}, | ||
"homepage": "https://github.com/onespeed-io/tipe-roles#readme", | ||
"homepage": "https://github.com/tipeio/tipe-roles#readme", | ||
"dependencies": {} | ||
} |
@@ -55,3 +55,3 @@ | ||
Creator: 'Creator', | ||
Member: 'member', | ||
Member: 'Member', | ||
Editor: 'Editor' | ||
@@ -61,2 +61,5 @@ } | ||
exports.roleToPolicies = function roleToPolicies(role) { | ||
if (typeof role !== 'string') { | ||
throw new Error('roleToPolicies ' + role + ' needs to be type string') | ||
} | ||
switch (role) { | ||
@@ -255,1 +258,39 @@ case exports.roles.Owner: return exports.owner().policies | ||
} | ||
exports.isAllowed = function isAllowed(policy, id, type, roles, onError) { | ||
// list of all policies in project plus org | ||
return exports.getRoles(id, type, roles).indexOf(policy) !== -1 | ||
} | ||
exports.getRoles = function getRoles(id, type, roles, onError) { | ||
if (type === 'ORG_ROLE') { | ||
const orgRole = roles.find(role => role.org.toString() === id.toString()) | ||
if (!orgRole) { | ||
return onError({ type: 'ORG_ROLE', id, type, roles }) | ||
} | ||
return roleToPolicies(orgRole.roles) | ||
} | ||
const orgs = {} | ||
const projectRole = roles | ||
.filter(function(role) { | ||
if (role.type === 'ORG_ROLE') { | ||
// refactor roles to role | ||
orgs[role.org] = role.role || role.roles | ||
} | ||
return role.type === 'PROJECT_ROLE' | ||
}) | ||
.find(function(role) { return role.project.toString() === id.toString() }) | ||
if (!projectRole) { | ||
return onError({ type: 'PROJECT_ROLE', id, type, roles }) | ||
} | ||
const roles = [].concat( | ||
orgs[projectRole.org], | ||
// refactor roles to role | ||
projectRole.role || projectRole.roles | ||
) | ||
return roles.map(function(role) { return roleToPolicies(role) }) | ||
} |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10333
253
2