* @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);
[
'status' => 'error',
'data' => [
- 'message' => (string) $this->l10n->t('Error while enabling user.')
- ]
- ],
- Http::STATUS_FORBIDDEN
+ 'message' => $errorMsgGeneral
+ ]
+ ], Http::STATUS_FORBIDDEN
);
}
);
}
- $user->setEnabled(true);
+ $user->setEnabled($enabled);
return new DataResponse(
[
'status' => 'success',
'data' => [
'username' => $id,
- 'enabled' => 1
+ 'enabled' => $enabled
]
]
);
[
'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);
- }
}
/**
->expects($this->once())
->method('getBackendClassName')
->willReturn('bar');
+ $user
+ ->method('isEnabled')
+ ->willReturn(true);
$this->userManager
->expects($this->once())
'email' => 'abc@example.org',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
+ 'isEnabled' => true,
],
Http::STATUS_CREATED
);
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(true)->disable('abc');
+ $response = $this->getController(true)->setEnabled('abc', false);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(false)->disable('abc');
+ $response = $this->getController(false)->setEnabled('abc', false);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(true)->disable('abc');
+ $response = $this->getController(true)->setEnabled('abc', false);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(false)->disable('abc');
+ $response = $this->getController(false)->setEnabled('abc', false);
$this->assertEquals($expectedResponse, $response);
}
],
]
);
- $response = $this->getController(true)->disable('abc');
+ $response = $this->getController(true)->setEnabled('abc', false);
$this->assertEquals($expectedResponse, $response);
}
],
]
);
- $response = $this->getController(false)->disable('abc');
+ $response = $this->getController(false)->setEnabled('abc', false);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(true)->enable('abc');
+ $response = $this->getController(true)->setEnabled('abc', true);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(false)->enable('abc');
+ $response = $this->getController(false)->setEnabled('abc', true);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(true)->enable('abc');
+ $response = $this->getController(true)->setEnabled('abc', true);
$this->assertEquals($expectedResponse, $response);
}
],
Http::STATUS_FORBIDDEN
);
- $response = $this->getController(false)->enable('abc');
+ $response = $this->getController(false)->setEnabled('abc', true);
$this->assertEquals($expectedResponse, $response);
}
],
]
);
- $response = $this->getController(true)->enable('abc');
+ $response = $this->getController(true)->setEnabled('abc', true);
$this->assertEquals($expectedResponse, $response);
}
],
]
);
- $response = $this->getController(false)->enable('abc');
+ $response = $this->getController(false)->setEnabled('abc', true);
$this->assertEquals($expectedResponse, $response);
}
}