aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Profile
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2022-03-11 02:11:28 +0000
committerChristopher Ng <chrng8@gmail.com>2022-03-18 02:55:12 +0000
commit1fc0b4320c8921ad59bf4d41a88bf9936e1f653d (patch)
tree8d630f864f4a2760f72307e68553cc2ee0c516d4 /lib/private/Profile
parentd364edcf6a18fa237dc53f6b95614851ed5fdc9a (diff)
downloadnextcloud-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/Profile')
-rw-r--r--lib/private/Profile/ProfileManager.php24
1 files changed, 24 insertions, 0 deletions
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 {