Note: I filed this question under lodash as I'm pretty sure it can help me solve that problem nicely, but haven't put my finger on it just now
I have an object describing different user roles and their permissions;
I will have something like 10-15 roles defined "like this" (this doesn't reflect the application code but the problem itself):
var role1 = {
views: {
v1: {access: true},
v2: {access: false},
v#: {access: false}
}
}
var role2 = {
views: {
v1: {access: false},
v2: {access: true},
v3: {access: true},
}
}
The user connected will have multiple roles; In that example it could be ['role1', 'role2']
, and out of this I need to construct a single permissions
object that will be a combination of all the props defined in all the user roles.
It is basically whitelist-based, where all "true" properties should override anything that was defined as false. Thus, the expected result should be:
permissions = {
views: {
v1: {access: true},
v2: {access: true},
v2: {access: true}
}
}
I'm not too sure how to tackle that one without relying on crazy nested loops
Here's a starting point in JSBin: http://jsbin.com/usaQejOJ/1/edit?js,console
Thanks for your help!