Created user-modal.js, code refactoring

Conflicts:

	UI/Common/UIxAclEditor.m
	UI/Common/UIxUserRightsEditor.m
	UI/Common/product.plist
	UI/Contacts/UIxContactsUserRightsEditor.m
	UI/Templates/ContactsUI/UIxContactFoldersView.wox
	UI/WebServerResources/js/Common/resource.js
	UI/WebServerResources/js/ContactsUI.js
pull/91/head
Alexandre Cloutier 2014-10-08 14:08:54 -04:00 committed by Francis Lachapelle
parent f3c26671af
commit 9113ca54f7
11 changed files with 338 additions and 139 deletions

View File

@ -80,7 +80,7 @@
return defaultUserID;
}
- (NSArray *) usersForObject
- (id <WOActionResults>) aclsAction
{
NSEnumerator *aclsEnum;
NSString *currentUID, *ownerLogin;
@ -105,14 +105,14 @@
object = [NSDictionary dictionaryWithObjectsAndKeys: currentUser, @"uid",
[self currentUserClass], @"userClass",
[self currentUserDisplayName], @"displayName",
[NSNumber numberWithBool:[self currentUserIsSubscribed]], @"isSubscribed", nil];
[users setObject:object forKey: currentUID];
[NSNumber numberWithBool: [self currentUserIsSubscribed]], @"isSubscribed", nil];
[users setObject: object forKey: currentUID];
}
}
// Adding the Any authenticated user and the public access
[users setObject:[NSDictionary dictionaryWithObjectsAndKeys: @"<default>", @"uid", [self labelForKey: @"Any Authenticated User"], @"displayName", @"public-user", @"userClass", nil] forKey: @"<default>"];
[users setObject: [NSDictionary dictionaryWithObjectsAndKeys: @"<default>", @"uid", [self labelForKey: @"Any Authenticated User"], @"displayName", @"public-user", @"userClass", nil] forKey: @"<default>"];
if ([self isPublicAccessEnabled])
[users setObject:[NSDictionary dictionaryWithObjectsAndKeys: @"anonymous", @"uid", [self labelForKey: @"Public Access"], @"displayName", @"public-user", @"userClass", nil] forKey: @"anonymous"];
[users setObject: [NSDictionary dictionaryWithObjectsAndKeys: @"anonymous", @"uid", [self labelForKey: @"Public Access"], @"displayName", @"public-user", @"userClass", nil] forKey: @"anonymous"];
prepared = YES;
}

View File

@ -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) _initRightsForUserID:(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;
}
@ -150,14 +183,13 @@
id <WOActionResults> response;
if (![self _initRights])
response = [NSException exceptionWithHTTPStatus: 403
reason: @"No such user."];
else
{
[self prepareRightsForm];
response = self;
}
response = [self responseWithStatus: 403
andString: @"No such user."];
else {
//[self prepareRightsForm];
response = [self responseWithStatus: 200
andString:[[self userRightsForObject] jsonRepresentation]];
}
return response;
}
@ -186,32 +218,31 @@
- (id <WOActionResults>) saveUserRightsAction
{
id <WOActionResults> response;
WORequest *request;
SOGoDomainDefaults *dd;
NSDictionary *jsonObject, *currentObject;
NSDictionary *dirtyUsers, *currentUser, *jsonResponse;;
NSEnumerator *enumerator;
NSString *uid;
NSArray *o;
id key;
value = [[self context] request];
jsonObject = [[value contentAsString] objectFromJSONString];
enumerator = [jsonObject keyEnumerator];
request = [[self context] request];
dirtyUsers = [[request contentAsString] objectFromJSONString];
enumerator = [dirtyUsers keyEnumerator];
while((key = [enumerator nextObject]))
while((uid = [enumerator nextObject]))
{
currentObject = [jsonObject objectForKey: key];
if(![self _initRightsWithParameter: [currentObject objectForKey: @"uid"]])
currentUser = [dirtyUsers objectForKey: uid];
if(!([self _initRightsForUserID: [currentUser objectForKey: @"uid"]]))
{
jsonResponse = [NSDictionary dictionaryWithObject: @"No such user." forKey: @"error"];
response = [self responseWithStatus: 403
andString: @"No such user."];
andString: [jsonResponse jsonRepresentation]];
return response;
}
else
{
NSArray *o;
o = [NSArray arrayWithArray: userRights];
[self updateRights];
[self updateRights:[currentUser objectForKey: @"aclOptions"]];
[[self clientObject] setRoles: userRights forUser: uid];
dd = [[context activeUser] domainDefaults];
@ -220,7 +251,8 @@
response = [self jsCloseWithRefreshMethod: nil];
}
}
response = [self responseWithStatus: 200];
return response;
}

