From 1fc0b4320c8921ad59bf4d41a88bf9936e1f653d Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Fri, 11 Mar 2022 02:11:28 +0000 Subject: Add global profile toggle config Signed-off-by: Christopher Ng --- lib/private/Profile/ProfileManager.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/private/Profile') 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; @@ -123,6 +129,24 @@ class ProfileManager { $this->coordinator = $coordinator; } + /** + * 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 */ -- cgit v1.2.3