aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Accounts
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2021-03-24 12:32:06 +0100
committerVincent Petry <vincent@nextcloud.com>2021-03-26 13:07:08 +0100
commit266a6fb5f8a0ec0e89e2a96f7e2ebb4a5bbf44f5 (patch)
treef7bce1b5cf24025d9fe03deee0fe0b98386da8d7 /lib/private/Accounts
parent5d14fd4396b54134ce04809a10f46b084107003b (diff)
downloadnextcloud-server-266a6fb5f8a0ec0e89e2a96f7e2ebb4a5bbf44f5.tar.gz
nextcloud-server-266a6fb5f8a0ec0e89e2a96f7e2ebb4a5bbf44f5.zip
OCS allow reading and writing account property scopes
Extends the provisioning API to allow a user to get and set their own account property scopes. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'lib/private/Accounts')
-rw-r--r--lib/private/Accounts/AccountManager.php33
-rw-r--r--lib/private/Accounts/AccountProperty.php2
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index ff3b04d8395..74ba53737ca 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -144,6 +144,37 @@ class AccountManager implements IAccountManager {
}
}
+ $allowedScopes = [
+ self::SCOPE_PRIVATE,
+ self::SCOPE_LOCAL,
+ self::SCOPE_FEDERATED,
+ self::SCOPE_PUBLISHED,
+ self::VISIBILITY_PRIVATE,
+ self::VISIBILITY_CONTACTS_ONLY,
+ self::VISIBILITY_PUBLIC,
+ ];
+
+ // validate and convert scope values
+ foreach ($data as $propertyName => $propertyData) {
+ if (isset($propertyData['scope'])) {
+ if ($throwOnData && !in_array($propertyData['scope'], $allowedScopes, true)) {
+ throw new \InvalidArgumentException('scope');
+ }
+
+ if (
+ $propertyData['scope'] === self::SCOPE_PRIVATE
+ && ($propertyName === self::PROPERTY_DISPLAYNAME || $propertyName === self::PROPERTY_EMAIL)
+ ) {
+ // v2-private is not available for these fields
+ throw new \InvalidArgumentException('scope');
+ }
+
+ // migrate scope values to the new format
+ // invalid scopes are mapped to a default value
+ $data[$propertyName]['scope'] = AccountProperty::mapScopeToV2($propertyData['scope']);
+ }
+ }
+
if (empty($userData)) {
$this->insertNewUser($user, $data);
} elseif ($userData !== $data) {
@@ -405,7 +436,7 @@ class AccountManager implements IAccountManager {
}
$query->setParameter('name', $propertyName)
- ->setParameter('value', $property['value']);
+ ->setParameter('value', $property['value'] ?? '');
$query->execute();
}
}
diff --git a/lib/private/Accounts/AccountProperty.php b/lib/private/Accounts/AccountProperty.php
index 4c75ad85414..850f39df9e3 100644
--- a/lib/private/Accounts/AccountProperty.php
+++ b/lib/private/Accounts/AccountProperty.php
@@ -128,7 +128,7 @@ class AccountProperty implements IAccountProperty {
return $this->scope;
}
- private function mapScopeToV2($scope) {
+ public static function mapScopeToV2($scope) {
if (strpos($scope, 'v2-') === 0) {
return $scope;
}