diff --git a/src/js/client.js b/src/js/client.js index dc6363e01..2bd86a9cc 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -2350,10 +2350,11 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.addMailbox = function (domain, name, userId, callback) { + Client.prototype.addMailbox = function (domain, name, ownerId, ownerType, callback) { var data = { name: name, - userId: userId + ownerId: ownerId, + ownerType: ownerType }; post('/api/v1/mail/' + domain + '/mailboxes', data, null, function (error, data, status) { @@ -2364,9 +2365,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; - Client.prototype.updateMailbox = function (domain, name, userId, callback) { + Client.prototype.updateMailbox = function (domain, name, ownerId, ownerType, callback) { var data = { - userId: userId + ownerId: ownerId, + ownerType: ownerType }; post('/api/v1/mail/' + domain + '/mailboxes/' + name, data, null, function (error, data, status) { diff --git a/src/views/email.html b/src/views/email.html index 2185d96d7..064043d3d 100644 --- a/src/views/email.html +++ b/src/views/email.html @@ -86,7 +86,7 @@
- +
@@ -111,7 +111,7 @@
- +
diff --git a/src/views/email.js b/src/views/email.js index 64f875fcd..4b2f001b0 100644 --- a/src/views/email.js +++ b/src/views/email.js @@ -16,7 +16,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio $scope.user = Client.getUserInfo(); $scope.config = Client.getConfig(); $scope.apps = Client.getInstalledApps(); - $scope.users = []; + $scope.owners = []; // users + groups $scope.incomingDomains = []; $scope.domain = null; $scope.adminDomain = null; @@ -359,7 +359,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio submit: function () { $scope.mailboxes.add.busy = true; - Client.addMailbox($scope.domain.domain, $scope.mailboxes.add.name, $scope.mailboxes.add.owner.id, function (error) { + Client.addMailbox($scope.domain.domain, $scope.mailboxes.add.name, $scope.mailboxes.add.owner.id, $scope.mailboxes.add.owner.type, function (error) { if (error) { $scope.mailboxes.add.busy = false; $scope.mailboxes.add.error = error; @@ -408,7 +408,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio $scope.mailboxes.edit.busy = true; // $scope.mailboxes.edit.owner is expected to be validated by the UI - Client.updateMailbox($scope.domain.domain, $scope.mailboxes.edit.name, $scope.mailboxes.edit.owner.id, function (error) { + Client.updateMailbox($scope.domain.domain, $scope.mailboxes.edit.name, $scope.mailboxes.edit.owner.id, $scope.mailboxes.edit.owner.type, function (error) { if (error) { $scope.mailboxes.edit.error = error; $scope.mailboxes.edit.busy = false; @@ -478,7 +478,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio if (error) return iteratorCallback(error); m.aliases = aliases; - m.owner = $scope.users.find(function (u) { return u.id === m.ownerId; }); // owner may not exist + m.owner = $scope.owners.find(function (o) { return o.id === m.ownerId; }); // owner may not exist m.ownerDisplayName = m.owner ? m.owner.display : ''; // this meta property is set when we get the user list iteratorCallback(); }); @@ -763,31 +763,36 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio if (error) return console.error('Unable to get user listing.', error); // ensure we have a display value available - $scope.users = users.map(function (u) { - u.display = u.username || u.email; - return u; + users.forEach(function (u) { + $scope.owners.push({ display: u.username || u.email, id: u.id, type: 'user' }); }); - $scope.users = users; + Client.getGroups(function (error, groups) { + if (error) return console.error('Unable to get group listing.', error); - Client.getDomains(function (error, result) { - if (error) return console.error('Unable to get view domain.', error); + groups.forEach(function (g) { + $scope.owners.push({ display: g.name, id: g.id, type: 'group' }); + }); - $scope.domain = result.filter(function (d) { return d.domain === domainName; })[0]; - $scope.adminDomain = result.filter(function (d) { return d.domain === $scope.config.adminDomain; })[0]; - $scope.refreshDomain(); + Client.getDomains(function (error, result) { + if (error) return console.error('Unable to get view domain.', error); - async.eachSeries(result, function (domain, iteratorDone) { - Client.getMailConfigForDomain(domain.domain, function (error, mailConfig) { - if (error) return console.error('Failed to fetch mail config for domain', domain.domain, error); + $scope.domain = result.filter(function (d) { return d.domain === domainName; })[0]; + $scope.adminDomain = result.filter(function (d) { return d.domain === $scope.config.adminDomain; })[0]; + $scope.refreshDomain(); - if (mailConfig.enabled) $scope.incomingDomains.push(domain); - iteratorDone(); + async.eachSeries(result, function (domain, iteratorDone) { + Client.getMailConfigForDomain(domain.domain, function (error, mailConfig) { + if (error) return console.error('Failed to fetch mail config for domain', domain.domain, error); + + if (mailConfig.enabled) $scope.incomingDomains.push(domain); + iteratorDone(); + }); + }, function iteratorDone(error) { + if (error) return console.error(error); + + $scope.ready = true; }); - }, function iteratorDone(error) { - if (error) return console.error(error); - - $scope.ready = true; }); }); });