summaryrefslogtreecommitdiffstats
path: root/settings/Controller
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2017-04-26 12:45:23 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-04-29 00:59:09 -0300
commit99e97f135de73de85550e167feb7ccc80f1fc13d (patch)
treea5510f428538fa1951570dcdff251697f009832f /settings/Controller
parent668fe7df51e097a762d9f03e0329a06d0751cd78 (diff)
downloadnextcloud-server-99e97f135de73de85550e167feb7ccc80f1fc13d.tar.gz
nextcloud-server-99e97f135de73de85550e167feb7ccc80f1fc13d.zip
consolidate setEnabled method
and fix a unit test Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'settings/Controller')
-rw-r--r--settings/Controller/UsersController.php88
1 files changed, 12 insertions, 76 deletions
diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php
index 277263b3753..4fed2655940 100644
--- a/settings/Controller/UsersController.php
+++ b/settings/Controller/UsersController.php
@@ -519,66 +519,17 @@ class UsersController extends Controller {
* @NoAdminRequired
*
* @param string $id
+ * @param int $enabled
* @return DataResponse
*/
- public function disable($id) {
- $userId = $this->userSession->getUser()->getUID();
- $user = $this->userManager->get($id);
-
- if ($userId === $id) {
- return new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => (string) $this->l10n->t('Error while disabling user.')
- ]
- ], Http::STATUS_FORBIDDEN
- );
- }
-
- if ($user) {
- if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
- return new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => (string) $this->l10n->t('Authentication error')
- ]
- ],
- Http::STATUS_FORBIDDEN
- );
- }
-
- $user->setEnabled(false);
- return new DataResponse(
- [
- 'status' => 'success',
- 'data' => [
- 'username' => $id,
- 'enabled' => 0
- ]
- ]
- );
+ public function setEnabled($id, $enabled) {
+ $enabled = (bool)$enabled;
+ if($enabled) {
+ $errorMsgGeneral = (string) $this->l10n->t('Error while enabling user.');
} else {
- return new DataResponse(
- [
- 'status' => 'error',
- 'data' => [
- 'message' => (string) $this->l10n->t('Error while disabling user.')
- ]
- ],
- Http::STATUS_FORBIDDEN
- );
+ $errorMsgGeneral = (string) $this->l10n->t('Error while disabling user.');
}
- }
- /**
- * @NoAdminRequired
- *
- * @param string $id
- * @return DataResponse
- */
- public function enable($id) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
@@ -587,10 +538,9 @@ class UsersController extends Controller {
[
'status' => 'error',
'data' => [
- 'message' => (string) $this->l10n->t('Error while enabling user.')
- ]
- ],
- Http::STATUS_FORBIDDEN
+ 'message' => $errorMsgGeneral
+ ]
+ ], Http::STATUS_FORBIDDEN
);
}
@@ -607,13 +557,13 @@ class UsersController extends Controller {
);
}
- $user->setEnabled(true);
+ $user->setEnabled($enabled);
return new DataResponse(
[
'status' => 'success',
'data' => [
'username' => $id,
- 'enabled' => 1
+ 'enabled' => $enabled
]
]
);
@@ -622,27 +572,13 @@ class UsersController extends Controller {
[
'status' => 'error',
'data' => [
- 'message' => (string) $this->l10n->t('Error while enabling user.')
+ 'message' => $errorMsgGeneral
]
],
Http::STATUS_FORBIDDEN
);
}
- }
- /**
- * @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);
- }
}
/**