From ee1c6eefb4412fc972f06710e97a43100c6ddb9c Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Thu, 28 Oct 2021 00:39:09 +0000 Subject: Add additional check on action registrations - Minor refactor Signed-off-by: Christopher Ng --- lib/private/Profile/ProfileManager.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'lib/private/Profile') diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php index a7fdfcc62f4..18b53ba9a7e 100644 --- a/lib/private/Profile/ProfileManager.php +++ b/lib/private/Profile/ProfileManager.php @@ -92,6 +92,7 @@ class ProfileManager { */ private const PROFILE_PROPERTIES = [ IAccountManager::PROPERTY_ADDRESS, + IAccountManager::PROPERTY_AVATAR, IAccountManager::PROPERTY_BIOGRAPHY, IAccountManager::PROPERTY_DISPLAYNAME, IAccountManager::PROPERTY_HEADLINE, @@ -150,6 +151,11 @@ class ProfileManager { } } + if (in_array($action->getId(), self::PROFILE_PROPERTIES, true)) { + $this->logger->error('Cannot register action with ID: ' . $action->getId() . ', as it is used by a core account property.'); + return; + } + // Add action to associative array of actions $this->actions[$action->getId()] = $action; } @@ -252,16 +258,26 @@ class ProfileManager { // Add account properties foreach (self::PROFILE_PROPERTIES as $property) { - $profileParameters[$property] = - $this->isParameterVisible($targetUser, $visitingUser, $property) - // Explicitly set to null when value is empty string - ? ($account->getProperty($property)->getValue() ?: null) - : null; + switch ($property) { + case IAccountManager::PROPERTY_ADDRESS: + case IAccountManager::PROPERTY_BIOGRAPHY: + case IAccountManager::PROPERTY_DISPLAYNAME: + case IAccountManager::PROPERTY_HEADLINE: + case IAccountManager::PROPERTY_ORGANISATION: + case IAccountManager::PROPERTY_ROLE: + $profileParameters[$property] = + $this->isParameterVisible($targetUser, $visitingUser, $property) + // Explicitly set to null when value is empty string + ? ($account->getProperty($property)->getValue() ?: null) + : null; + break; + case IAccountManager::PROPERTY_AVATAR: + // Add avatar visibility + $profileParameters['isUserAvatarVisible'] = $this->isParameterVisible($targetUser, $visitingUser, $property); + break; + } } - // Add avatar visibility - $profileParameters['isUserAvatarVisible'] = $this->isParameterVisible($targetUser, $visitingUser, IAccountManager::PROPERTY_AVATAR); - // Add actions $profileParameters['actions'] = array_map( function (ILinkAction $action) { -- cgit v1.2.3