diff options
author | Julius Härtl <jus@bitgrid.net> | 2021-10-05 13:06:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 13:06:59 +0200 |
commit | d68f0282515cb5122cdbd834217b62079dcad9bc (patch) | |
tree | 194113d2fbaef56e5faee18fa3f64b02991e7e66 /lib/private/URLGenerator.php | |
parent | ee32c7c3282407c4cc714dc7e00a374781d9ef56 (diff) | |
parent | 1684fd0b6f9a79641f4558ad33c30b185d5d0bd0 (diff) | |
download | nextcloud-server-d68f0282515cb5122cdbd834217b62079dcad9bc.tar.gz nextcloud-server-d68f0282515cb5122cdbd834217b62079dcad9bc.zip |
Merge pull request #27733 from PhrozenByte/enhancement/noid/IURLGenerator-linkToDefaultPageUrl
Diffstat (limited to 'lib/private/URLGenerator.php')
-rw-r--r-- | lib/private/URLGenerator.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 511c37d2624..382179b23e0 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -8,6 +8,7 @@ declare(strict_types=1); * @author Arthur Schiwon <blizzz@arthur-schiwon.de> * @author Bart Visscher <bartv@thisnet.nl> * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @author Daniel Rudolf <github.com@daniel-rudolf.de> * @author Felix Epp <work@felixepp.de> * @author Joas Schilling <coding@schilljs.com> * @author Jörn Friedrich Dreyer <jfd@butonic.de> @@ -45,6 +46,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\IUserSession; use RuntimeException; /** @@ -53,6 +55,8 @@ use RuntimeException; class URLGenerator implements IURLGenerator { /** @var IConfig */ private $config; + /** @var IUserSession */ + public $userSession; /** @var ICacheFactory */ private $cacheFactory; /** @var IRequest */ @@ -63,10 +67,12 @@ class URLGenerator implements IURLGenerator { private $baseUrl = null; public function __construct(IConfig $config, + IUserSession $userSession, ICacheFactory $cacheFactory, IRequest $request, Router $router) { $this->config = $config; + $this->userSession = $userSession; $this->cacheFactory = $cacheFactory; $this->request = $request; $this->router = $router; @@ -268,6 +274,49 @@ class URLGenerator implements IURLGenerator { } /** + * Returns the URL of the default page based on the system configuration + * and the apps visible for the current user + * @return string + */ + public function linkToDefaultPageUrl(): string { + // Deny the redirect if the URL contains a @ + // This prevents unvalidated redirects like ?redirect_url=:user@domain.com + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { + return $this->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); + } + + $defaultPage = $this->config->getAppValue('core', 'defaultpage'); + if ($defaultPage) { + return $this->getAbsoluteURL($defaultPage); + } + + $appId = 'files'; + $defaultApps = explode(',', $this->config->getSystemValue('defaultapp', 'dashboard,files')); + + $userId = $this->userSession->isLoggedIn() ? $this->userSession->getUser()->getUID() : null; + if ($userId !== null) { + $userDefaultApps = explode(',', $this->config->getUserValue($userId, 'core', 'defaultapp')); + $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps)); + } + + // find the first app that is enabled for the current user + foreach ($defaultApps as $defaultApp) { + $defaultApp = \OC_App::cleanAppId(strip_tags($defaultApp)); + if (\OC::$server->getAppManager()->isEnabledForUser($defaultApp)) { + $appId = $defaultApp; + break; + } + } + + if ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true + || getenv('front_controller_active') === 'true') { + return $this->getAbsoluteURL('/apps/' . $appId . '/'); + } + + return $this->getAbsoluteURL('/index.php/apps/' . $appId . '/'); + } + + /** * @return string base url of the current request */ public function getBaseUrl(): string { |