Show hint in OCS API for user creation

* adds a 107 error code together with the hint of the exception
* logs the exception as warning
* fixes #7946

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2018-02-22 14:16:49 +01:00
parent a5b73fe761
commit 168f188596
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
1 changed files with 10 additions and 2 deletions

View File

@ -31,6 +31,7 @@
namespace OCA\Provisioning_API\Controller; namespace OCA\Provisioning_API\Controller;
use OC\Accounts\AccountManager; use OC\Accounts\AccountManager;
use OC\HintException;
use OC\Settings\Mailer\NewUserMailHelper; use OC\Settings\Mailer\NewUserMailHelper;
use OC_Helper; use OC_Helper;
use OCP\App\IAppManager; use OCP\App\IAppManager;
@ -187,15 +188,22 @@ class UsersController extends OCSController {
try { try {
$newUser = $this->userManager->createUser($userid, $password); $newUser = $this->userManager->createUser($userid, $password);
$this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
if (is_array($groups)) { if (is_array($groups)) {
foreach ($groups as $group) { foreach ($groups as $group) {
$this->groupManager->get($group)->addUser($newUser); $this->groupManager->get($group)->addUser($newUser);
$this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
} }
} }
return new DataResponse(); return new DataResponse();
} catch (HintException $e ) {
$this->logger->logException($e, [
'message' => 'Failed addUser attempt with hint exception.',
'level' => \OCP\Util::WARN,
'app' => 'ocs_api',
]);
throw new OCSException($e->getHint(), 107);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']);
throw new OCSException('Bad request', 101); throw new OCSException('Bad request', 101);