From b0fefa0179e1bea24e488c89d5e637ca37bc0db0 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 15 Dec 2021 14:16:17 +0100 Subject: [PATCH 1/2] Add default app setting on a user basis --- lib/private/legacy/util.php | 12 +++++++++++- tests/lib/UtilTest.php | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 04382f244f4e..d5a653a12a33 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -1175,7 +1175,17 @@ public static function getDefaultPageUrl() { $location = $urlGenerator->getAbsoluteURL($defaultPage); } else { $appId = 'files'; - $defaultApps = \explode(',', \OC::$server->getConfig()->getSystemValue('defaultapp', 'files')); + $uid = \OC_User::getUser(); + $config = \OC::$server->getConfig(); + $defaultApps = \explode(',', $config->getSystemValue('defaultapp', 'files')); + + if ($uid) { + $userDefaultApp = $config->getUserValue($uid, 'core', 'defaultapp', null); + if ($userDefaultApp) { + \array_unshift($defaultApps, $userDefaultApp); + } + } + // find the first app that is enabled for the current user foreach ($defaultApps as $defaultApp) { $defaultApp = OC_App::cleanAppId(\strip_tags($defaultApp)); diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index f40b98e81c33..f5dfa7bd37bb 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -362,6 +362,25 @@ public function testGetDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontContr $this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/files/', OC_Util::getDefaultPageUrl()); } + public function testGetDefaultPageUrlWithUserConfig() { + $uid = $this->getUniqueID(); + $userDefaultApp = 'user_default_app'; + \OC_User::setUserId($uid); + \OC::$server->getConfig()->setUserValue($uid, 'core', 'defaultapp', $userDefaultApp); + + $appManager = $this->createMock(IAppManager::class); + $appManager->expects($this->any()) + ->method('isEnabledForUser') + ->willReturn(true); + Dummy_OC_Util::$appManager = $appManager; + + \putenv('front_controller_active=true'); + $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a'; + $this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/' . $userDefaultApp . '/', Dummy_OC_Util::getDefaultPageUrl()); + \OC::$server->getConfig()->deleteUserValue($uid, 'core', 'defaultapp'); + \OC_User::setUserId(null); + } + /** * Test needUpgrade() when the core version is increased */ From f0d73ce9bc3e6edd93623d9431bb338c530513c6 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 15 Dec 2021 14:24:50 +0100 Subject: [PATCH 2/2] Add changelog item for #39600 --- changelog/unreleased/39600 | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/unreleased/39600 diff --git a/changelog/unreleased/39600 b/changelog/unreleased/39600 new file mode 100644 index 000000000000..e2cac6716869 --- /dev/null +++ b/changelog/unreleased/39600 @@ -0,0 +1,3 @@ +Enhancement: Add default app setting on a user basis + +https://github.com/owncloud/core/pull/39600