diff options
Diffstat (limited to 'lib/private/Profile/ProfileManager.php')
-rw-r--r-- | lib/private/Profile/ProfileManager.php | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php index 9d3d94fab21..c38412f6bd0 100644 --- a/lib/private/Profile/ProfileManager.php +++ b/lib/private/Profile/ProfileManager.php @@ -10,9 +10,12 @@ declare(strict_types=1); 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; @@ -23,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; @@ -33,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 = []; @@ -52,6 +59,7 @@ class ProfileManager implements IProfileManager { PhoneAction::class, WebsiteAction::class, TwitterAction::class, + BlueskyAction::class, FediverseAction::class, ]; @@ -79,6 +87,7 @@ class ProfileManager implements IProfileManager { private IFactory $l10nFactory, private LoggerInterface $logger, private Coordinator $coordinator, + private readonly PresetManager $presetManager, ) { $this->configCache = new CappedMemoryCache(); } @@ -223,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, pronouns?: 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); @@ -243,8 +252,8 @@ class ProfileManager implements IProfileManager { case IAccountManager::PROPERTY_ORGANISATION: case IAccountManager::PROPERTY_ROLE: case IAccountManager::PROPERTY_PRONOUNS: - $profileParameters[$property] = - $this->isProfileFieldVisible($property, $targetUser, $visitingUser) + $profileParameters[$property] + = $this->isProfileFieldVisible($property, $targetUser, $visitingUser) // Explicitly set to null when value is empty string ? ($account->getProperty($property)->getValue() ?: null) : null; @@ -309,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]; } @@ -316,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 */ @@ -346,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 { @@ -395,7 +430,7 @@ 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, |