diff --git a/src/apps.js b/src/apps.js index 8b0a59adf..022039509 100644 --- a/src/apps.js +++ b/src/apps.js @@ -12,6 +12,7 @@ exports = module.exports = { getBySubdomain: getBySubdomain, getByIpAddress: getByIpAddress, getAll: getAll, + getAllByUser: getAllByUser, purchase: purchase, install: install, configure: configure, @@ -357,6 +358,21 @@ function getAll(callback) { }); } +function getAllByUser(user, callback) { + assert.strictEqual(typeof user, 'object'); + assert.strictEqual(typeof callback, 'function'); + + getAll(function (error, result) { + if (error) return callback(error); + + async.filter(result, function (app, callback) { + hasAccessTo(app, user, function (error, hasAccess) { + callback(hasAccess); + }); + }, callback.bind(null, null)); // never error + }); +} + function purchase(appStoreId, callback) { assert.strictEqual(typeof appStoreId, 'string'); assert.strictEqual(typeof callback, 'function');