diff options
author | Christopher Ng <chrng8@gmail.com> | 2022-03-11 02:11:28 +0000 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2022-03-18 02:55:12 +0000 |
commit | 1fc0b4320c8921ad59bf4d41a88bf9936e1f653d (patch) | |
tree | 8d630f864f4a2760f72307e68553cc2ee0c516d4 /lib/private | |
parent | d364edcf6a18fa237dc53f6b95614851ed5fdc9a (diff) | |
download | nextcloud-server-1fc0b4320c8921ad59bf4d41a88bf9936e1f653d.tar.gz nextcloud-server-1fc0b4320c8921ad59bf4d41a88bf9936e1f653d.zip |
Add global profile toggle config
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Contacts/ContactsMenu/ContactsStore.php | 20 | ||||
-rw-r--r-- | lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php | 18 | ||||
-rw-r--r-- | lib/private/Profile/ProfileManager.php | 24 |
3 files changed, 41 insertions, 21 deletions
diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index a27c2ae455a..5b7a942a244 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -32,7 +32,7 @@ namespace OC\Contacts\ContactsMenu; use OC\KnownUser\KnownUserService; -use OCP\Accounts\IAccountManager; +use OC\Profile\ProfileManager; use OCP\Contacts\ContactsMenu\IContactsStore; use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\IManager; @@ -44,10 +44,6 @@ use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; class ContactsStore implements IContactsStore { - use \OC\Profile\TProfileHelper; - - /** @var IAccountManager */ - private $accountManager; /** @var IManager */ private $contactsManager; @@ -55,6 +51,9 @@ class ContactsStore implements IContactsStore { /** @var IConfig */ private $config; + /** @var ProfileManager */ + private $profileManager; + /** @var IUserManager */ private $userManager; @@ -71,18 +70,18 @@ class ContactsStore implements IContactsStore { private $l10nFactory; public function __construct( - IAccountManager $accountManager, IManager $contactsManager, IConfig $config, + ProfileManager $profileManager, IUserManager $userManager, IURLGenerator $urlGenerator, IGroupManager $groupManager, KnownUserService $knownUserService, IL10NFactory $l10nFactory ) { - $this->accountManager = $accountManager; $this->contactsManager = $contactsManager; $this->config = $config; + $this->profileManager = $profileManager; $this->userManager = $userManager; $this->urlGenerator = $urlGenerator; $this->groupManager = $groupManager; @@ -335,10 +334,9 @@ class ContactsStore implements IContactsStore { // Provide profile parameters for core/src/OC/contactsmenu/contact.handlebars template if (isset($contact['UID']) && isset($contact['FN'])) { $targetUserId = $contact['UID']; - $user = $this->userManager->get($targetUserId); - if (!empty($user)) { - $account = $this->accountManager->getAccount($user); - if ($this->isProfileEnabled($account)) { + $targetUser = $this->userManager->get($targetUserId); + if (!empty($targetUser)) { + if ($this->profileManager->isProfileEnabled($targetUser)) { $entry->setProfileTitle($this->l10nFactory->get('lib')->t('View profile')); $entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId])); } diff --git a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php index 15d24fc7773..e654319c3fa 100644 --- a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php +++ b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php @@ -24,7 +24,7 @@ namespace OC\Contacts\ContactsMenu\Providers; -use OCP\Accounts\IAccountManager; +use OC\Profile\ProfileManager; use OCP\Contacts\ContactsMenu\IActionFactory; use OCP\Contacts\ContactsMenu\IEntry; use OCP\Contacts\ContactsMenu\IProvider; @@ -33,14 +33,13 @@ use OCP\IUserManager; use OCP\L10N\IFactory as IL10NFactory; class ProfileProvider implements IProvider { - use \OC\Profile\TProfileHelper; - - /** @var IAccountManager */ - private $accountManager; /** @var IActionFactory */ private $actionFactory; + /** @var ProfileManager */ + private $profileManager; + /** @var IL10NFactory */ private $l10nFactory; @@ -51,21 +50,21 @@ class ProfileProvider implements IProvider { private $userManager; /** - * @param IAccountManager $accountManager * @param IActionFactory $actionFactory + * @param ProfileManager $profileManager * @param IL10NFactory $l10nFactory * @param IURLGenerator $urlGenerator * @param IUserManager $userManager */ public function __construct( - IAccountManager $accountManager, IActionFactory $actionFactory, + ProfileManager $profileManager, IL10NFactory $l10nFactory, IURLGenerator $urlGenerator, IUserManager $userManager ) { - $this->accountManager = $accountManager; $this->actionFactory = $actionFactory; + $this->profileManager = $profileManager; $this->l10nFactory = $l10nFactory; $this->urlGenerator = $urlGenerator; $this->userManager = $userManager; @@ -78,8 +77,7 @@ class ProfileProvider implements IProvider { $targetUserId = $entry->getProperty('UID'); $targetUser = $this->userManager->get($targetUserId); if (!empty($targetUser)) { - $account = $this->accountManager->getAccount($targetUser); - if ($this->isProfileEnabled($account)) { + if ($this->profileManager->isProfileEnabled($targetUser)) { $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg')); $profileActionText = $this->l10nFactory->get('lib')->t('View profile'); $profileUrl = $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]); diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php index c4317b294f3..edb51458c66 100644 --- a/lib/private/Profile/ProfileManager.php +++ b/lib/private/Profile/ProfileManager.php @@ -40,6 +40,7 @@ use OCP\Accounts\IAccountManager; use OCP\Accounts\PropertyDoesNotExistException; use OCP\App\IAppManager; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\IConfig; use OCP\IUser; use OCP\L10N\IFactory; use OCP\Profile\ILinkAction; @@ -54,6 +55,9 @@ class ProfileManager { /** @var IAppManager */ private $appManager; + /** @var IConfig */ + private $config; + /** @var ProfileConfigMapper */ private $configMapper; @@ -106,6 +110,7 @@ class ProfileManager { public function __construct( IAccountManager $accountManager, IAppManager $appManager, + IConfig $config, ProfileConfigMapper $configMapper, ContainerInterface $container, KnownUserService $knownUserService, @@ -115,6 +120,7 @@ class ProfileManager { ) { $this->accountManager = $accountManager; $this->appManager = $appManager; + $this->config = $config; $this->configMapper = $configMapper; $this->container = $container; $this->knownUserService = $knownUserService; @@ -124,6 +130,24 @@ class ProfileManager { } /** + * If no user is passed as an argument return whether profile is enabled globally in `config.php` + */ + public function isProfileEnabled(?IUser $user = null): ?bool { + $profileEnabledGlobally = $this->config->getSystemValueBool('profile.enabled', true); + + if (empty($user) || !$profileEnabledGlobally) { + return $profileEnabledGlobally; + } + + $account = $this->accountManager->getAccount($user); + return filter_var( + $account->getProperty(IAccountManager::PROPERTY_PROFILE_ENABLED)->getValue(), + FILTER_VALIDATE_BOOLEAN, + FILTER_NULL_ON_FAILURE, + ); + } + + /** * Register an action for the user */ private function registerAction(ILinkAction $action, IUser $targetUser, ?IUser $visitingUser): void { |