diff --git a/config/config.sample.php b/config/config.sample.php index 5a31f79d4984..58229c146023 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -163,6 +163,14 @@ */ 'defaultapp' => 'files', +/** + * Set the default app path to open on login. For example if the default app is + * "external", set this to /1/ to default to the first External Site. You can + * use a comma-separated list of paths to match up with the apps in defaultapp. + * e.g. if defaultapp='external,files' defaultapp_path='/1/,/?dir=accounting' + */ +'defaultapp_path' => '', + /** * ``true`` enables the Help menu item in the user menu (top right of the * ownCloud Web interface). ``false`` removes the Help item. diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 4e58a737c578..92c73781adcd 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -27,6 +27,7 @@ * @author Marvin Thomas Rabe * @author Michael Gapczynski * @author Morris Jobke + * @author Nick Sweeting * @author Philipp Schaffrath * @author Robin Appelman * @author Robin McCorkell @@ -1089,20 +1090,33 @@ public static function getDefaultPageUrl() { $location = $urlGenerator->getAbsoluteURL($defaultPage); } else { $appId = 'files'; - $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); + $appPath = '/'; + $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', $appId)); + $defaultAppPaths = explode(',', \OCP\Config::getSystemValue('defaultapp_path', $appPath)); + // find the first app that is enabled for the current user - foreach ($defaultApps as $defaultApp) { + foreach ($defaultApps as $idx=>$defaultApp) { $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); + // if app has a corresponding path, use it, otherwise default to / + if (isset($defaultAppPaths[$idx]) && $defaultAppPaths[$idx] !== '') { + $defaultAppPath = strip_tags($defaultAppPaths[$idx]); + } else { + $defaultAppPath = '/'; + } if (static::getAppManager()->isEnabledForUser($defaultApp)) { $appId = $defaultApp; + $appPath = $defaultAppPath; break; } } - - if(getenv('front_controller_active') === 'true') { - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); + if ($appId === 'external' && $appPath === '/') { + // correct external/ to external/1/ if custom path wasn't specified + $appPath = '/1/'; + } + if (getenv('front_controller_active') === 'true') { + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . $appPath); } else { - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . $appPath); } } } diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 442ece6dcce4..ae223b025ee7 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -299,7 +299,7 @@ public function dataProviderForTestIsSharingDisabledForUser() { * * @dataProvider defaultAppsProvider */ - function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { + function testDefaultApps($defaultAppConfig, $defaultAppPathConfig, $expectedPath, $enabledApps) { $oldDefaultApps = \OCP\Config::getSystemValue('defaultapp', ''); // CLI is doing messy stuff with the webroot, so need to work it around $oldWebRoot = \OC::$WEBROOT; @@ -316,6 +316,7 @@ function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { // need to set a user id to make sure enabled apps are read from cache \OC_User::setUserId($this->getUniqueID()); \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig); + \OCP\Config::setSystemValue('defaultapp_path', $defaultAppPathConfig); $this->assertEquals('http://localhost/' . $expectedPath, Dummy_OC_Util::getDefaultPageUrl()); // restore old state @@ -326,30 +327,62 @@ function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { function defaultAppsProvider() { return [ - // none specified, default to files + // neither app nor path specified, default to /files/ [ + '', '', 'index.php/apps/files/', ['files'], ], - // unexisting or inaccessible app specified, default to files + // non-existant or inaccessible app specified, default to /files/ [ 'unexist', + '', 'index.php/apps/files/', ['files'], ], - // non-standard app + // non-standard app with no path specified [ 'calendar', + '', 'index.php/apps/calendar/', ['files', 'calendar'], ], - // non-standard app with fallback + // non-standard app with fallback and no paths specified [ 'contacts,calendar', + '', 'index.php/apps/calendar/', ['files', 'calendar'], ], + // files app with manual app path specified + [ + 'files', + '/?dir=/testfolder', + 'index.php/apps/files/?dir=/testfolder', + ['files'], + ], + // external app with manual app path specified + [ + 'external', + '/3/', + 'index.php/apps/external/3/', + ['external'], + ], + // external app with path / corrected to /1/ automatically + [ + 'external', + '/', + 'index.php/apps/external/1/', + ['external'], + ], + // non-standard app with fallback and custom paths specified + [ + 'contacts,calendar', + '/?view=1,/?view=2', + 'index.php/apps/calendar/?view=2', + ['files', 'calendar'], + ], ]; }