(feat) first pass of working code for ACL admin module

This commit is contained in:
Ludovic Marcotte
2015-10-06 16:38:16 -04:00
parent ad40bff91f
commit 4f4b00cc54
12 changed files with 612 additions and 50 deletions
@@ -4,7 +4,7 @@
(function() {
'use strict';
angular.module('SOGo.AdministrationUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.ContactsUI', 'SOGo.Authentication'])
angular.module('SOGo.AdministrationUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.Authentication', 'SOGo.PreferencesUI', 'SOGo.ContactsUI', 'SOGo.SchedulerUI'])
.config(configure)
.run(runBlock);
@@ -22,9 +22,6 @@
controller: 'AdministrationController',
controllerAs: 'app'
}
},
resolve: {
stateAdministration: stateAdministration
}
})
.state('administration.rights', {
@@ -34,18 +31,48 @@
templateUrl: 'rights.html'
}
}
})
.state('administration.rights.edit', {
url: '/:userId/:folderId/edit',
views: {
acl: {
templateUrl: 'UIxAdministrationAclEditor', // UI/Templates/Administration/UIxAdministrationAclEditor.wox
controller: 'AdministrationAclController',
controllerAs: 'acl'
}
},
resolve: {
stateFolder: stateFolder
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/rights');
}
stateFolder.$inject = ['$stateParams', 'User', 'AddressBook', 'Calendar'];
function stateFolder($stateParams, User, AddressBook, Calendar) {
var user = _.find(User.$users, function(user) {
return user.uid == $stateParams.userId;
});
/**
* @ngInject
*/
stateAdministration.$inject = ['Administration'];
function stateAdministration(Administration) {
return Administration;
var folder = _.find(user.$$folders, function(folder) {
return folder.name == $stateParams.folderId;
});
var o;
if (folder.type == "Appointment") {
o = new Calendar({id: folder.name.split('/').pop(),
owner: folder.owner,
name: folder.displayName});
} else {
o = new AddressBook({id: folder.name.split('/').pop(),
owner: folder.owner,
name: folder.displayName});
}
return o;
}
/**
@@ -0,0 +1,79 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* JavaScript for SOGoAdministration */
(function() {
'use strict';
/**
* @ngInject
*/
AdministrationAclController.$inject = ['$state', '$mdToast', 'stateFolder', 'User'];
function AdministrationAclController($state, $mdToast, stateFolder, User) {
var vm = this;
vm.selectedUser = null;
vm.getTemplate = getTemplate;
vm.selectUser = selectUser;
vm.save = save;
vm.userToAdd = '';
vm.searchText = '';
vm.userFilter = userFilter;
vm.addUser = addUser;
stateFolder.$acl.$users(stateFolder.owner).then(function(data) {
vm.users = data;
});
function getTemplate() {
if (angular.isDefined(stateFolder.$cards))
return '../' + stateFolder.owner + '/Contacts/' + stateFolder.id + '/UIxContactsUserRightsEditor';
return '../' + stateFolder.owner + '/Calendar/' + stateFolder.id + '/UIxCalUserRightsEditor';
}
function selectUser(user) {
if (vm.selectedUser == user) {
vm.selectedUser = null;
}
else {
vm.selectedUser = user;
vm.selectedUser.$rights();
}
}
function userFilter($query) {
return User.$filter($query, stateFolder.$acl.users);
}
function addUser(data) {
if (data) {
stateFolder.$acl.$addUser(data, stateFolder.owner).then(function() {
vm.userToAdd = '';
vm.searchText = '';
}, function(error) {
Dialog.alert(l('Warning'), error);
});
}
}
function save() {
stateFolder.$acl.$saveUsersRights(stateFolder.owner).then(function() {
$mdToast.show(
$mdToast.simple()
.content(l('ACLs saved'))
.position('top right')
.hideDelay(3000)
);
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured please try again.'));
});
}
}
angular
.module('SOGo.AdministrationUI')
.controller('AdministrationAclController', AdministrationAclController);
})();
@@ -7,18 +7,45 @@
/**
* @ngInject
*/
AdministrationController.$inject = ['$state', '$mdDialog', '$mdToast', 'Dialog', 'User', 'stateAdministration', 'Authentication'];
function AdministrationController($state, $mdDialog, $mdToast, Dialog, User, stateAdministration, Authentication) {
AdministrationController.$inject = ['$state', '$mdDialog', '$mdToast', 'Dialog', 'User', 'Administration'];
function AdministrationController($state, $mdDialog, $mdToast, Dialog, User, Administration) {
var vm = this;
vm.administration = stateAdministration;
vm.administration = Administration;
vm.selectedUser = null;
vm.users = User.$users;
vm.go = go;
vm.filter = filter;
vm.selectUser = selectUser;
vm.selectFolder = selectFolder;
function go(module) {
$state.go('administration.' + module);
}
function filter(searchText) {
User.$filter(searchText).then(function() {
});
}
function selectUser(i) {
if (vm.selectedUser == vm.users[i]) {
vm.selectedUser = null;
}
else {
// Fetch folders of specific type for selected user
vm.users[i].$folders().then(function() {
vm.selectedUser = vm.users[i];
});
}
}
function selectFolder(folder) {
$state.go('administration.rights.edit', {userId: vm.selectedUser.uid, folderId: folder.name});
}
}
angular
+30 -8
View File
@@ -35,10 +35,11 @@
/**
* @function $users
* @memberof Acl.prototype
* @param {Object} owner - the owner to use when fetching the ACL as it might not be the Settings.activeUser
* @desc Fetch the list of users that have specific rights for the current folder.
* @return a promise of an array of User objects
*/
Acl.prototype.$users = function() {
Acl.prototype.$users = function(owner) {
var _this = this,
deferred = Acl.$q.defer(),
user;
@@ -46,14 +47,20 @@
deferred.resolve(this.users);
}
else {
return Acl.$$resource.fetch(this.folderId, 'acls').then(function(response) {
var acls;
if (angular.isDefined(owner))
acls = Acl.$$resource.userResource(owner).fetch(this.folderId, 'acls');
else
acls = Acl.$$resource.fetch(this.folderId, 'acls');
return acls.then(function(response) {
_this.users = [];
//console.debug(JSON.stringify(users, undefined, 2));
angular.forEach(response.users, function(data) {
user = new Acl.$User(data);
user.canSubscribeUser = user.isSubscribed;
user.wasSubscribed = user.isSubscribed;
user.$rights = angular.bind(user, user.$acl, _this.folderId);
user.$rights = angular.bind(user, user.$acl, _this.folderId, owner);
_this.users.push(user);
});
deferred.resolve(_this.users);
@@ -67,9 +74,10 @@
* @function $addUser
* @memberof Acl.prototype
* @param {Object} user - a User object with minimal set of attributes (uid, isGroup, cn, c_email)
* @param {Object} owner - the owner to use when fetching the ACL as it might not be the Settings.activeUser
* @see {@link User.$filter}
*/
Acl.prototype.$addUser = function(user) {
Acl.prototype.$addUser = function(user, owner) {
var _this = this,
deferred = Acl.$q.defer(),
param = {uid: user.uid};
@@ -78,7 +86,14 @@
deferred.resolve();
}
else {
Acl.$$resource.fetch(this.folderId, 'addUserInAcls', param).then(function() {
var acls;
if (angular.isDefined(owner))
acls = Acl.$$resource.userResource(owner).fetch(this.folderId, 'addUserInAcls', param);
else
acls = Acl.$$resource.fetch(this.folderId, 'addUserInAcls', param);
acls.then(function() {
user.wasSubscribed = false;
user.userClass = user.isGroup ? 'group-user' : 'normal-user';
user.$rights = angular.bind(user, user.$acl, _this.folderId);
@@ -123,9 +138,10 @@
* @function $saveUsersRights
* @memberof Acl.prototype
* @desc Save user rights that have changed and subscribe users that have been selected.
* @param {Object} owner - the owner to use when fetching the ACL as it might not be the Settings.activeUser
* @return a promise that resolved only if the modifications and subscriptions were successful
*/
Acl.prototype.$saveUsersRights = function() {
Acl.prototype.$saveUsersRights = function(owner) {
var _this = this,
deferredSave = Acl.$q.defer(),
deferredSubscribe = Acl.$q.defer(),
@@ -140,8 +156,14 @@
}
});
if (users.length) {
Acl.$$resource.save(this.folderId, users, param)
.then(function() {
var acls;
if (angular.isDefined(owner))
acls = Acl.$$resource.userResource(owner).save(this.folderId, users, param);
else
acls = Acl.$$resource.save(this.folderId, users, param);
acls.then(function() {
// Save was successful; copy rights to shadow rights
angular.forEach(_this.users, function(user) {
if (user.$rightsAreDirty()) {
@@ -128,9 +128,10 @@
* @memberof User.prototype
* @desc Fetch the user rights associated to a specific folder and populate the 'rights' attribute.
* @param {string} the folder ID
* @param {Object} owner - the owner to use when fetching the ACL as it might not be the Settings.activeUser
* @return a promise
*/
User.prototype.$acl = function(folderId) {
User.prototype.$acl = function(folderId, owner) {
var _this = this,
deferred = User.$q.defer(),
param = {uid: this.uid};
@@ -138,7 +139,14 @@
deferred.resolve(this.rights);
}
else {
User.$$resource.fetch(folderId, 'userRights', param).then(function(data) {
var rights;
if (angular.isDefined(owner))
rights = User.$$resource.userResource(owner).fetch(folderId, 'userRights', param);
else
rights = User.$$resource.fetch(folderId, 'userRights', param);
rights.then(function(data) {
_this.rights = data;
// Convert numbers (0|1) to boolean values
//angular.forEach(_.keys(_this.rights), function(key) {