summaryrefslogtreecommitdiffstats
path: root/settings/Controller/UsersController.php
diff options
context:
space:
mode:
authorThomas Pulzer <t.pulzer@kniel.de>2016-07-08 13:22:34 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-04-29 00:54:30 -0300
commit637c75bca176d3ef7a06e8b4fa2d60fece1c89a7 (patch)
tree287dee19aea7777a243856eae5f81d12f3286216 /settings/Controller/UsersController.php
parent130780056109d8b65e7b9abe40c89e26a75c5e35 (diff)
downloadnextcloud-server-637c75bca176d3ef7a06e8b4fa2d60fece1c89a7.tar.gz
nextcloud-server-637c75bca176d3ef7a06e8b4fa2d60fece1c89a7.zip
Implemented visual feedback if a user is disabled in admin user menu.
Implemented visuals for enabling/disabling user from admin user list. Added the controller functions for enabling/disabling a user. Added the route for changing user status (enabled/disabled) and added an additional route handler in the user controller. Finished the visuals to reflect current user status and changed user status respectively. Changed the single icon for enabling/disabling a user into a menu where deletion and state toggling of a user is selectable. Added displaying of disabled user count. Improved style of user action menu. Added proper counting of disabled users. Removed visual indicator for disabled users. Moved pseudo-group detection for disabled users from frontend to the controller. Changed units for newly introduced css values from em to px. Removed unnecessary png and optimized svg with scour. Changed the userlist template to display the user action menu with correct width. Style fixes for better readability and coding style conformity. Changed the icons for enabling, disabling and deleting a user in the action menu.
Diffstat (limited to 'settings/Controller/UsersController.php')
-rw-r--r--settings/Controller/UsersController.php154
1 files changed, 144 insertions, 10 deletions
diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php
index 7f6602a510c..5949d9c9746 100644
--- a/settings/Controller/UsersController.php
+++ b/settings/Controller/UsersController.php
@@ -225,6 +225,7 @@ class UsersController extends Controller {
'email' => $displayName,
'isRestoreDisabled' => !$restorePossible,
'isAvatarAvailable' => $avatarAvailable,
+ 'isEnabled' => $user->isEnabled(),
];
}
@@ -253,11 +254,6 @@ class UsersController extends Controller {
* TODO: Tidy up and write unit tests - code is mainly static method calls
*/
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
- // FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
- if($gid === '_everyone') {
- $gid = '';
- }
-
// Remove backends
if(!empty($backend)) {
$activeBackends = $this->userManager->getBackends();
@@ -272,15 +268,18 @@ class UsersController extends Controller {
$users = [];
if ($this->isAdmin) {
-
- if($gid !== '') {
+ if($gid !== '' && $gid !== 'disabledUsers') {
$batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
} else {
$batch = $this->userManager->search($pattern, $limit, $offset);
}
foreach ($batch as $user) {
- $users[] = $this->formatUserForIndex($user);
+ if( ($gid !== 'disabledUsers' && $user->isEnabled()) ||
+ ($gid === 'disabledUsers' && !$user->isEnabled())
+ ) {
+ $users[] = $this->formatUserForIndex($user);
+ }
}
} else {
@@ -293,7 +292,7 @@ class UsersController extends Controller {
$subAdminOfGroups = $gids;
// Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
- if($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
+ if($gid !== '' && $gid !== 'disabledUsers' && !in_array($gid, $subAdminOfGroups)) {
$gid = '';
}
@@ -318,7 +317,11 @@ class UsersController extends Controller {
$this->groupManager->getUserGroupIds($user),
$subAdminOfGroups
));
- $users[] = $this->formatUserForIndex($user, $userGroups);
+ if( ($gid !== 'disabledUsers' && $user->isEnabled()) ||
+ ($gid === 'disabledUsers' && !$user->isEnabled())
+ ) {
+ $users[] = $this->formatUserForIndex($user, $userGroups);
+ }
}
}
@@ -514,6 +517,137 @@ class UsersController extends Controller {
/**
* @NoAdminRequired
+ *
+ * @param string $id
+ * @return DataResponse
+ */
+ public function disable($id) {
+ $userId = $this->userSession->getUser()->getUID();
+ $user = $this->userManager->get($id);
+
+ if($userId === $id) {
+ return new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => (string)$this->l10n->t('Unable to disable user.')
+ )
+ ),
+ Http::STATUS_FORBIDDEN
+ );
+ }
+
+ if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
+ return new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => (string)$this->l10n->t('Authentication error')
+ )
+ ),
+ Http::STATUS_FORBIDDEN
+ );
+ }
+
+ if($user) {
+ $user->setEnabled(false);
+ return new DataResponse(
+ array(
+ 'status' => 'success',
+ 'data' => array(
+ 'username' => $id,
+ 'enabled' => 0
+ )
+ )
+ );
+ } else {
+ return new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => (string)$this->l10n->t('Unable to disable user.')
+ )
+ )
+ );
+ }
+ }
+
+ /**
+ * @NoAdminRequired
+ *
+ * @param string $id
+ * @return DataResponse
+ */
+ public function enable($id) {
+ $userId = $this->userSession->getUser()->getUID();
+ $user = $this->userManager->get($id);
+
+ if($userId === $id) {
+ return new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => (string)$this->l10n->t('Unable to enable user.')
+ )
+ ),
+ Http::STATUS_FORBIDDEN
+ );
+ }
+
+ if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
+ return new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => (string)$this->l10n->t('Authentication error')
+ )
+ ),
+ Http::STATUS_FORBIDDEN
+ );
+ }
+
+ if($user) {
+ $user->setEnabled(true);
+ return new DataResponse(
+ array(
+ 'status' => 'success',
+ 'data' => array(
+ 'username' => $id,
+ 'enabled' => 1
+ )
+ )
+ );
+ } else {
+ return new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => (string)$this->l10n->t('Unable to enable user.')
+ )
+ )
+ );
+ }
+ }
+
+ /**
+ * @NoAdminRequired
+ *
+ * @param string $id
+ * @param int $enabled
+ * @return DataResponse
+ */
+ public function setEnabled($id, $enabled) {
+ if((bool)$enabled) {
+ return $this->enable($id);
+ } else {
+ return $this->disable($id);
+ }
+ }
+
+ /**
+ * Set the mail address of a user
+ *
+ * @NoAdminRequired
* @NoSubadminRequired
* @PasswordConfirmationRequired
*