mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-09 05:25:26 +00:00
Multiple improvements regarding ACLs
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
abstract: true,
|
||||
views: {
|
||||
card: {
|
||||
template: '<ui-view/>',
|
||||
template: '<ui-view/>'
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
@@ -98,7 +98,7 @@
|
||||
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook, Dialog, stateAddressbooks, stateAddressbook) {
|
||||
var currentAddressbook;
|
||||
|
||||
// Resolve objects
|
||||
// Resolved objects
|
||||
$scope.addressbooks = stateAddressbooks;
|
||||
$rootScope.addressbook = stateAddressbook;
|
||||
|
||||
@@ -177,158 +177,62 @@
|
||||
|
||||
};
|
||||
$scope.exportCards = function() {
|
||||
window.location.href = ApplicationBaseURL + "/" + $rootScope.addressbook.id + "/exportFolder";
|
||||
window.location.href = ApplicationBaseURL + '/' + $rootScope.addressbook.id + '/exportFolder';
|
||||
};
|
||||
$scope.share = function() {
|
||||
var modal = $modal.open({
|
||||
templateUrl: 'addressbookSharing.html',
|
||||
controller: function($scope, $modalInstance, User) {
|
||||
/* Variables for the scope */
|
||||
var dirtyObjects = {};
|
||||
stateAddressbook.$acl.$users().then(function(users) {
|
||||
$scope.users = [];
|
||||
angular.forEach(users, function(user){
|
||||
user.canSubscribeUser = user.isSubscribed;
|
||||
$scope.users.push(user);
|
||||
})
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occurs while trying to fetch users from the server.'));
|
||||
});
|
||||
$scope.User = new User();
|
||||
/* Functions */
|
||||
resolve: {
|
||||
modalUsers: function() {
|
||||
return stateAddressbook.$acl.$users();
|
||||
}
|
||||
},
|
||||
controller: ['$scope', '$modalInstance', 'sgUser', 'modalUsers', function($scope, $modalInstance, User, modalUsers) {
|
||||
$scope.users = modalUsers; // ACL users
|
||||
$scope.userFilter = User.$filter; // Filter for typeahead
|
||||
$scope.closeModal = function() {
|
||||
stateAddressbook.$acl.$resetUsersRights(); // cancel changes
|
||||
$modalInstance.close();
|
||||
};
|
||||
$scope.saveModal = function() {
|
||||
if(!_.isEmpty(dirtyObjects)) {
|
||||
if(dirtyObjects["anonymous"]) {
|
||||
if($scope.validateChanges(dirtyObjects["anonymous"])) {
|
||||
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){
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
}
|
||||
})
|
||||
}
|
||||
else{
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
}
|
||||
}
|
||||
else if (dirtyObjects["<default>"]) {
|
||||
if($scope.validateChanges(dirtyObjects["<default>"])) {
|
||||
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){
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
};
|
||||
})
|
||||
}
|
||||
else{
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
var usersToSubscribe = [];
|
||||
angular.forEach(dirtyObjects, function(dirtyObject){
|
||||
if(dirtyObject.canSubscribeUser && dirtyObject.isSubscribed){
|
||||
usersToSubscribe.push(dirtyObject.uid);
|
||||
}
|
||||
})
|
||||
if(!_.isEmpty(usersToSubscribe))
|
||||
stateAddressbook.$acl.$subscribeUsers(usersToSubscribe).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
|
||||
$modalInstance.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
stateAddressbook.$acl.$saveUsersRights().then(function() {
|
||||
$modalInstance.close();
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
||||
});
|
||||
};
|
||||
$scope.validateChanges = function(object) {
|
||||
if (object.aclOptions.canViewObjects || object.aclOptions.canCreateObjects || object.aclOptions.canEditObjects || object.aclOptions.canEraseObjects)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
};
|
||||
$scope.removeUser = function() {
|
||||
if (!_.isEmpty($scope.userSelected)) {
|
||||
if(dirtyObjects[$scope.userSelected.uid])
|
||||
delete dirtyObjects[$scope.userSelected.uid];
|
||||
stateAddressbook.$acl.$removeUser($scope.userSelected.uid).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
$scope.confirmChange = function(user) {
|
||||
var confirmation = user.$confirmRights();
|
||||
if (confirmation) {
|
||||
Dialog.confirm(l('Warning'), confirmation).then(function(res) {
|
||||
if (!res)
|
||||
user.$resetRights(true);
|
||||
});
|
||||
// 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})) {
|
||||
stateAddressbook.$acl.$addUser(user.uid).then(function() {
|
||||
var displayName = user.cn + " <" + user.c_email + ">";
|
||||
var userClass = user.isGroup ? "group-user" : "normal-user";
|
||||
var newUser = {canSubscribeUser: 0, displayName: displayName, isSubscribed: 0, uid: user.uid, userClass: userClass};
|
||||
$scope.users.push(newUser);
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$scope.removeUser = function(user) {
|
||||
stateAddressbook.$acl.$removeUser(user.uid).then(function() {
|
||||
if (user.uid == $scope.selectedUser.uid) {
|
||||
delete $scope.selectedUser;
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('This user is already in your permissions list.'));
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
};
|
||||
$scope.addUser = function(data) {
|
||||
$scope.userToAdd = '';
|
||||
stateAddressbook.$acl.$addUser(data).catch(function(error) {
|
||||
Dialog.alert(l('Warning'), error);
|
||||
});
|
||||
};
|
||||
$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 {
|
||||
stateAddressbook.$acl.$userRights($scope.userSelected.uid).then(function(userRights) {
|
||||
$scope.userSelected.aclOptions = userRights;
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
}
|
||||
if ($scope.selectedUser != user) {
|
||||
$scope.selectedUser = user;
|
||||
$scope.selectedUser.$rights();
|
||||
}
|
||||
};
|
||||
$scope.markUserAsDirty = function(user) {
|
||||
if(!$scope.userSelected)
|
||||
$scope.selectUser(user);
|
||||
|
||||
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");
|
||||
};
|
||||
}
|
||||
}]
|
||||
});
|
||||
};
|
||||
$scope.doSearch = function(keyEvent) {
|
||||
|
||||
Reference in New Issue
Block a user