diff options
author | Robin Appelman <robin@icewind.nl> | 2023-09-22 11:10:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 11:10:42 +0200 |
commit | b6927d0fa3faeb54f313d23b84ca94fd139453cf (patch) | |
tree | fef9ff89c2e2371eded1bc8af3b4c7fc5453719c | |
parent | 26ad0a1b9c4b617e50cfd27b9696b052522953be (diff) | |
parent | d1673ca3b8c1a922816740f2f11c7610ec31e05e (diff) | |
download | nextcloud-server-b6927d0fa3faeb54f313d23b84ca94fd139453cf.tar.gz nextcloud-server-b6927d0fa3faeb54f313d23b84ca94fd139453cf.zip |
Merge pull request #39075 from fsamapoor/refactor_lib_private_profile
Refactors lib/private/Profile.
-rw-r--r-- | lib/private/Profile/Actions/EmailAction.php | 21 | ||||
-rw-r--r-- | lib/private/Profile/Actions/FediverseAction.php | 14 | ||||
-rw-r--r-- | lib/private/Profile/Actions/PhoneAction.php | 21 | ||||
-rw-r--r-- | lib/private/Profile/Actions/TwitterAction.php | 21 | ||||
-rw-r--r-- | lib/private/Profile/Actions/WebsiteAction.php | 21 | ||||
-rw-r--r-- | lib/private/Profile/ProfileManager.php | 116 |
6 files changed, 58 insertions, 156 deletions
diff --git a/lib/private/Profile/Actions/EmailAction.php b/lib/private/Profile/Actions/EmailAction.php index 8ab4939b515..a676f6e228e 100644 --- a/lib/private/Profile/Actions/EmailAction.php +++ b/lib/private/Profile/Actions/EmailAction.php @@ -33,26 +33,13 @@ use OCP\L10N\IFactory; use OCP\Profile\ILinkAction; class EmailAction implements ILinkAction { - /** @var string */ - private $value; - - /** @var IAccountManager */ - private $accountManager; - - /** @var IFactory */ - private $l10nFactory; - - /** @var IUrlGenerator */ - private $urlGenerator; + private string $value = ''; public function __construct( - IAccountManager $accountManager, - IFactory $l10nFactory, - IURLGenerator $urlGenerator + private IAccountManager $accountManager, + private IFactory $l10nFactory, + private IURLGenerator $urlGenerator, ) { - $this->accountManager = $accountManager; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; } public function preload(IUser $targetUser): void { diff --git a/lib/private/Profile/Actions/FediverseAction.php b/lib/private/Profile/Actions/FediverseAction.php index ed3fcd80b52..30682ba6b2a 100644 --- a/lib/private/Profile/Actions/FediverseAction.php +++ b/lib/private/Profile/Actions/FediverseAction.php @@ -34,19 +34,13 @@ use OCP\L10N\IFactory; use OCP\Profile\ILinkAction; class FediverseAction implements ILinkAction { - private ?string $value = null; - private IAccountManager $accountManager; - private IFactory $l10nFactory; - private IURLGenerator $urlGenerator; + private string $value = ''; public function __construct( - IAccountManager $accountManager, - IFactory $l10nFactory, - IURLGenerator $urlGenerator + private IAccountManager $accountManager, + private IFactory $l10nFactory, + private IURLGenerator $urlGenerator, ) { - $this->accountManager = $accountManager; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; } public function preload(IUser $targetUser): void { diff --git a/lib/private/Profile/Actions/PhoneAction.php b/lib/private/Profile/Actions/PhoneAction.php index 6081a04ad7e..6a4b2dd49d4 100644 --- a/lib/private/Profile/Actions/PhoneAction.php +++ b/lib/private/Profile/Actions/PhoneAction.php @@ -33,26 +33,13 @@ use OCP\L10N\IFactory; use OCP\Profile\ILinkAction; class PhoneAction implements ILinkAction { - /** @var string */ - private $value; - - /** @var IAccountManager */ - private $accountManager; - - /** @var IFactory */ - private $l10nFactory; - - /** @var IUrlGenerator */ - private $urlGenerator; + private string $value = ''; public function __construct( - IAccountManager $accountManager, - IFactory $l10nFactory, - IURLGenerator $urlGenerator + private IAccountManager $accountManager, + private IFactory $l10nFactory, + private IURLGenerator $urlGenerator, ) { - $this->accountManager = $accountManager; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; } public function preload(IUser $targetUser): void { diff --git a/lib/private/Profile/Actions/TwitterAction.php b/lib/private/Profile/Actions/TwitterAction.php index 041da42e539..178bd04c786 100644 --- a/lib/private/Profile/Actions/TwitterAction.php +++ b/lib/private/Profile/Actions/TwitterAction.php @@ -34,26 +34,13 @@ use OCP\L10N\IFactory; use OCP\Profile\ILinkAction; class TwitterAction implements ILinkAction { - /** @var string */ - private $value; - - /** @var IAccountManager */ - private $accountManager; - - /** @var IFactory */ - private $l10nFactory; - - /** @var IUrlGenerator */ - private $urlGenerator; + private string $value = ''; public function __construct( - IAccountManager $accountManager, - IFactory $l10nFactory, - IURLGenerator $urlGenerator + private IAccountManager $accountManager, + private IFactory $l10nFactory, + private IURLGenerator $urlGenerator, ) { - $this->accountManager = $accountManager; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; } public function preload(IUser $targetUser): void { diff --git a/lib/private/Profile/Actions/WebsiteAction.php b/lib/private/Profile/Actions/WebsiteAction.php index 6b052be57bd..22e2692c4c5 100644 --- a/lib/private/Profile/Actions/WebsiteAction.php +++ b/lib/private/Profile/Actions/WebsiteAction.php @@ -33,26 +33,13 @@ use OCP\L10N\IFactory; use OCP\Profile\ILinkAction; class WebsiteAction implements ILinkAction { - /** @var string */ - private $value; - - /** @var IAccountManager */ - private $accountManager; - - /** @var IFactory */ - private $l10nFactory; - - /** @var IUrlGenerator */ - private $urlGenerator; + private string $value = ''; public function __construct( - IAccountManager $accountManager, - IFactory $l10nFactory, - IURLGenerator $urlGenerator + private IAccountManager $accountManager, + private IFactory $l10nFactory, + private IURLGenerator $urlGenerator, ) { - $this->accountManager = $accountManager; - $this->l10nFactory = $l10nFactory; - $this->urlGenerator = $urlGenerator; } public function preload(IUser $targetUser): void { diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php index f20ae74768e..8fa65271205 100644 --- a/lib/private/Profile/ProfileManager.php +++ b/lib/private/Profile/ProfileManager.php @@ -50,38 +50,11 @@ use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; class ProfileManager { - /** @var IAccountManager */ - private $accountManager; - - /** @var IAppManager */ - private $appManager; - - /** @var IConfig */ - private $config; - - /** @var ProfileConfigMapper */ - private $configMapper; - - /** @var ContainerInterface */ - private $container; - - /** @var KnownUserService */ - private $knownUserService; - - /** @var IFactory */ - private $l10nFactory; - - /** @var LoggerInterface */ - private $logger; - - /** @var Coordinator */ - private $coordinator; - /** @var ILinkAction[] */ - private $actions = []; + private array $actions = []; /** @var null|ILinkAction[] */ - private $sortedActions = null; + private ?array $sortedActions = null; /** @var CappedMemoryCache<ProfileConfig> */ private CappedMemoryCache $configCache; @@ -112,25 +85,16 @@ class ProfileManager { ]; public function __construct( - IAccountManager $accountManager, - IAppManager $appManager, - IConfig $config, - ProfileConfigMapper $configMapper, - ContainerInterface $container, - KnownUserService $knownUserService, - IFactory $l10nFactory, - LoggerInterface $logger, - Coordinator $coordinator + private IAccountManager $accountManager, + private IAppManager $appManager, + private IConfig $config, + private ProfileConfigMapper $configMapper, + private ContainerInterface $container, + private KnownUserService $knownUserService, + private IFactory $l10nFactory, + private LoggerInterface $logger, + private Coordinator $coordinator, ) { - $this->accountManager = $accountManager; - $this->appManager = $appManager; - $this->config = $config; - $this->configMapper = $configMapper; - $this->container = $container; - $this->knownUserService = $knownUserService; - $this->l10nFactory = $l10nFactory; - $this->logger = $logger; - $this->coordinator = $coordinator; $this->configCache = new CappedMemoryCache(); } @@ -239,40 +203,36 @@ class ProfileManager { $visibility = $this->getProfileConfig($targetUser, $visitingUser)[$paramId]['visibility']; // Handle profile visibility and account property scope - switch ($visibility) { - case ProfileConfig::VISIBILITY_HIDE: - return false; - case ProfileConfig::VISIBILITY_SHOW_USERS_ONLY: - if (!empty($scope)) { - switch ($scope) { - case IAccountManager::SCOPE_PRIVATE: - return $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID()); - case IAccountManager::SCOPE_LOCAL: - case IAccountManager::SCOPE_FEDERATED: - case IAccountManager::SCOPE_PUBLISHED: - return $visitingUser !== null; - default: - return false; - } - } + + if ($visibility === ProfileConfig::VISIBILITY_SHOW_USERS_ONLY) { + if (empty($scope)) { return $visitingUser !== null; - case ProfileConfig::VISIBILITY_SHOW: - if (!empty($scope)) { - switch ($scope) { - case IAccountManager::SCOPE_PRIVATE: - return $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID()); - case IAccountManager::SCOPE_LOCAL: - case IAccountManager::SCOPE_FEDERATED: - case IAccountManager::SCOPE_PUBLISHED: - return true; - default: - return false; - } - } + } + + return match ($scope) { + IAccountManager::SCOPE_PRIVATE => $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID()), + IAccountManager::SCOPE_LOCAL, + IAccountManager::SCOPE_FEDERATED, + IAccountManager::SCOPE_PUBLISHED => $visitingUser !== null, + default => false, + }; + } + + if ($visibility === ProfileConfig::VISIBILITY_SHOW) { + if (empty($scope)) { return true; - default: - return false; + }; + + return match ($scope) { + IAccountManager::SCOPE_PRIVATE => $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID()), + IAccountManager::SCOPE_LOCAL, + IAccountManager::SCOPE_FEDERATED, + IAccountManager::SCOPE_PUBLISHED => true, + default => false, + }; } + + return false; } /** |