diff --git a/UI/Common/UIxUserRightsEditor.m b/UI/Common/UIxUserRightsEditor.m index 3519abc0e..2208c50c2 100644 --- a/UI/Common/UIxUserRightsEditor.m +++ b/UI/Common/UIxUserRightsEditor.m @@ -119,29 +119,62 @@ if ([newUID length] > 0) { if (!defaultUserID) - ASSIGN (defaultUserID, [[self clientObject] defaultUserID]); + ASSIGN (defaultUserID, [[self clientObject] defaultUserID]); um = [SOGoUserManager sharedUserManager]; - if ([newUID isEqualToString: defaultUserID] - || [newUID isEqualToString: @"anonymous"] - || [[um getEmailForUID: newUID] length] > 0) - { - if (![newUID hasPrefix: @"@"]) - { + if ([newUID isEqualToString: defaultUserID] || [newUID isEqualToString: @"anonymous"] + || [[um getEmailForUID: newUID] length] > 0) + { + if (![newUID hasPrefix: @"@"]) + { domain = [[context activeUser] domain]; - group = [SOGoGroup groupWithIdentifier: newUID inDomain: domain]; - if (group) - newUID = [NSString stringWithFormat: @"@%@", newUID]; - } + group = [SOGoGroup groupWithIdentifier: newUID inDomain: domain]; + if (group) + newUID = [NSString stringWithFormat: @"@%@", newUID]; + } + ASSIGN (uid, newUID); + clientObject = [self clientObject]; + [userRights addObjectsFromArray: [clientObject aclsForUser: uid]]; - ASSIGN (uid, newUID); - clientObject = [self clientObject]; - [userRights addObjectsFromArray: [clientObject aclsForUser: uid]]; - - response = YES; - } + response = YES; + } } + return response; +} +- (BOOL) _initRightsWithParameter:(NSString *) newUID +{ + BOOL response; + NSString *domain; + SOGoUserManager *um; + SOGoObject *clientObject; + SOGoGroup *group; + + response = NO; + + if ([newUID length] > 0) + { + if (!defaultUserID) + ASSIGN (defaultUserID, [[self clientObject] defaultUserID]); + + um = [SOGoUserManager sharedUserManager]; + if ([newUID isEqualToString: defaultUserID] || [newUID isEqualToString: @"anonymous"] + || [[um getEmailForUID: newUID] length] > 0) + { + if (![newUID hasPrefix: @"@"]) + { + domain = [[context activeUser] domain]; + group = [SOGoGroup groupWithIdentifier: newUID inDomain: domain]; + if (group) + newUID = [NSString stringWithFormat: @"@%@", newUID]; + } + ASSIGN (uid, newUID); + clientObject = [self clientObject]; + [userRights addObjectsFromArray: [clientObject aclsForUser: uid]]; + + response = YES; + } + } return response; } @@ -186,20 +219,32 @@ - (id ) saveUserRightsAction { id response; + WORequest *value; SOGoDomainDefaults *dd; + NSDictionary *jsonObject, *currentObject; + NSEnumerator *enumerator; + NSArray *o; + id key; - if (![self _initRights]) - response = [NSException exceptionWithHTTPStatus: 403 - reason: @"No such user."]; - else + value = [[self context] request]; + jsonObject = [[value contentAsString] objectFromJSONString]; + enumerator = [jsonObject keyEnumerator]; + + while((key = [enumerator nextObject])) + { + currentObject = [jsonObject objectForKey: key]; + if(![self _initRightsWithParameter: [currentObject objectForKey: @"UID"]]) { - NSArray *o; - - o = [NSArray arrayWithArray: userRights]; - - [self updateRights]; + response = [self responseWithStatus: 403 + andString: @"No such user."]; + return response; + } + else + { + [self updateRights:[currentObject objectForKey: @"aclOptions"]]; [[self clientObject] setRoles: userRights forUser: uid]; - + + o = [NSArray arrayWithArray: userRights]; dd = [[context activeUser] domainDefaults]; if (![o isEqualToArray: userRights] && [dd aclSendEMailNotifications]) [self sendACLAdvisoryTemplateForObject: [self clientObject]]; @@ -234,10 +279,6 @@ [userRights removeObjectsInArray: list]; } -- (void) prepareRightsForm -{ -} - - (void) updateRights { [self subclassResponsibility: _cmd]; diff --git a/UI/Templates/ContactsUI/UIxContactFoldersView.wox b/UI/Templates/ContactsUI/UIxContactFoldersView.wox index 14c2dabe6..69f8cf59b 100644 --- a/UI/Templates/ContactsUI/UIxContactFoldersView.wox +++ b/UI/Templates/ContactsUI/UIxContactFoldersView.wox @@ -61,6 +61,77 @@
+ +
diff --git a/UI/WebServerResources/js/Common/resource.js b/UI/WebServerResources/js/Common/resource.js index 2c78f7416..f5ce3868e 100644 --- a/UI/WebServerResources/js/Common/resource.js +++ b/UI/WebServerResources/js/Common/resource.js @@ -108,4 +108,41 @@ return deferred.promise; }; + + /** + * @function fetch + * @desc Fetch resources using a specific object, action and/or parameters + * @param {string} object_id - the object on which the action will be applied (ex: addressbook, calendar) + * @param {string} action - the action to be used in the URL + * @param {string} params - the url parameter + */ + Resource.prototype.fetch = function(object_id, action, params) { + var deferred = this._q.defer(); + var object_id_path = object_id ? ("/" + object_id) : ""; + var action_path = action ? ("/" + action) : ""; + var params_path = params ? ("?" + params) : ""; + + var path = this._path + object_id_path + action_path + params_path; + + this._http + .get(path) + .success(deferred.resolve) + .error(deferred.reject); + + return deferred.promise; + }; + + Resource.prototype.saveAclUsers = function(object_id, action, data) { + var deferred = this._q.defer(); + var object_id_path = object_id ? ("/" + object_id) : ""; + var action_path = action ? ("/" + action) : ""; + var path = this._path + object_id_path + action_path; + + this._http + .post(path, data) + .success(deferred.resolve) + .error(deferred.reject); + + return deferred.promise; + }; })(); diff --git a/UI/WebServerResources/js/ContactsUI.js b/UI/WebServerResources/js/ContactsUI.js index d2f756a72..823bddd1d 100644 --- a/UI/WebServerResources/js/ContactsUI.js +++ b/UI/WebServerResources/js/ContactsUI.js @@ -177,6 +177,80 @@ $scope.closeModal = function() { $modalInstance.close(); }; + $scope.saveModal = function() { + if(Object.keys(dirtyObjects).length > 0) { + $scope.AclUsers.saveUsersRights(dirtyObjects); + } + $modalInstance.close(); + }; + $scope.removeUser = function() { + if ($scope.userSelected) { + if(dirtyObjects[$scope.userSelected.UID]) + delete dirtyObjects[$scope.userSelected.UID]; + $scope.AclUsers.removeUser($scope.userSelected); + $scope.AclUsers.getUsers().then(function(data) { + $scope.users = data; + }); + $scope.userSelected = {}; + } + }; + $scope.addUser = function (user) { + if (user) { + angular.forEach($scope.userObjects, function(userObject) { + if (user.indexOf(userObject.uid) != -1) { + var test = true; + angular.forEach($scope.users, function(userData) { + if (user.indexOf(userData.UID) != -1) { + test = false; + } + }) + if (test) { + $scope.AclUsers.addUser(userObject.uid); + $scope.AclUsers.getUsers().then(function(data) { + $scope.users = data; + }); + } + else { + // TODO : Write a better msg and add the string inside the .string + Dialog.alert(l('Warning'), l('This user is already added to your AclUsers list')); + } + } + }); + } + }; + $scope.selectUser = function(index) { + // Check if it is a different user + if ($scope.userSelected != $scope.users[index]){ + $scope.userSelected = {}; + $scope.selected = index; + $scope.userSelected = $scope.users[index]; + + if (dirtyObjects[$scope.userSelected.UID]) { + $scope.userSelected.aclOptions = dirtyObjects[$scope.userSelected.UID].aclOptions; + } + else { + $scope.AclUsers.openRightsForUserId($scope.userSelected.UID).then(function(userRights) { + $scope.userSelected.aclOptions = userRights; + }); + } + } + }; + $scope.getContacts = function(value){ + return $scope.AclUsers.searchUsers(value).then(function(response) { + $scope.usersFound = []; + $scope.userObjects = response; + angular.forEach(response, function(userObject){ + $scope.usersFound.push(userObject.displayName + " <" + userObject.email + ">"); + }); + return $scope.usersFound; + }); + }; + $scope.dirtyObjects = function() { + dirtyObjects[$scope.userSelected.UID] = $scope.userSelected; + }; + $scope.displayUserRights = function() { + return ($scope.userSelected && $scope.userSelected.UID != "anonymous") ? true : false; + }; } }); };