Add apps.hasAccessTo()

This commit is contained in:
Johannes Zellner
2015-10-15 15:06:34 +02:00
parent c916a76e6b
commit fbc3ed0213
2 changed files with 38 additions and 0 deletions

View File

@@ -5,6 +5,8 @@
exports = module.exports = {
AppsError: AppsError,
hasAccessTo: hasAccessTo,
get: get,
getBySubdomain: getBySubdomain,
getAll: getAll,
@@ -222,6 +224,20 @@ function getIconUrlSync(app) {
return fs.existsSync(iconPath) ? '/api/v1/apps/' + app.id + '/icon' : null;
}
function hasAccessTo(app, user) {
assert.strictEqual(typeof app, 'object');
assert.strictEqual(typeof user, 'object');
function validator(entry) {
if (entry.indexOf('user-') === 0 && entry.slice('user-'.length) === user.id) return true;
return false;
}
if (app.accessRestriction === '') return true;
return app.accessRestriction.split(',').some(validator);
}
function get(appId, callback) {
assert.strictEqual(typeof appId, 'string');
assert.strictEqual(typeof callback, 'function');