Fixup catchall to use mailboxes instead of users

This commit is contained in:
Johannes Zellner
2018-04-12 13:02:32 +02:00
parent 404c280595
commit 290b44fbb7
2 changed files with 43 additions and 24 deletions
+41 -22
View File
@@ -45,18 +45,25 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
};
$scope.catchall = {
addresses: [],
availableAddresses: [],
mailboxes: [],
busy: false,
submit: function () {
$scope.catchall.busy = true;
Client.setCatchallAddresses($scope.selectedDomain.domain, $scope.catchall.addresses, function (error) {
var addresses = $scope.catchall.mailboxes.map(function (m) { return m.name; });
Client.setCatchallAddresses($scope.selectedDomain.domain, addresses, function (error) {
if (error) console.error('Unable to add catchall address.', error);
$scope.catchall.busy = false;
});
},
refresh: function () {
$scope.catchall.mailboxes = $scope.selectedDomain.mailConfig.catchAll.map(function (name) {
return $scope.mailboxes.mailboxes.find(function (m) { return m.name === name; });
}).filter(function (m) { return !!m; });
}
};
@@ -161,11 +168,15 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
}
},
refresh: function () {
refresh: function (callback) {
callback = typeof callback === 'function' ? callback : function (error) { if (error) return console.error(error); };
Client.listMailingLists($scope.selectedDomain.domain, function (error, result) {
if (error) return console.error(error);
if (error) return callback(error);
$scope.mailinglists.mailinglists = result;
callback();
});
}
};
@@ -229,9 +240,13 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
}
$scope.mailboxes.add.reset();
$scope.mailboxes.refresh();
$scope.mailboxes.refresh(function (error) {
if (error) return console.error(error);
$('#mailboxAddModal').modal('hide');
$scope.catchall.refresh();
$('#mailboxAddModal').modal('hide');
});
});
}
},
@@ -301,25 +316,33 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
if (error) return console.error(error);
$scope.mailboxes.remove.mailbox = null;
$scope.mailboxes.refresh();
$scope.mailboxes.refresh(function (error) {
if (error) return console.error(error);
$('#mailboxRemoveModal').modal('hide');
$scope.catchall.refresh();
$('#mailboxRemoveModal').modal('hide');
});
});
}
},
refresh: function () {
refresh: function (callback) {
callback = typeof callback === 'function' ? callback : function (error) { if (error) return console.error(error); };
Client.getMailboxes($scope.selectedDomain.domain, function (error, mailboxes) {
if (error) return console.error(error);
if (error) return callback(error);
Client.listAliases($scope.selectedDomain.domain, function (error, aliases) {
if (error) return console.error(error);
if (error) return callback(error);
$scope.mailboxes.mailboxes = mailboxes.map(function (m) {
m.aliases = aliases.filter(function (a) { return a.aliasTarget === m.name; }).map(function (a) { return a.name; }).join(',');
m.owner = $scope.users.find(function (u) { return u.id === m.ownerId; });
return m;
});
callback();
});
});
}
@@ -513,20 +536,16 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
}
}
// catch-all, only allow users with a Cloudron email address
$scope.catchall.availableAddresses = $scope.users.filter(function (u) { return !!u.username && !!u.email; }).map(function (u) { return u.username; });
// dedupe in case to avoid angular breakage
$scope.catchall.addresses = mailConfig.catchAll.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
});
// amend to selected domain to be available for the UI
$scope.selectedDomain.mailConfig = mailConfig;
$scope.selectedDomain.mailStatus = {};
$scope.mailboxes.refresh();
$scope.mailinglists.refresh();
$scope.mailboxes.refresh(function (error) {
if (error) console.error(error);
$scope.mailinglists.refresh();
$scope.catchall.refresh();
});
// we will fetch the status without blocking the ui
Client.getMailStatusForDomain($scope.selectedDomain.domain, function (error, mailStatus) {