diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-08 01:10:32 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-08 01:20:17 +0200 |
commit | 1e271e9f76a5378d719e699c828a530c95ece336 (patch) | |
tree | ee18684bb102a3899d5b8ac8be1f1a95abf12b5e /apps/provisioning_api/lib | |
parent | 0ac4563ae4cf03b5c28daec82fc4631d1579c13a (diff) | |
download | nextcloud-server-1e271e9f76a5378d719e699c828a530c95ece336.tar.gz nextcloud-server-1e271e9f76a5378d719e699c828a530c95ece336.zip |
provAPI to use only public API of IAccountManager
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/provisioning_api/lib')
3 files changed, 44 insertions, 37 deletions
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index c26c4f9e2d0..6f682b41f28 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -31,12 +31,13 @@ declare(strict_types=1); namespace OCA\Provisioning_API\Controller; -use OC\Accounts\AccountManager; use OC\Group\Manager; use OC\User\Backend; use OC\User\NoUserException; use OC_Helper; use OCP\Accounts\IAccountManager; +use OCP\Accounts\PropertyDoesNotExistException; +use OCP\AppFramework\Http; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; @@ -61,7 +62,7 @@ abstract class AUserData extends OCSController { protected $groupManager; /** @var IUserSession */ protected $userSession; - /** @var AccountManager */ + /** @var IAccountManager */ protected $accountManager; /** @var IFactory */ protected $l10nFactory; @@ -72,7 +73,7 @@ abstract class AUserData extends OCSController { IConfig $config, IGroupManager $groupManager, IUserSession $userSession, - AccountManager $accountManager, + IAccountManager $accountManager, IFactory $l10nFactory) { parent::__construct($appName, $request); @@ -140,30 +141,35 @@ abstract class AUserData extends OCSController { $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); - if ($includeScopes) { - $data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(); - } - - $data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); - if ($includeScopes) { - $data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(); - } - $data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); - if ($includeScopes) { - $data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(); - } + try { + if ($includeScopes) { + $data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(); + } - foreach ([ - IAccountManager::PROPERTY_PHONE, - IAccountManager::PROPERTY_ADDRESS, - IAccountManager::PROPERTY_WEBSITE, - IAccountManager::PROPERTY_TWITTER, - ] as $propertyName) { - $property = $userAccount->getProperty($propertyName); - $data[$propertyName] = $property->getValue(); + $data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress(); + if ($includeScopes) { + $data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(); + } + $data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName(); if ($includeScopes) { - $data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope(); + $data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(); + } + + foreach ([ + IAccountManager::PROPERTY_PHONE, + IAccountManager::PROPERTY_ADDRESS, + IAccountManager::PROPERTY_WEBSITE, + IAccountManager::PROPERTY_TWITTER, + ] as $propertyName) { + $property = $userAccount->getProperty($propertyName); + $data[$propertyName] = $property->getValue(); + if ($includeScopes) { + $data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope(); + } } + } catch (PropertyDoesNotExistException $e) { + // hard coded properties should exist + throw new OCSException($e->getMessage(), Http::STATUS_INTERNAL_SERVER_ERROR, $e); } $data['groups'] = $gids; diff --git a/apps/provisioning_api/lib/Controller/GroupsController.php b/apps/provisioning_api/lib/Controller/GroupsController.php index b031c405046..583af8454f6 100644 --- a/apps/provisioning_api/lib/Controller/GroupsController.php +++ b/apps/provisioning_api/lib/Controller/GroupsController.php @@ -34,7 +34,7 @@ declare(strict_types=1); namespace OCA\Provisioning_API\Controller; -use OC\Accounts\AccountManager; +use OCP\Accounts\IAccountManager; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; @@ -61,7 +61,7 @@ class GroupsController extends AUserData { IConfig $config, IGroupManager $groupManager, IUserSession $userSession, - AccountManager $accountManager, + IAccountManager $accountManager, IFactory $l10nFactory, LoggerInterface $logger) { parent::__construct($appName, diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 115b955354b..84fdaf8bc89 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -46,7 +46,6 @@ use libphonenumber\NumberParseException; use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumberFormat; use libphonenumber\PhoneNumberUtil; -use OC\Accounts\AccountManager; use OC\Authentication\Token\RemoteWipe; use OC\HintException; use OC\KnownUser\KnownUserService; @@ -102,7 +101,7 @@ class UsersController extends AUserData { IAppManager $appManager, IGroupManager $groupManager, IUserSession $userSession, - AccountManager $accountManager, + IAccountManager $accountManager, IURLGenerator $urlGenerator, LoggerInterface $logger, IFactory $l10nFactory, @@ -734,13 +733,14 @@ class UsersController extends AUserData { case IAccountManager::PROPERTY_ADDRESS: case IAccountManager::PROPERTY_WEBSITE: case IAccountManager::PROPERTY_TWITTER: - $userAccount = $this->accountManager->getUser($targetUser); - if ($userAccount[$key]['value'] !== $value) { - $userAccount[$key]['value'] = $value; + $userAccount = $this->accountManager->getAccount($targetUser); + $userProperty = $userAccount->getProperty($key); + if ($userProperty->getValue() !== $value) { try { - $this->accountManager->updateUser($targetUser, $userAccount, true); + $userProperty->setValue($value); + $this->accountManager->updateAccount($userAccount); - if ($key === IAccountManager::PROPERTY_PHONE) { + if ($userProperty->getName() === IAccountManager::PROPERTY_PHONE) { $this->knownUserService->deleteByContactUserId($targetUser->getUID()); } } catch (\InvalidArgumentException $e) { @@ -756,11 +756,12 @@ class UsersController extends AUserData { case IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX: case IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX: $propertyName = substr($key, 0, strlen($key) - strlen(self::SCOPE_SUFFIX)); - $userAccount = $this->accountManager->getUser($targetUser); - if ($userAccount[$propertyName]['scope'] !== $value) { - $userAccount[$propertyName]['scope'] = $value; + $userAccount = $this->accountManager->getAccount($targetUser); + $userProperty = $userAccount->getProperty($propertyName); + if ($userProperty->getScope() !== $value) { + $userProperty->setScope($value); try { - $this->accountManager->updateUser($targetUser, $userAccount, true); + $this->accountManager->updateAccount($userAccount); } catch (\InvalidArgumentException $e) { throw new OCSException('Invalid ' . $e->getMessage(), 102); } |