@rss/common
Advanced tools
Comparing version 0.0.30 to 0.0.31
@@ -41,7 +41,7 @@ 'use strict'; | ||
module.exports.hasManageAccessToInventory = function (inventory, user) { | ||
return module.exports.isChemAdmin(user.campusCode, user) || module.exports.isManagerOfInventory(inventory, user) || module.exports.isGroupOwner(inventory, user) || module.exports.isGroupDelegate(inventory, user); | ||
return user && module.exports.isChemAdmin(user.campusCode, user) || inventory && user && (module.exports.isManagerOfInventory(inventory, user) || module.exports.isGroupOwner(inventory, user) || module.exports.isGroupDelegate(inventory, user)); | ||
}; | ||
module.exports.isManagerOfInventory = function (inventory, user) { | ||
return inventory.owner.userId === user.userId || (inventory.permissions || []).find(function (permission) { | ||
return (inventory.owner || {}).userId === user.userId || (inventory.permissions || []).find(function (permission) { | ||
return permission.type === 'MANAGE' && permission.userId === user.userId; | ||
@@ -52,3 +52,3 @@ }); | ||
module.exports.isGroupOwner = function (inventory, user) { | ||
return inventory.groups.some(function (group) { | ||
return (inventory.groups || []).some(function (group) { | ||
return group.owner.userId === user.userId; | ||
@@ -59,4 +59,4 @@ }); | ||
module.exports.isGroupDelegate = function (inventory, user) { | ||
return user.roles.filter(function (role) { | ||
return inventory.groups.some(function (item) { | ||
return (user.roles || []).filter(function (role) { | ||
return (inventory.groups || []).some(function (item) { | ||
return item.id === role.groupId; | ||
@@ -63,0 +63,0 @@ }); |
{ | ||
"name": "@rss/common", | ||
"version": "0.0.30", | ||
"version": "0.0.31", | ||
"description": "common constant, classes, & helper", | ||
@@ -5,0 +5,0 @@ "author": "Risk & Safety Solution", |
@@ -32,16 +32,19 @@ const ROLES = require('../constant/core/roles.constant'); | ||
module.exports.hasManageAccessToInventory = (inventory, user) => | ||
module.exports.isChemAdmin(user.campusCode, user) || | ||
module.exports.isManagerOfInventory(inventory, user) || | ||
module.exports.isGroupOwner(inventory, user) || | ||
module.exports.isGroupDelegate(inventory, user); | ||
(user && module.exports.isChemAdmin(user.campusCode, user)) || | ||
(inventory && | ||
user && | ||
(module.exports.isManagerOfInventory(inventory, user) || | ||
module.exports.isGroupOwner(inventory, user) || | ||
module.exports.isGroupDelegate(inventory, user))); | ||
module.exports.isManagerOfInventory = (inventory, user) => | ||
inventory.owner.userId === user.userId || | ||
(inventory.owner || {}).userId === user.userId || | ||
(inventory.permissions || []).find((permission) => permission.type === 'MANAGE' && permission.userId === user.userId); | ||
module.exports.isGroupOwner = (inventory, user) => inventory.groups.some((group) => group.owner.userId === user.userId); | ||
module.exports.isGroupOwner = (inventory, user) => | ||
(inventory.groups || []).some((group) => group.owner.userId === user.userId); | ||
module.exports.isGroupDelegate = (inventory, user) => | ||
user.roles | ||
.filter((role) => inventory.groups.some((item) => item.id === role.groupId)) | ||
(user.roles || []) | ||
.filter((role) => (inventory.groups || []).some((item) => item.id === role.groupId)) | ||
.some((role) => role.role === ROLES.DELEGATE); | ||
@@ -48,0 +51,0 @@ |
702067
216
11983