Page MenuHomeSealhub

and.js
No OneTemporary

"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const AccessStrategy = locreq("lib/chip-types/access-strategy.js");
const Query = require("../../../datastore/query.js");
function parse_params(app, params) {
return Object.keys(params).map(i => new AccessStrategy(app, params[i]));
}
module.exports = function(app) {
const and = {
name: "and",
getRestrictingQuery: async function(context, params) {
const access_strategies = parse_params(app, params);
const queries = await Promise.map(access_strategies, strategy =>
strategy.getRestrictingQuery(context)
);
if (queries.some(query => query instanceof Query.DenyAll)) {
return new Query.DenyAll();
}
const aggregated_pipeline = queries.reduce(
(acc, query) => acc.concat(query.toPipeline()),
[]
);
return Query.fromCustomPipeline(aggregated_pipeline);
},
item_sensitive: function(params) {
const access_strategies = parse_params(app, params);
return Promise.map(access_strategies, function(access_strategy) {
return access_strategy.is_item_sensitive();
}).reduce((a, b) => a || b);
},
checker_function: function(context, params, item) {
return and.item_sensitive(params).then(function(item_sensitive) {
if (item_sensitive && item === undefined) {
return undefined;
} else {
const access_strategies = parse_params(app, params);
const results = access_strategies.map(function(strategy) {
return strategy.check(context, item);
});
return Promise.all(results);
}
});
},
};
return and;
};

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 14:02 (16 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557148
Default Alt Text
and.js (1 KB)

Event Timeline