From d59585974e2f3f51598da31f6e1dd0684affa77b Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Fri, 19 Aug 2022 20:02:57 +0000 Subject: Fix creation of new user and display the correct error message Signed-off-by: Christopher Ng --- apps/provisioning_api/lib/Controller/UsersController.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'apps/provisioning_api') diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 839ac404c94..37bbdc9e1c4 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -426,7 +426,14 @@ class UsersController extends AUserData { } if ($displayName !== '') { - $this->editUser($userid, self::USER_FIELD_DISPLAYNAME, $displayName); + try { + $this->editUser($userid, self::USER_FIELD_DISPLAYNAME, $displayName); + } catch (OCSException $e) { + if ($newUser instanceof IUser) { + $newUser->delete(); + } + throw $e; + } } if ($quota !== '') { @@ -837,8 +844,10 @@ class UsersController extends AUserData { switch ($key) { case self::USER_FIELD_DISPLAYNAME: case IAccountManager::PROPERTY_DISPLAYNAME: - if (!$targetUser->setDisplayName($value)) { - throw new OCSException('Invalid displayname', 102); + try { + $targetUser->setDisplayName($value); + } catch (InvalidArgumentException $e) { + throw new OCSException($e->getMessage(), 101); } break; case self::USER_FIELD_QUOTA: -- cgit v1.2.3