Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.3] MACT-86: Explicitly blacklist non listed apps #164

Merged
merged 3 commits into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 48 additions & 19 deletions submodules/wizard/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,11 @@ define(function(require) {

monster.waterfall([
function(waterfallCallback) {
var parentAccountId = self.wizardGetStore('parentAccountId'),
appsAccountId = self.wizardGetStore('resellerAccountId', parentAccountId);

self.wizardGetAppList({
accountId: appsAccountId,
success: function(appList) {
waterfallCallback(null, appList);
},
Expand Down Expand Up @@ -1504,6 +1508,8 @@ define(function(require) {
*/
wizardReviewFormatData: function(data) {
var self = this,
parentAccountId = self.wizardGetStore('parentAccountId'),
appsAccountId = self.wizardGetStore('resellerAccountId', parentAccountId),
wizardAppFlags = self.appFlags.wizard,
formattedData = _
.chain(data)
Expand Down Expand Up @@ -1590,7 +1596,7 @@ define(function(require) {
formattedData.usageAndCallRestrictions.callRestrictionTypes = self.wizardGetStore('numberClassifiers');

// Set app list
formattedData.appRestrictions.apps = self.wizardGetStore('apps');
formattedData.appRestrictions.apps = self.wizardGetStore(['apps', appsAccountId]);

return formattedData;
},
Expand Down Expand Up @@ -2067,35 +2073,57 @@ define(function(require) {
var self = this,
accountId = args.accountId,
appRestrictions = args.appRestrictions,
callback = args.callback;

monster.waterfall([
function(waterfallCallback) {
if (appRestrictions.accessLevel === 'full') {
return waterfallCallback(null, []);
callback = args.callback,
getAllowedAppIds = function(next) {
if (appRestrictions.accessLevel === 'restricted') {
return next(null, appRestrictions.allowedAppIds);
}

var parentAccountId = self.wizardGetStore('parentAccountId'),
appsAccountId = self.wizardGetStore('resellerAccountId', parentAccountId);

// List all apps that the reseller or parent account has enabled
self.wizardGetAppList({
accountId: appsAccountId,
success: function(appList) {
waterfallCallback(null, appList);
next(null, _.map(appList, 'id'));
},
error: function(err) {
waterfallCallback(err);
next(err);
}
});
},
function(appList, waterfallCallback) {
var blacklist = _
.chain(appList)
.map('id')
.difference(appRestrictions.allowedAppIds)
.value();
getDefaultAppIds = function(next) {
self.wizardGetAppList({
accountId: accountId,
success: function(appList) {
next(null, _.map(appList, 'id'));
},
error: function(err) {
next(err);
}
});
};

monster.waterfall([
function getBlacklistAppIds(waterfallCallback) {
monster.parallel({
allowed: getAllowedAppIds,
defaults: getDefaultAppIds
}, function(err, appIds) {
waterfallCallback(err, _.difference(appIds.defaults, appIds.allowed));
});
},
function saveAppBlacklist(blacklistAppIds, waterfallCallback) {
if (_.isEmpty(blacklistAppIds)) {
return waterfallCallback(null);
}

self.wizardRequestResourceCreateOrUpdate({
resource: 'appsStore.updateBlacklist',
accountId: accountId,
data: {
blacklist: blacklist
blacklist: blacklistAppIds
},
callback: waterfallCallback
});
Expand Down Expand Up @@ -2267,18 +2295,19 @@ define(function(require) {
* Gets the stored list of apps available. If the list is not stored, then it is
* requested to the API.
* @param {Object} args
* @param {String} args.accountId Account ID from which the app list will be obtained
* @param {Function} args.success Success callback
* @param {Function} [args.error] Optional error callback
*/
wizardGetAppList: function(args) {
var self = this,
parentAccountId = self.wizardGetStore('parentAccountId');
accountId = args.accountId;

self.wizardGetDataList(_.merge({
storeKey: 'apps',
storeKey: 'apps.' + accountId,
requestData: function(reqArgs) {
monster.pub('apploader.getAppList', {
accountId: self.wizardGetStore('resellerAccountId', parentAccountId),
accountId: accountId,
scope: 'all',
forceFetch: true,
success: function(appList) {
Expand Down