]> source.dussan.org Git - nextcloud-server.git/commitdiff
create a property on editUser when it was not set before
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 22 Jun 2021 16:42:39 +0000 (18:42 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Tue, 29 Jun 2021 22:47:43 +0000 (00:47 +0200)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/provisioning_api/lib/Controller/UsersController.php

index 709f139d8306896da62f278aae6f73abaa0e4363..65789e14b7f3a9458cb5e40c133bfd707ce0c042 100644 (file)
@@ -53,6 +53,7 @@ use OC\User\Backend;
 use OCA\Settings\Mailer\NewUserMailHelper;
 use OCP\Accounts\IAccountManager;
 use OCP\Accounts\IAccountProperty;
+use OCP\Accounts\PropertyDoesNotExistException;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Http;
 use OCP\AppFramework\Http\DataResponse;
@@ -850,19 +851,22 @@ class UsersController extends AUserData {
                        case IAccountManager::PROPERTY_WEBSITE:
                        case IAccountManager::PROPERTY_TWITTER:
                                $userAccount = $this->accountManager->getAccount($targetUser);
-                               $userProperty = $userAccount->getProperty($key);
-                               if ($userProperty->getValue() !== $value) {
-                                       try {
-                                               $userProperty->setValue($value);
-                                               $this->accountManager->updateAccount($userAccount);
-
-                                               if ($userProperty->getName() === IAccountManager::PROPERTY_PHONE) {
-                                                       $this->knownUserService->deleteByContactUserId($targetUser->getUID());
+                               try {
+                                       $userProperty = $userAccount->getProperty($key);
+                                       if ($userProperty->getValue() !== $value) {
+                                               try {
+                                                       $userProperty->setValue($value);
+                                                       if ($userProperty->getName() === IAccountManager::PROPERTY_PHONE) {
+                                                               $this->knownUserService->deleteByContactUserId($targetUser->getUID());
+                                                       }
+                                               } catch (\InvalidArgumentException $e) {
+                                                       throw new OCSException('Invalid ' . $e->getMessage(), 102);
                                                }
-                                       } catch (\InvalidArgumentException $e) {
-                                               throw new OCSException('Invalid ' . $e->getMessage(), 102);
                                        }
+                               } catch (PropertyDoesNotExistException $e) {
+                                       $userAccount->setProperty($key, $value, IAccountManager::SCOPE_PRIVATE, IAccountManager::NOT_VERIFIED);
                                }
+                               $this->accountManager->updateAccount($userAccount);
                                break;
                        case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
                        case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX: