Skip to content

Commit

Permalink
Support multiple value per key
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscogouveia committed Feb 15, 2016
1 parent 948fd8b commit e06ca4e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/index.js
Expand Up @@ -64,7 +64,7 @@ internals.evaluatePolicy = (item, dataRetriever, callback) => {
* Evaluate a single rule.
*
* {
* 'target': ['any-of', item1, ..., itemN],
* 'target': [...],
* 'effect': PERMIT, DENY
* }
**/
Expand Down Expand Up @@ -133,8 +133,8 @@ internals.evaluateTarget = (target, dataRetriever, callback) => {
}

for (const index in target) {
let fullyMatches = true;
const element = target[index];
let fullyMatches = true;

for (const key in element) {
const value = dataRetriever.get(key);
Expand All @@ -157,19 +157,31 @@ internals.evaluateTarget = (target, dataRetriever, callback) => {
return callback(null, false);
};

/**
* If target has more than one value, all of them should match
**/
internals._targetApplies = (target, value) => {

if (target === value) {
return true;
}

if (value instanceof Array) {
if (value.indexOf(target) !== -1) {
return true;
if (!(value instanceof Array)) {
value = [value];
}

if (!(target instanceof Array)) {
target = [target];
}

for (const index in target) {
if (value.indexOf(target[index]) === -1) {
// At least one doesn't match
return false;
}
}

return false;
return true;
};

/**
Expand Down

0 comments on commit e06ca4e

Please sign in to comment.