mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #33625 from nextcloud/fix/33572/add-user
Fix creation of new user and display the correct error message
This commit is contained in:
commit
253c0641b1
5 changed files with 24 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue