]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(URLGenerator): Use NavigationManager to generate default page URL
authorprovokateurin <kate@provokateurin.de>
Tue, 27 Aug 2024 11:12:21 +0000 (13:12 +0200)
committerprovokateurin <kate@provokateurin.de>
Mon, 9 Sep 2024 09:04:36 +0000 (11:04 +0200)
Signed-off-by: provokateurin <kate@provokateurin.de>
lib/private/URLGenerator.php

index 1ddc9aaa0e11157a3e9dd34c02a40303ac6b51e4..7a23f36b7e71f50de28c4bb59e14861a64d90e49 100644 (file)
@@ -14,6 +14,7 @@ use OCP\App\AppPathNotFoundException;
 use OCP\App\IAppManager;
 use OCP\ICacheFactory;
 use OCP\IConfig;
+use OCP\INavigationManager;
 use OCP\IRequest;
 use OCP\IURLGenerator;
 use OCP\IUserSession;
@@ -36,6 +37,7 @@ class URLGenerator implements IURLGenerator {
        /** @var null|string */
        private $baseUrl = null;
        private ?IAppManager $appManager = null;
+       private ?INavigationManager $navigationManager = null;
 
        public function __construct(IConfig $config,
                IUserSession $userSession,
@@ -58,6 +60,14 @@ class URLGenerator implements IURLGenerator {
                return $this->appManager;
        }
 
+       private function getNavigationManager(): INavigationManager {
+               if ($this->navigationManager !== null) {
+                       return $this->navigationManager;
+               }
+               $this->navigationManager = \OCP\Server::get(INavigationManager::class);
+               return $this->navigationManager;
+       }
+
        /**
         * Creates an url using a defined route
         *
@@ -288,14 +298,17 @@ class URLGenerator implements IURLGenerator {
                        return $this->getAbsoluteURL($defaultPage);
                }
 
-               $appId = $this->getAppManager()->getDefaultAppForUser();
-
-               if ($this->config->getSystemValueBool('htaccess.IgnoreFrontController', false)
-                       || getenv('front_controller_active') === 'true') {
-                       return $this->getAbsoluteURL('/apps/' . $appId . '/');
+               $entryId = $this->getNavigationManager()->getDefaultEntryIdForUser();
+               $entry = $this->getNavigationManager()->get($entryId);
+               $href = (string)$entry['href'];
+               if ($href === '') {
+                       throw new \InvalidArgumentException('Default navigation entry is missing href: ' . $entryId);
+               }
+               if (str_starts_with($href, '/index.php/') && ($this->config->getSystemValueBool('htaccess.IgnoreFrontController', false) || getenv('front_controller_active') === 'true')) {
+                       $href = substr($href, 10);
                }
 
-               return $this->getAbsoluteURL('/index.php/apps/' . $appId . '/');
+               return $this->getAbsoluteURL($href);
        }
 
        /**