aboutsummaryrefslogtreecommitdiffstats
path: root/settings/Controller/UsersController.php
diff options
context:
space:
mode:
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
*