aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Accounts
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2021-05-12 00:33:26 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2021-05-12 01:31:15 +0200
commit8413ed947577a37c79ceebfc827acd37494d1a37 (patch)
treed0de6294ed93ad2c9e2d191bd5d2f2d399e485e1 /lib/private/Accounts
parent1e271e9f76a5378d719e699c828a530c95ece336 (diff)
downloadnextcloud-server-8413ed947577a37c79ceebfc827acd37494d1a37.tar.gz
nextcloud-server-8413ed947577a37c79ceebfc827acd37494d1a37.zip
allow to set valid scopes only in AccountProperty
the auto-fallback to v2-local is removed as well to react on wrong input Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/Accounts')
-rw-r--r--lib/private/Accounts/AccountProperty.php31
1 files changed, 20 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;
}
/**