From c005515ebd3fcf1d79070b3e7e2a783cf2ea53e1 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 1 Jul 2014 15:42:26 +0200 Subject: [PATCH] Support for multiple default apps If a default app isn't visible for the user, try the next one. Else fallback to the "files" app. --- config/config.sample.php | 6 +++++- lib/private/util.php | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 59e1f3890c..e613609bce 100755 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -74,7 +74,11 @@ $CONFIG = array( /* URL to the parent directory of the 3rdparty directory, as seen by the browser */ "3rdpartyurl" => "", -/* Default app to load on login */ +/* Default app to open on login. + * This can be a comma-separated list of app ids. + * If the first app is not enabled for the current user, + * it will try with the second one and so on. If no enabled app could be found, + * the "files" app will be displayed instead. */ "defaultapp" => "files", /* Enable the help menu item in the settings */ diff --git a/lib/private/util.php b/lib/private/util.php index 424c27e74a..e9e081a48f 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -827,9 +827,17 @@ class OC_Util { if ($defaultPage) { $location = $urlGenerator->getAbsoluteURL($defaultPage); } else { - $defaultApp = \OCP\Config::getSystemValue('defaultapp', 'files'); - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $defaultApp); + $appId = 'files'; + $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); + // find the first app that is enabled for the current user + foreach ($defaultApps as $defaultApp) { + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); + if (OC_App::isEnabled($defaultApp)) { + $appId = $defaultApp; + break; + } + } + $location = $urlGenerator->linkTo($appId, 'index.php'); } } OC_Log::write('core', 'redirectToDefaultPage: '.$location, OC_Log::DEBUG);