View File

@ -45,10 +45,6 @@
actionClass = "UIxObjectActions";
actionName = "delete";
};
acls = {
protectedBy = "ReadAcls";
pageName = "UIxAclEditor";
};
saveAcls = {
protectedBy = "Change Permissions";
pageName = "UIxAclEditor";
@ -63,6 +59,11 @@
pageName = "UIxUserRightsEditor";
actionName = "saveUserRights";
};
acls = {
protectedBy = "ReadAcls";
pageName = "UIxAclEditor";
actionName = "acls";
};
};
};
SOGoParentFolder = {

View File

@ -29,14 +29,6 @@
@implementation UIxContactsUserRightsEditor
- (void) setUserCanCreateObjects: (BOOL) userCanCreateObjects
{
if (userCanCreateObjects)
[self appendRight: SOGoRole_ObjectCreator];
else
[self removeRight: SOGoRole_ObjectCreator];
}
- (BOOL) userCanCreateObjects
{
return [userRights containsObject: SOGoRole_ObjectCreator];

View File

@ -8,7 +8,7 @@
xmlns:label="OGo:label"
xmlns:rsrc="OGo:url"
const:userDefaultsKeys="SOGoContactsCategories"
const:jsFiles="Common/resource.js, Contacts/card-model.js, Contacts/addressbook-model.js"
const:jsFiles="Common/user-model.js, Common/acl-model.js, Common/resource.js, Contacts/card-model.js, Contacts/addressbook-model.js"
className="UIxPageFrame"
title="name"
var:popup="isPopup">
@ -66,11 +66,77 @@
<!-- modal for addressbook sharing options -->
<script type="text/ng-template" id="addressbookSharing.html">
<h2>Sharing</h2>
<p class="lead"></p>
<p></p>
<span class="close-reveal-modal" data-ng-click="closeModal()"><i class="icon-close"><!-- close --></i></span>
</script>
<div id="modalACL">
<h2><var:string label:value="Sharing"/></h2>
<div>
<!-- left side -->
<div id="usersList">
<div>
<ul>
<li ng-repeat="user in users | orderBy:['userClass', 'displayName']" data-ng-click="selectUser(user)"
data-ng-class="{_selected: user==selected}">
<span>
<i data-ng-class="(user.userClass == 'public-user') ? 'icon-user4' : 'icon-vcard'"><!-- spacer --></i>
{{user.displayName}}</span>
<span class="subscriptionArea" data-ng-hide="user.userClass == 'public-user'">
<input type="checkbox" ng-model="user.isSubscribed" ng-checked="user.isSubscribed"
ng-disabled="!user.canSubscribeUser" ng-change="markUserAsDirty(user)" />
<span><var:string label:value="Subscribe User"/></span></span>
</li>
</ul>
</div>
<div>
<form ng-submit="addUser(userToAdd)" class="addContactsToolbar">
<input type="search" ng-model="userToAdd" label:placeholder="Add..." typeahead-wait-ms="1000"
typeahead="user as user.displayName for user in User.$filter($viewValue) | filter:$viewValue" class="form-control" />
<button type="submit" ><var:string label:value="Add User"/></button>
<button type="button" ng-disabled="userIsReadOnly()" data-ng-click="removeUser()"><var:string label:value="Remove User"/></button>
</form>
</div>
</div>
<!-- right side -->
<div id="AccessRightList">
<input id="uid" type="hidden" name="uid" var:value="uid"/>
<div class="title">
<label><var:string label:value="Access rights to"/><br />
<span id="folderName" class="value">{{addressbook.name}}</span></label>
<label><var:string label:value="For user"/><br />
<span class="value">{{userSelected.displayName}}</span></label>
</div>
<div class="calendarUserRights">
<ul>
<li data-ng-show="displayUserRights()">
<input type="checkbox" ng-checked="userSelected.aclOptions.canCreateObjects"
ng-model="userSelected.aclOptions.canCreateObjects" ng-change="markUserAsDirty()" />
<var:string label:value="This person can add cards to this addressbook."/></li>
<li data-ng-show="displayUserRights()" ng-model="displayUserRights">
<input type="checkbox" ng-checked="userSelected.aclOptions.canEditObjects"
ng-model="userSelected.aclOptions.canEditObjects" ng-change="markUserAsDirty()" />
<var:string label:value="This person can edit the cards of this addressbook."/></li>
<li data-ng-show="displayUserRights()" ng-model="displayUserRights">
<input type="checkbox" ng-checked="userSelected.aclOptions.canEraseObjects"
ng-model="userSelected.aclOptions.canEraseObjects" ng-change="markUserAsDirty()" />
<var:string label:value="This person can erase cards from this addressbook."/></li>
<li data-ng-hide="!userSelected.displayName">
<input type="checkbox" ng-checked="userSelected.aclOptions.canViewObjects"
ng-model="userSelected.aclOptions.canViewObjects" ng-change="markUserAsDirty()" />
<var:string label:value="This person can read the cards of this addressbook."/></li>
</ul>
</div>
</div>
</div>
<div id="aclButtons">
<button data-ng-click="closeModal()"><var:string label:value="Close"/></button>
<button data-ng-click="saveModal()"><var:string label:value="Save"/></button>
</div>
</div>
<span class="close-reveal-modal" data-ng-click="closeModal()"><i class="icon-close"><!-- close --></i></span>
</script>
<script type="text/ng-template" id="addressbooks.html">

View File

@ -8,7 +8,7 @@
xmlns:label="OGo:label"
xmlns:rsrc="OGo:url"
const:userDefaultsKeys="SOGoContactsCategories"
const:jsFiles="Common/resource.js, Common/acl-model.js, Contacts/card-model.js, Contacts/addressbook-model.js"
const:jsFiles="Common/user-model.js, Common/resource.js, Common/acl-model.js, Contacts/card-model.js, Contacts/addressbook-model.js"
className="UIxPageFrame"
title="name"
var:popup="isPopup">
@ -367,15 +367,15 @@
<script type="text/ng-template" id="acl-modal.html">
<ion-modal-view>
<ion-header-bar class="bar-positive">
<div class="buttons" ng-show="onGoingSearch">
<button class="button button-icon" ng-click="closeModal()">close</button>
</div>
<div class="buttons" ng-hide="onGoingSearch">
<button class="button button-icon" ng-click="cancelSearch()">back</button>
<button class="button button-icon" ng-click="closeModal()"><var:string label:value="Close"/></button>
</div>
<div class="buttons" ng-show="onGoingSearch">
<button class="button button-icon" ng-click="cancelSearch()"><var:string label:value="Back"/></button>
</div>
<h1 class="title">{{addressbook.name}}</h1>
<div class="buttons">
<button class="button button-icon" ng-click="saveModal()">save</button>
<button class="button button-icon" ng-click="saveModal()"><var:string label:value="Save"/></button>
</div>
</ion-header-bar>
<ion-content>
@ -409,8 +409,8 @@
</ion-list>
</ion-content>
<ion-footer-bar class="bar-footer">
<ion-search class="item item-light" placeholder="Search a user/group" min-length="2" model="usersFound"
source="getContacts(str)" clear="cancelSearch()">
<ion-search class="item item-light" label:placeholder="Add..." min-length="2" model="usersFound"
source="searchUsers(search)" clear="cancelSearch()">
</ion-search>
</ion-footer-bar>
</ion-modal-view>

View File

@ -1,10 +1,8 @@
(function() {
'use strict';
function AclUsers(addressbook) {
this.addressbook_id = addressbook.id;
this.addressbook_name = addressbook.name;
this.addressbook_owner = addressbook.owner;
function AclUsers(folder) {
this.folder_id = folder.id;
}
/* The factory we'll use to register with Angular */
@ -24,36 +22,29 @@
/* Instance methods
* Public method, assigned to prototype
*/
AclUsers.prototype.getUsers = function() {
return AclUsers.$$resource.fetch(this.addressbook_id, "getUsersForObject");
AclUsers.prototype.userRights = function(uid) {
var param = {"uid": uid};
return AclUsers.$$resource.fetch(this.folder_id, "userRights", param);
};
AclUsers.prototype.searchUsers = function(inputText) {
var param = "search=" + inputText;
return AclUsers.$$resource.fetch(null, "usersSearch", param);
};
AclUsers.prototype.openRightsForUserId = function(user) {
var param = "uid=" + user;
return AclUsers.$$resource.fetch(this.addressbook_id, "userRights", param);
AclUsers.prototype.addUser = function(uid) {
var param = {"uid": uid};
AclUsers.$$resource.fetch(this.folder_id, "addUserInAcls", param);
};
AclUsers.prototype.addUser = function(user) {
var param = "uid=" + user;
AclUsers.$$resource.fetch(this.addressbook_id, "addUserInAcls", param);
};
AclUsers.prototype.subscribeUsers = function(users) {
var param = "uids=" + users;
AclUsers.$$resource.fetch(this.addressbook_id, "subscribeUsers", param);
};
AclUsers.prototype.removeUser = function(user) {
var userId = "uid=" + user.uid;
AclUsers.$$resource.fetch(this.addressbook_id, "removeUserFromAcls", userId);
AclUsers.prototype.removeUser = function(uid) {
var param = {"uid": uid};
AclUsers.$$resource.fetch(this.folder_id, "removeUserFromAcls", param);
};
AclUsers.prototype.saveUsersRights = function(dirtyObjects) {
AclUsers.$$resource.saveAclUsers(this.addressbook_id, "saveUserRights", dirtyObjects);
var param = {"action": "saveUserRights"};
AclUsers.$$resource.save(this.folder_id, dirtyObjects, param);
};
AclUsers.prototype.subscribeUsers = function(uids) {
var param = {"uids": uids};
AclUsers.$$resource.fetch(this.folder_id, "subscribeUsers", param);
};
})();

View File

@ -84,10 +84,10 @@
return deferred.promise;
};
Resource.prototype.save = function(uid, newValue, options) {
Resource.prototype.save = function(id, newValue, options) {
var deferred = this._q.defer(),
action = (options && options.action)? options.action : 'save',
path = this._path + '/' + uid + '/' + action;
path = this._path + '/' + id + '/' + action;
this._http
.post(path, newValue)
@ -108,4 +108,29 @@
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 {Object} params - Object parameters injected through the $http protocol
*/
Resource.prototype.fetch = function(folder_id, action, params) {
var deferred = this._q.defer();
var folder_id_path = folder_id ? ("/" + folder_id) : "";
var action_path = action ? ("/" + action) : "";
var path = this._path + folder_id_path + action_path;
this._http({
method: 'GET',
url: path,
params: params
})
.success(deferred.resolve)
.error(deferred.reject);
return deferred.promise;
};
})();

View File

@ -19,10 +19,10 @@
* Public method, assigned to prototype
*/
User.prototype.$filter = function(search) {
// return a collections of users for a filter
// return a collections of users for a filter
var param = {search: search};
return User.$$resource.fetch(null, "usersSearch", param).then(function(results) {
return User.$$resource.fetch(null, "usersSearch", param).then(function(results) {
return results;
})
};
})();
})();

View File

@ -178,10 +178,91 @@
$scope.share = function() {
var modal = $modal.open({
templateUrl: 'addressbookSharing.html',
controller: function($scope, $modalInstance) {
controller: function($scope, $http, $modalInstance, sgAclUsers, sgUser) {
/* Variables for the scope */
$scope.AclUsers = new sgAclUsers($rootScope.addressbook);
$scope.User = new sgUser($rootScope.addressbook);
var dirtyObjects = {};
$scope.User.$acls().then(function(users) {
$scope.users = [];
angular.forEach(users, function(user){
user.canSubscribeUser = (user.isSubscribed) ? false : true;
$scope.users.push(user);
})
});
/* Functions */
$scope.closeModal = function() {
$modalInstance.close();
};
$scope.saveModal = function() {
if(!_.isEmpty(dirtyObjects)) {
$scope.AclUsers.saveUsersRights(dirtyObjects);
}
$modalInstance.close();
};
$scope.removeUser = function() {
if (!_.isEmpty($scope.userSelected)) {
if(dirtyObjects[$scope.userSelected.uid])
delete dirtyObjects[$scope.userSelected.uid];
$scope.AclUsers.removeUser($scope.userSelected.uid);
// Remove from the users list
$scope.users = _.reject($scope.users, function(o) {
return o.uid == $scope.userSelected.uid;
});
$scope.userSelected = {};
}
};
$scope.addUser = function(user) {
if (user.uid) {
// Looks through the list and returns the first value that matches all of the key-value pairs listed
if(!_.findWhere($scope.users, {uid: user.uid})) {
$scope.AclUsers.addUser(user.uid);
$scope.User.$acls().then(function(users) {
$scope.users = [];
angular.forEach(users, function(user){
user.canSubscribeUser = (user.isSubscribed) ? false : true;
$scope.users.push(user);
})
});
}
else
Dialog.alert(l('Warning'), l('You have already subscribed to that folder!'));
}
else
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
};
$scope.selectUser = function(user) {
// Check if it is a different user
if ($scope.userSelected != user){
$scope.userSelected = {};
$scope.selected = user;
$scope.userSelected = user;
if (dirtyObjects[$scope.userSelected.uid]) {
$scope.userSelected.aclOptions = dirtyObjects[$scope.userSelected.uid].aclOptions;
}
else {
$scope.AclUsers.userRights($scope.userSelected.uid).then(function(userRights) {
$scope.userSelected.aclOptions = userRights;
});
}
}
};
$scope.markUserAsDirty = function(user) {
if(!$scope.userSelected) {
$scope.selectUser(user);
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
}
else
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
};
$scope.displayUserRights = function() {
return ($scope.userSelected && ($scope.userSelected.uid != "anonymous")) ? true : false;
};
$scope.userIsReadOnly = function() {
return (!$scope.userSelected || $scope.userSelected.userClass == "public-user");
};
}
});
};

View File

@ -128,13 +128,10 @@
if (attrs.source) {
scope.$watch('search.value', function (newValue, oldValue) {
if (newValue.length > attrs.minLength) {
scope.getData({str: newValue}).then(function (results) {
scope.getData({search: newValue}).then(function (results) {
scope.model = results;
});
}
else {
scope.model = [];
}
});
}
scope.clearSearch = function() {
@ -144,7 +141,7 @@
},
template: '<div class="item-input-wrapper">' +
'<i class="icon ion-android-search"></i>' +
'<input type="search" placeholder="{{placeholder}}" ng-model="search.value">' +
'<input type="search" placeholder="{{placeholder}}" ng-model="search.value" id="searchInput">' +
'<i ng-if="search.value.length > 0" ng-click="clearSearch()" class="icon ion-close"></i>' +
'</div>'
};
@ -162,7 +159,7 @@
// };
}])
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'sgAclUsers', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, sgAclUsers) {
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'sgAclUsers', 'sgUser', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, sgAclUsers, sgUser) {
// Initialize with data from template
$scope.addressbooks = AddressBook.$findAll(contactFolders);
$scope.newAddressbook = function() {
@ -210,12 +207,13 @@
$scope.$aclEditorModal = modal;
$scope.addressbook = addressbook;
$scope.AclUsers = new sgAclUsers(addressbook);
$scope.User = new sgUser(addressbook);
var aclUsers = {};
$scope.AclUsers.getUsers().then(function(users) {
$scope.User.$acls().then(function(users) {
$scope.refreshUsers(users);
});
$scope.showDelete = false;
$scope.onGoingSearch = true;
$scope.onGoingSearch = false;
// Variables in javascript
var dirtyObjects = {};
@ -223,7 +221,7 @@
// Local functions
$scope.refreshUsers = function(users) {
$scope.users = [];
$scope.onGoingSearch = true;
$scope.onGoingSearch = false;
angular.forEach(users, function(user){
user.inAclList = true;
user.canSubscribeUser = (user.isSubscribed) ? false : true;
@ -237,16 +235,22 @@
$scope.$aclEditorModal.remove();
};
$scope.saveModal = function() {
if(Object.keys(dirtyObjects).length > 0) {
if(!_.isEmpty(dirtyObjects)) {
if(dirtyObjects["anonymous"])
{
Dialog.confirm(l("Warning"), l("Any user with an account on this system will be able to access your mailbox \"%{0}\". Are you certain you trust them all?")).then(function(res){
if(res){Dialog.alert("okay!")};
Dialog.confirm(l("Warning"), l("Any user with an account on this system will be able to access your folder. Are you certain you trust them all?")).then(function(res){
if(res){
$scope.AclUsers.saveUsersRights(dirtyObjects);
$scope.$aclEditorModal.remove();
};
})
}
else if (dirtyObjects["<default>"]) {
Dialog.confirm(l("Warning"), l("Potentially anyone on the Internet will be able to access your calendar \"%{0}\", even if they do not have an account on this system. Is this information suitable for the public Internet?")).then(function(res){
if(res){Dialog.alert("okay!")};
Dialog.confirm(l("Warning"), l("Potentially anyone on the Internet will be able to access your folder, even if they do not have an account on this system. Is this information suitable for the public Internet?")).then(function(res){
if(res){
$scope.AclUsers.saveUsersRights(dirtyObjects);
$scope.$aclEditorModal.remove();
};
})
}
else {
@ -257,13 +261,17 @@
usersToSubscribe.push(dirtyObject.uid);
}
})
$scope.AclUsers.subscribeUsers(usersToSubscribe);
if(!_.isEmpty(usersToSubscribe))
$scope.AclUsers.subscribeUsers(usersToSubscribe);
$scope.$aclEditorModal.remove();
}
}
$scope.$aclEditorModal.remove();
else
$scope.$aclEditorModal.remove();
};
$scope.cancelSearch = function() {
$scope.AclUsers.getUsers().then(function(users) {
$scope.User.$acls().then(function(users) {
$scope.refreshUsers(users);
});
};
@ -275,24 +283,27 @@
if(dirtyObjects[user.uid])
delete dirtyObjects[user.uid];
delete aclUsers[user.uid];
$scope.AclUsers.removeUser(user);
$scope.AclUsers.getUsers().then(function(users) {
$scope.refreshUsers(users);
$scope.AclUsers.removeUser(user.uid);
// Remove from the users list
$scope.users = _.reject($scope.users, function(o) {
return o.uid == user.uid;
});
$scope.userSelected = {};
}
};
$scope.addUser = function (user) {
if (user) {
$scope.AclUsers.addUser(user.uid);
$scope.AclUsers.getUsers().then(function(users) {
$scope.refreshUsers(users);
});
}
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'));
if (user.uid) {
if(!aclUsers[user.uid]) {
$scope.AclUsers.addUser(user.uid);
user.inAclList = true;
user.canSubscribeUser = (user.isSubscribed) ? false : true;
aclUsers[user.uid] = user;
}
else
Dialog.alert(l('Warning'), l('You have already subscribed to that folder!'));
}
else
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
};
$scope.editUser = function(user) {
if ($scope.userSelected != user){
@ -305,17 +316,17 @@
}
else {
// Otherwise, if it's the first time the user consult the user rights; fetch from server
$scope.AclUsers.openRightsForUserId($scope.userSelected.uid).then(function(userRights) {
$scope.AclUsers.userRights($scope.userSelected.uid).then(function(userRights) {
$scope.userSelected.aclOptions = userRights;
});
}
}
};
$scope.getContacts = function(value){
$scope.searchUsers = function(search){
$scope.users = [];
$scope.onGoingSearch = false;
return $scope.AclUsers.searchUsers(value).then(function(usersFound) {
angular.forEach(usersFound, function(userFound){
$scope.onGoingSearch = true;
return $scope.User.$filter(search).then(function(results) {
angular.forEach(results, function(userFound){
userFound.inAclList = (aclUsers[userFound.uid]) ? true : false;
$scope.users.push(userFound);
})
@ -343,7 +354,7 @@
};
$scope.displayUserRights = function() {
// Does the rights applies on the user/group
return ($scope.userSelected && $scope.userSelected.uid != "anonymous") ? true : false;
return ($scope.userSelected && ($scope.userSelected.uid != "anonymous")) ? true : false;
};
$scope.displaySubscribeUser = function() {
// Is the user/group available for subscription