Add apps.hasAccessTo()
This commit is contained in:
16
src/apps.js
16
src/apps.js
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user