openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
53 lines (46 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.inGroup = inGroup;
exports.getUserViewableChannels = getUserViewableChannels;
exports.getUserRerunableChannels = getUserRerunableChannels;
var _channels = require("../model/channels");
function inGroup(group, user) {
return user.groups.indexOf(group) >= 0;
}
/**
* A promise returning function that returns the list
* of viewable channels for a user.
*/
function getUserViewableChannels(user, access = 'txViewAcl') {
// if admin find all channels
if (inGroup('admin', user)) {
return _channels.ChannelModelAPI.find({}).exec();
} else {
// otherwise only channels that this user has access to
return _channels.ChannelModelAPI.find({
[access]: {
$in: user.groups
}
}).exec();
}
}
/**
* A promise returning function that returns the list
* of rerunnable channels for a user.
*/
function getUserRerunableChannels(user) {
// if admin allow all channel
if (inGroup('admin', user)) {
return _channels.ChannelModelAPI.find({}).exec();
} else {
// otherwise figure out what this user can rerun
return _channels.ChannelModelAPI.find({
txRerunAcl: {
$in: user.groups
}
}).exec();
}
}
//# sourceMappingURL=authorisation.js.map