diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2021-05-12 14:17:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 14:17:50 +0200 |
commit | 7e1c842d96cde01ebb6854b3e28fb998006575b2 (patch) | |
tree | 0da4f083e0db25a76c59c9d93d869fcf08809c23 /lib | |
parent | 6c741724fbdfc71762407298738c330e5ceb9b88 (diff) | |
parent | 8413ed947577a37c79ceebfc827acd37494d1a37 (diff) | |
download | nextcloud-server-7e1c842d96cde01ebb6854b3e28fb998006575b2.tar.gz nextcloud-server-7e1c842d96cde01ebb6854b3e28fb998006575b2.zip |
Merge pull request #26923 from nextcloud/techdebt/noid/provapi-no-private-accountmanager
provisioning API to use only public API of IAccountManager
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Accounts/AccountProperty.php | 31 | ||||
-rw-r--r-- | lib/public/Accounts/IAccountProperty.php | 3 |
2 files changed, 23 insertions, 11 deletions
diff --git a/lib/private/Accounts/AccountProperty.php b/lib/private/Accounts/AccountProperty.php index 850f39df9e3..0152137f6de 100644 --- a/lib/private/Accounts/AccountProperty.php +++ b/lib/private/Accounts/AccountProperty.php @@ -43,7 +43,7 @@ class AccountProperty implements IAccountProperty { public function __construct(string $name, string $value, string $scope, string $verified) { $this->name = $name; $this->value = $value; - $this->scope = $this->mapScopeToV2($scope); + $this->setScope($scope); $this->verified = $verified; } @@ -78,7 +78,16 @@ class AccountProperty implements IAccountProperty { * @return IAccountProperty */ public function setScope(string $scope): IAccountProperty { - $this->scope = $this->mapScopeToV2($scope); + $newScope = $this->mapScopeToV2($scope); + if (!in_array($newScope, [ + IAccountManager::SCOPE_LOCAL, + IAccountManager::SCOPE_FEDERATED, + IAccountManager::SCOPE_PRIVATE, + IAccountManager::SCOPE_PUBLISHED + ])) { + throw new \InvalidArgumentException('Invalid scope'); + } + $this->scope = $newScope; return $this; } @@ -128,21 +137,21 @@ class AccountProperty implements IAccountProperty { return $this->scope; } - public static function mapScopeToV2($scope) { + public static function mapScopeToV2(string $scope): string { if (strpos($scope, 'v2-') === 0) { return $scope; } switch ($scope) { - case IAccountManager::VISIBILITY_PRIVATE: - return IAccountManager::SCOPE_LOCAL; - case IAccountManager::VISIBILITY_CONTACTS_ONLY: - return IAccountManager::SCOPE_FEDERATED; - case IAccountManager::VISIBILITY_PUBLIC: - return IAccountManager::SCOPE_PUBLISHED; + case IAccountManager::VISIBILITY_PRIVATE: + return IAccountManager::SCOPE_LOCAL; + case IAccountManager::VISIBILITY_CONTACTS_ONLY: + return IAccountManager::SCOPE_FEDERATED; + case IAccountManager::VISIBILITY_PUBLIC: + return IAccountManager::SCOPE_PUBLISHED; + default: + return $scope; } - - return IAccountManager::SCOPE_LOCAL; } /** diff --git a/lib/public/Accounts/IAccountProperty.php b/lib/public/Accounts/IAccountProperty.php index 657121a27e8..1366ddd9543 100644 --- a/lib/public/Accounts/IAccountProperty.php +++ b/lib/public/Accounts/IAccountProperty.php @@ -26,6 +26,8 @@ declare(strict_types=1); namespace OCP\Accounts; +use InvalidArgumentException; + /** * Interface IAccountProperty * @@ -50,6 +52,7 @@ interface IAccountProperty extends \JsonSerializable { * * @param string $scope * @return IAccountProperty + * @throws InvalidArgumentException (since 22.0.0) */ public function setScope(string $scope): IAccountProperty; |