]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix creation of new user and display the correct error message 33625/head
authorChristopher Ng <chrng8@gmail.com>
Fri, 19 Aug 2022 20:02:57 +0000 (20:02 +0000)
committerChristopher Ng <chrng8@gmail.com>
Mon, 22 Aug 2022 19:13:11 +0000 (19:13 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/provisioning_api/lib/Controller/UsersController.php
lib/private/User/Database.php
lib/private/User/User.php
lib/public/IUser.php
lib/public/User/Backend/ISetDisplayNameBackend.php

index 839ac404c947b419815c00049988886b437a246a..37bbdc9e1c4d0391b9f57d2b65540caf53e0ee7a 100644 (file)
@@ -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:
index 0b38f04bfe3c02eb396cd4c86edf5f4aa951011e..f106c2e8b6dae1b9123bece518de1f880c27a386 100644 (file)
@@ -212,11 +212,13 @@ class Database extends ABackend implements
         * @param string $displayName The new display name
         * @return bool
         *
+        * @throws \InvalidArgumentException
+        *
         * Change the display name of a user
         */
        public function setDisplayName(string $uid, string $displayName): bool {
                if (mb_strlen($displayName) > 64) {
-                       return false;
+                       throw new \InvalidArgumentException('Invalid displayname');
                }
 
                $this->fixDI();
index 7f7d6273e306b7c0e2baa1ee90232e3b95323f61..c24a5fe1c6b590ce56b4404382eae1191a5ecaae 100644 (file)
@@ -154,6 +154,9 @@ class User implements IUser {
         *
         * @param string $displayName
         * @return bool
+        *
+        * @since 25.0.0 Throw InvalidArgumentException
+        * @throws \InvalidArgumentException
         */
        public function setDisplayName($displayName) {
                $displayName = trim($displayName);
index daf993df6cd2dc690d08c2f69607b3456f25b2a8..bb7bdf3304aa8257862a7791b1fbcb17cecba958 100644 (file)
@@ -58,6 +58,9 @@ interface IUser {
         * @param string $displayName
         * @return bool
         * @since 8.0.0
+        *
+        * @since 25.0.0 Throw InvalidArgumentException
+        * @throws \InvalidArgumentException
         */
        public function setDisplayName($displayName);
 
index 922d356bfd738a32a28139ff1ea36abeae30df4c..db62223ad52fafe50ab68736c94159d582ecf533 100644 (file)
@@ -36,6 +36,9 @@ interface ISetDisplayNameBackend {
         * @param string $uid The username
         * @param string $displayName The new display name
         * @return bool
+        *
+        * @since 25.0.0 Throw InvalidArgumentException
+        * @throws \InvalidArgumentException
         */
        public function setDisplayName(string $uid, string $displayName): bool;
 }