Fixup spam configuration UI

This commit is contained in:
Girish Ramakrishnan
2020-08-22 13:01:25 -07:00
parent 08abe4bff2
commit 7c2322e6e0
3 changed files with 112 additions and 24 deletions

View File

@@ -145,26 +145,71 @@ angular.module('Application').controller('EmailsController', ['$scope', '$locati
}
};
$scope.blockAllowLists = {
$scope.spamConfig = {
busy: false,
error: null,
allowList: '',
blockList: '',
error: {},
acl: { whitelist: [], blacklist: [] },
customConfig: '',
config: '',
blacklist: '', // currently, we don't support whitelist because it requires user to understand a bit more of what he is doing
refresh: function () {
Client.getSpamCustomConfig(function (error, config) {
if (error) return console.error('Failed to get custom spam config', error);
$scope.spamConfig.customConfig = config;
});
Client.getSpamAcl(function (error, acl) {
if (error) return console.error('Failed to get spam acl', error);
$scope.spamConfig.acl = acl;
});
},
show: function() {
$scope.blockAllowLists.busy = false;
$scope.blockAllowLists.error = null;
$scope.blockAllowLists.allowList = '';
$scope.blockAllowLists.blockList = '';
$scope.spamConfig.busy = false;
$scope.spamConfig.error = {};
$scope.blockAllowListsChangeForm.$setUntouched();
$scope.blockAllowListsChangeForm.$setPristine();
$scope.spamConfig.blacklist = $scope.spamConfig.acl.blacklist.join('\n');
$scope.spamConfig.config = $scope.spamConfig.customConfig;
$('#blockAllowListsChangeModal').modal('show');
$scope.spamConfigChangeForm.$setUntouched();
$scope.spamConfigChangeForm.$setPristine();
$('#spamConfigChangeModal').modal('show');
},
submit: function () {
console.log('tbd');
$scope.spamConfig.busy = true;
$scope.spamConfig.error = {};
var blacklist = $scope.spamConfig.blacklist.split('\n').filter(function (l) { return l !== ''; });
Client.setSpamAcl({ blacklist: blacklist, whitelist: [] }, function (error) {
if (error) {
$scope.spamConfig.busy = false;
$scope.spamConfig.error.blacklist = error.message;
$scope.spamConfigChangeForm.blacklist.$setPristine();
return;
}
Client.setSpamCustomConfig($scope.spamConfig.config, function (error) {
if (error) {
$scope.spamConfig.busy = false;
$scope.spamConfig.error.config = error.message;
$scope.spamConfigChangeForm.config.$setPristine();
return;
}
$scope.spamConfig.busy = false;
$scope.spamConfig.refresh();
$('#spamConfigChangeModal').modal('hide');
});
});
}
},
@@ -251,6 +296,8 @@ angular.module('Application').controller('EmailsController', ['$scope', '$locati
$scope.maxEmailSize.currentSize = size;
});
$scope.spamConfig.refresh();
});
}