diff options
author | Joas Schilling <coding@schilljs.com> | 2017-01-18 14:35:30 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-01-18 14:35:30 +0100 |
commit | 89801f76ea91f6eca4a0bc7371849356f58c4677 (patch) | |
tree | bd96767a90ecb18fcda4cf71e33dabd326cb0c7c /settings/js/users | |
parent | 5d1f7e5a7be4eba2c1cb0e601c7bc0ac43e1855f (diff) | |
download | nextcloud-server-89801f76ea91f6eca4a0bc7371849356f58c4677.tar.gz nextcloud-server-89801f76ea91f6eca4a0bc7371849356f58c4677.zip |
Use the provisioning api in the user management to handle group memberships
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'settings/js/users')
-rw-r--r-- | settings/js/users/groups.js | 4 | ||||
-rw-r--r-- | settings/js/users/users.js | 75 |
2 files changed, 51 insertions, 28 deletions
diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index cfe01c17530..aac1609bce7 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -225,7 +225,9 @@ GroupList = { toggleAddGroup: function (event) { if (GroupList.isAddGroupButtonVisible()) { - event.stopPropagation(); + if (event) { + event.stopPropagation(); + } $('#newgroup-form').show(); $('#newgroup-init').hide(); $('#newgroupname').focus(); diff --git a/settings/js/users/users.js b/settings/js/users/users.js index a2ccc059f15..3cf7b5e810a 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -420,42 +420,63 @@ var UserList = { var $element = $(element); - var checkHandler = null; + var addUserToGroup = null, + removeUserFromGroup = null; if(user) { // Only if in a user row, and not the #newusergroups select - checkHandler = function (group) { - if (user === OC.currentUser && group === 'admin') { + var handleUserGroupMembership = function (group, add) { + if (user === OC.getCurrentUser().uid && group === 'admin') { return false; } if (!OC.isUserAdmin() && checked.length === 1 && checked[0] === group) { return false; } - $.post( - OC.filePath('settings', 'ajax', 'togglegroups.php'), - { - username: user, - group: group + + if (add && OC.isUserAdmin() && UserList.availableGroups.indexOf(group) === -1) { + GroupList.createGroup(group); + if (UserList.availableGroups.indexOf(group) === -1) { + UserList.availableGroups.push(group); + } + } + + $.ajax({ + url: OC.linkToOCS('cloud/users/' + user , 2) + 'groups', + data: { + groupid: group }, - function (response) { - if (response.status === 'success') { - GroupList.update(); - var groupName = response.data.groupname; - if (UserList.availableGroups.indexOf(groupName) === -1 && - response.data.action === 'add' - ) { - UserList.availableGroups.push(groupName); - } + type: add ? 'POST' : 'DELETE', + beforeSend: function (request) { + request.setRequestHeader('Accept', 'application/json'); + }, + success: function() { + GroupList.update(); + if (add && UserList.availableGroups.indexOf(group) === -1) { + UserList.availableGroups.push(group); + } - if (response.data.action === 'add') { - GroupList.incGroupCount(groupName); - } else { - GroupList.decGroupCount(groupName); - } + if (add) { + GroupList.incGroupCount(group); + } else { + GroupList.decGroupCount(group); } - if (response.data.message) { - OC.Notification.show(response.data.message); + }, + error: function() { + if (add) { + OC.Notification.show(t('settings', 'Unable to add user to group {group}', { + group: group + })); + } else { + OC.Notification.show(t('settings', 'Unable to remove user from group {group}', { + group: group + })); } } - ); + }); + }; + addUserToGroup = function (group) { + return handleUserGroupMembership(group, true); + }; + removeUserFromGroup = function (group) { + return handleUserGroupMembership(group, false); }; } var addGroup = function (select, group) { @@ -473,8 +494,8 @@ var UserList = { createText: label, selectedFirst: true, checked: checked, - oncheck: checkHandler, - onuncheck: checkHandler, + oncheck: addUserToGroup, + onuncheck: removeUserFromGroup, minWidth: 100 }); }, |