Skip to content

Commit

Permalink
feat(custom properties): naive implementation
Browse files Browse the repository at this point in the history
`satisfies` no longer ignores unknown properties in the SGL query.
  • Loading branch information
Exulansis committed Feb 26, 2021
1 parent 350d571 commit ff61b99
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/principals/grandma_extra.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"roles": ["grandparent"],
"extra": "something"
}
}
4 changes: 4 additions & 0 deletions examples/rules/extra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"grant": ["extra"],
"when": {"extra": "something"}
}
13 changes: 12 additions & 1 deletion sgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ function checkSatisfies(group, c, disjoint) {
}
return true;
}
}
} else {
const customProperty = Object.keys(c)[0]
for (var i = 0; i < group.length; ++i) {
var p = group[i];
if (Array.isArray(p[customProperty])) {
return p[customProperty].includes(c[customProperty])
} else {
return p[customProperty] === c[customProperty]
}
}
}

return false;
}

Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ describe('sgl', function() {
it('multirole_satisfies_1', function() {
assert(sgl.satisfies(p.employee_and_investor, r.enter_to_employee));
});

it('grandma_extra_satisfies_extra', function() {
assert(sgl.satisfies([p.grandma_extra, p.employee_and_investor], r.extra));
})

});
});

0 comments on commit ff61b99

Please sign in to comment.