Skip to content
Prev Previous commit
Next Next commit
fix(URLGenerator): Use NavigationManager to generate default page URL
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 9, 2024
commit 01ec6762a249dbedc0bee452eb698c1dc6a52431
25 changes: 19 additions & 6 deletions lib/private/URLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\App\IAppManager;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
Expand All @@ -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,
Expand All @@ -58,6 +60,14 @@ private function getAppManager(): IAppManager {
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
*
Expand Down Expand Up @@ -288,14 +298,17 @@ public function linkToDefaultPageUrl(): string {
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);
}

/**
Expand Down