summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUdo Walter2020-01-19 22:18:35 +0100
committerUdo Walter2020-01-19 22:18:35 +0100
commit513a31d6f4c348168c5ea63df94cf05e23ca0f55 (patch)
tree768a770d9730b6ce841d487b2dbeccd56a09365b
parent[webapp] upgrade/migration from vuetify 1.5 to 2.X (diff)
parent[permissionmanager] rework list getters (diff)
downloadbas-513a31d6f4c348168c5ea63df94cf05e23ca0f55.tar.gz
bas-513a31d6f4c348168c5ea63df94cf05e23ca0f55.tar.xz
bas-513a31d6f4c348168c5ea63df94cf05e23ca0f55.zip
merge
-rw-r--r--server/lib/permissions/permissionhelper.js47
1 files changed, 11 insertions, 36 deletions
diff --git a/server/lib/permissions/permissionhelper.js b/server/lib/permissions/permissionhelper.js
index db2fc35..8e6b7cb 100644
--- a/server/lib/permissions/permissionhelper.js
+++ b/server/lib/permissions/permissionhelper.js
@@ -57,7 +57,7 @@ async function getAllowedGroups (userid, permissionName) {
else if (!user.roles[0].permissions[0].groupdependent) return [0]
// User has permission, permission is groupdependent
else {
- var permGrps = []
+ var result = []
for (let i = 0; i < user.roles.length; i++) {
var whitelist = []
var blacklist = []
@@ -70,26 +70,13 @@ async function getAllowedGroups (userid, permissionName) {
}
}
- // Get childs of white and blacklist groups
- var whiteSubChilds = await groupHelper.getAllChildren(whitelist)
- var blackSubChilds = await groupHelper.getAllChildren(blacklist)
-
- // Add all whitelist-ids to result.
- permGrps = permGrps.concat(whitelist.map(x => x.id))
- permGrps = permGrps.concat(whiteSubChilds.subgroups.map(s => s.id))
-
- // Filter out blacklist-ids from the result.
- blacklist = blacklist.map(x => x.id)
- blacklist = blacklist.concat(blackSubChilds.subgroups.map(x => x.id))
- for (let k = 0; k < blacklist.length; k++) {
- var index = permGrps.indexOf(blacklist[k])
- if (index > -1) {
- permGrps.splice(index, 1)
- }
- }
+ // Get childs of whitelist groups, filtered by blacklist
+ var whitelistChilds = await groupHelper.getAllChildren(whitelist, blacklist)
+ result = result.concat(whitelist.map(x => x.id))
+ result = result.concat(whitelistChilds.subgroups.map(s => s.id))
}
// Filter result for unique entries
- return permGrps.filter(function (elem, pos, arr) { return arr.indexOf(elem) === pos })
+ return result.filter(function (elem, pos, arr) { return arr.indexOf(elem) === pos })
}
}
@@ -148,7 +135,7 @@ async function getAllowedClients (userid, permissionName) {
else if (!user.roles[0].permissions[0].groupdependent) return [0]
// User has permission, permission is groupdependent
else {
- var permClients = []
+ var result = []
for (let i = 0; i < user.roles.length; i++) {
var whitelist = []
var blacklist = []
@@ -161,24 +148,12 @@ async function getAllowedClients (userid, permissionName) {
}
}
- // Get childs of white and blacklist groups
- var whiteSubChilds = await groupHelper.getAllChildren(whitelist)
- var blackSubChilds = await groupHelper.getAllChildren(blacklist)
-
- // Add all whitelist-ids to result.
- permClients = permClients.concat(whiteSubChilds.clients.map(s => s.id))
-
- // Filter out blacklist-ids from the result.
- blackSubChilds = blackSubChilds.clients.map(x => x.id)
- for (let k = 0; k < blackSubChilds.length; k++) {
- var index = permClients.indexOf(blackSubChilds[k])
- if (index > -1) {
- permClients.splice(index, 1)
- }
- }
+ // Get childs of whitelist groups, filtered by blacklist
+ var whitelistChilds = await groupHelper.getAllChildren(whitelist, blacklist)
+ result = result.concat(whitelistChilds.clients.map(c => c.id))
}
// Filter result for unique entries
- return permClients.filter(function (elem, pos, arr) { return arr.indexOf(elem) === pos })
+ return result.filter(function (elem, pos, arr) { return arr.indexOf(elem) === pos })
}
}