aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Profile/ProfileManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Profile/ProfileManager.php')
-rw-r--r--lib/private/Profile/ProfileManager.php74
1 files changed, 49 insertions, 25 deletions
diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php
index c8fb780bbe8..c38412f6bd0 100644
--- a/lib/private/Profile/ProfileManager.php
+++ b/lib/private/Profile/ProfileManager.php
@@ -3,33 +3,19 @@
declare(strict_types=1);
/**
- * @copyright 2021 Christopher Ng <chrng8@gmail.com>
- *
- * @author Christopher Ng <chrng8@gmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Profile;
use OC\AppFramework\Bootstrap\Coordinator;
+use OC\Config\PresetManager;
use OC\Core\Db\ProfileConfig;
use OC\Core\Db\ProfileConfigMapper;
+use OC\Core\ResponseDefinitions;
use OC\KnownUser\KnownUserService;
+use OC\Profile\Actions\BlueskyAction;
use OC\Profile\Actions\EmailAction;
use OC\Profile\Actions\FediverseAction;
use OC\Profile\Actions\PhoneAction;
@@ -40,6 +26,7 @@ use OCP\Accounts\PropertyDoesNotExistException;
use OCP\App\IAppManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Cache\CappedMemoryCache;
+use OCP\Config\Lexicon\Preset;
use OCP\IConfig;
use OCP\IUser;
use OCP\L10N\IFactory;
@@ -50,6 +37,9 @@ use Psr\Log\LoggerInterface;
use function array_flip;
use function usort;
+/**
+ * @psalm-import-type CoreProfileFields from ResponseDefinitions
+ */
class ProfileManager implements IProfileManager {
/** @var ILinkAction[] */
private array $actions = [];
@@ -69,6 +59,7 @@ class ProfileManager implements IProfileManager {
PhoneAction::class,
WebsiteAction::class,
TwitterAction::class,
+ BlueskyAction::class,
FediverseAction::class,
];
@@ -83,6 +74,7 @@ class ProfileManager implements IProfileManager {
IAccountManager::PROPERTY_HEADLINE,
IAccountManager::PROPERTY_ORGANISATION,
IAccountManager::PROPERTY_ROLE,
+ IAccountManager::PROPERTY_PRONOUNS,
];
public function __construct(
@@ -95,6 +87,7 @@ class ProfileManager implements IProfileManager {
private IFactory $l10nFactory,
private LoggerInterface $logger,
private Coordinator $coordinator,
+ private readonly PresetManager $presetManager,
) {
$this->configCache = new CappedMemoryCache();
}
@@ -110,7 +103,7 @@ class ProfileManager implements IProfileManager {
}
$account = $this->accountManager->getAccount($user);
- return (bool) filter_var(
+ return (bool)filter_var(
$account->getProperty(IAccountManager::PROPERTY_PROFILE_ENABLED)->getValue(),
FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE,
@@ -239,7 +232,7 @@ class ProfileManager implements IProfileManager {
/**
* Return the profile parameters of the target user that are visible to the visiting user
* in an associative array
- * @return array{userId: string, address?: string|null, biography?: string|null, displayname?: string|null, headline?: string|null, isUserAvatarVisible?: bool, organisation?: string|null, role?: string|null, actions: list<array{id: string, icon: string, title: string, target: ?string}>}
+ * @psalm-return CoreProfileFields
*/
public function getProfileFields(IUser $targetUser, ?IUser $visitingUser): array {
$account = $this->accountManager->getAccount($targetUser);
@@ -258,8 +251,9 @@ class ProfileManager implements IProfileManager {
case IAccountManager::PROPERTY_HEADLINE:
case IAccountManager::PROPERTY_ORGANISATION:
case IAccountManager::PROPERTY_ROLE:
- $profileParameters[$property] =
- $this->isProfileFieldVisible($property, $targetUser, $visitingUser)
+ case IAccountManager::PROPERTY_PRONOUNS:
+ $profileParameters[$property]
+ = $this->isProfileFieldVisible($property, $targetUser, $visitingUser)
// Explicitly set to null when value is empty string
? ($account->getProperty($property)->getValue() ?: null)
: null;
@@ -324,6 +318,7 @@ class ProfileManager implements IProfileManager {
// Construct the default config for account properties
$propertiesConfig = [];
foreach (self::DEFAULT_PROPERTY_VISIBILITY as $property => $visibility) {
+ $this->applyDefaultProfilePreset($property, $visibility);
$propertiesConfig[$property] = ['visibility' => $visibility];
}
@@ -331,6 +326,31 @@ class ProfileManager implements IProfileManager {
}
/**
+ * modify property visibility, based on current Preset
+ *
+ * @psalm-suppress UnhandledMatchCondition if conditions are not met, we do not change $visibility
+ */
+ private function applyDefaultProfilePreset(string $property, string &$visibility): void {
+ try {
+ $overwrite = match ($this->presetManager->getLexiconPreset()) {
+ Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match ($property) {
+ IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
+ },
+ Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match ($property) {
+ IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
+ },
+ Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match ($property) {
+ IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
+ },
+ };
+ } catch (\UnhandledMatchError) {
+ return;
+ }
+
+ $visibility = $overwrite;
+ }
+
+ /**
* Return the profile config of the target user,
* if a config does not already exist a default config is created and returned
*/
@@ -361,7 +381,7 @@ class ProfileManager implements IProfileManager {
}
/**
- * Return the profile config of the target user with additional medatata,
+ * Return the profile config of the target user with additional metadata,
* if a config does not already exist a default config is created and returned
*/
public function getProfileConfigWithMetadata(IUser $targetUser, ?IUser $visitingUser): array {
@@ -410,12 +430,16 @@ class ProfileManager implements IProfileManager {
],
IAccountManager::PROPERTY_ORGANISATION => [
'appId' => self::CORE_APP_ID,
- 'displayId' => $this->l10nFactory->get('lib')->t('Organisation'),
+ 'displayId' => $this->l10nFactory->get('lib')->t('Organization'),
],
IAccountManager::PROPERTY_ROLE => [
'appId' => self::CORE_APP_ID,
'displayId' => $this->l10nFactory->get('lib')->t('Role'),
],
+ IAccountManager::PROPERTY_PRONOUNS => [
+ 'appId' => self::CORE_APP_ID,
+ 'displayId' => $this->l10nFactory->get('lib')->t('Pronouns'),
+ ],
];
$paramMetadata = array_merge($actionsMetadata, $propertiesMetadata);