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 | |
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')
-rw-r--r-- | lib/base.php | 6 | ||||
-rw-r--r-- | lib/private/URLGenerator.php | 49 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 45 | ||||
-rw-r--r-- | lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php | 12 | ||||
-rw-r--r-- | lib/public/IURLGenerator.php | 8 |
5 files changed, 72 insertions, 48 deletions
diff --git a/lib/base.php b/lib/base.php index 45d06da0303..94610576fce 100644 --- a/lib/base.php +++ b/lib/base.php @@ -1021,12 +1021,10 @@ class OC { OC_App::loadApps(); OC_User::setupBackends(); OC_Util::setupFS(); - // FIXME - // Redirect to default application - OC_Util::redirectToDefaultPage(); + header('Location: ' . \OC::$server->getURLGenerator()->linkToDefaultPageUrl()); } else { // Not handled and not logged in - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); + header('Location: ' . \OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); } } 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 { diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 333b621e359..35c81dd34e6 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -71,8 +71,8 @@ use OCP\Files\Template\ITemplateManager; use OCP\IConfig; use OCP\IGroupManager; use OCP\ILogger; +use OCP\IURLGenerator; use OCP\IUser; -use OCP\IUserSession; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -1090,46 +1090,9 @@ class OC_Util { * @suppress PhanDeprecatedFunction */ public static function getDefaultPageUrl() { - /** @var IConfig $config */ - $config = \OC::$server->get(IConfig::class); - $urlGenerator = \OC::$server->getURLGenerator(); - // 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) { - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); - } else { - $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); - if ($defaultPage) { - $location = $urlGenerator->getAbsoluteURL($defaultPage); - } else { - $appId = 'files'; - $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'dashboard,files')); - - /** @var IUserSession $userSession */ - $userSession = \OC::$server->get(IUserSession::class); - $user = $userSession->getUser(); - if ($user) { - $userDefaultApps = explode(',', $config->getUserValue($user->getUID(), '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 (static::getAppManager()->isEnabledForUser($defaultApp)) { - $appId = $defaultApp; - break; - } - } - - if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); - } else { - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); - } - } - } - return $location; + /** @var IURLGenerator $urlGenerator */ + $urlGenerator = \OC::$server->get(IURLGenerator::class); + return $urlGenerator->linkToDefaultPageUrl(); } /** diff --git a/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php b/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php index 36e629d6342..e957b245e53 100644 --- a/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php +++ b/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php @@ -26,18 +26,24 @@ declare(strict_types=1); */ namespace OCP\AppFramework\Http; +use OCP\IURLGenerator; + /** * Redirects to the default app + * * @since 16.0.0 + * @depreacted 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead */ class RedirectToDefaultAppResponse extends RedirectResponse { - - /** * Creates a response that redirects to the default app + * * @since 16.0.0 + * @depreacted 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead */ public function __construct() { - parent::__construct(\OC_Util::getDefaultPageUrl()); + /** @var IURLGenerator $urlGenerator */ + $urlGenerator = \OC::$server->get(IURLGenerator::class); + parent::__construct($urlGenerator->linkToDefaultPageUrl()); } } diff --git a/lib/public/IURLGenerator.php b/lib/public/IURLGenerator.php index 9f1a6447eb4..580536b8b5f 100644 --- a/lib/public/IURLGenerator.php +++ b/lib/public/IURLGenerator.php @@ -98,6 +98,14 @@ interface IURLGenerator { public function linkToDocs(string $key): string; /** + * Returns the URL of the default page based on the system configuration + * and the apps visible for the current user + * @return string + * @since 23.0.0 + */ + public function linkToDefaultPageUrl(): string; + + /** * @return string base url of the current request * @since 13.0.0 */ |