summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-07-01 20:39:13 +0200
committerVincent Petry <pvince81@owncloud.com>2014-07-01 20:39:13 +0200
commit3d921ed3c35cba877015062fef27f2ad83717e7e (patch)
tree4d228a4d434c92454c598123f96ba41bafd4be90
parent19a6dc5420d3a27c50590b2f060700edff2ef73e (diff)
parent7c174520289dc5337dda1d32352e7542cb329670 (diff)
downloadnextcloud-server-3d921ed3c35cba877015062fef27f2ad83717e7e.tar.gz
nextcloud-server-3d921ed3c35cba877015062fef27f2ad83717e7e.zip
Merge pull request #9334 from owncloud/defaultappfix
Default app fix
-rwxr-xr-xconfig/config.sample.php6
-rw-r--r--lib/private/app.php2
-rwxr-xr-xlib/private/util.php32
-rw-r--r--tests/lib/util.php68
4 files changed, 101 insertions, 7 deletions
diff --git a/config/config.sample.php b/config/config.sample.php
index 59e1f3890ce..e613609bcef 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/app.php b/lib/private/app.php
index 9fb0ec2e34f..0ca2ca36bd2 100644
--- a/lib/private/app.php
+++ b/lib/private/app.php
@@ -163,7 +163,7 @@ class OC_App {
/**
* get all enabled apps
*/
- private static $enabledAppsCache = array();
+ protected static $enabledAppsCache = array();
public static function getEnabledApps($forceRefresh = false) {
if (!OC_Config::getValue('installed', false)) {
diff --git a/lib/private/util.php b/lib/private/util.php
index 7836489832d..897795f7535 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -815,10 +815,13 @@ class OC_Util {
}
/**
- * Redirect to the user default page
- * @return void
+ * Returns the URL of the default page
+ * based on the system configuration and
+ * the apps visible for the current user
+ *
+ * @return string URL
*/
- public static function redirectToDefaultPage() {
+ public static function getDefaultPageUrl() {
$urlGenerator = \OC::$server->getURLGenerator();
if(isset($_REQUEST['redirect_url'])) {
$location = urldecode($_REQUEST['redirect_url']);
@@ -827,11 +830,30 @@ class OC_Util {
if ($defaultPage) {
$location = $urlGenerator->getAbsoluteURL($defaultPage);
} else {
- $location = $urlGenerator->getAbsoluteURL('/index.php/apps/files');
+ $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->getAbsoluteURL('/index.php/apps/' . $appId . '/');
}
}
+ return $location;
+ }
+
+ /**
+ * Redirect to the user default page
+ * @return void
+ */
+ public static function redirectToDefaultPage() {
+ $location = self::getDefaultPageUrl();
OC_Log::write('core', 'redirectToDefaultPage: '.$location, OC_Log::DEBUG);
- header( 'Location: '.$location );
+ header('Location: '.$location);
exit();
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index aaa47f033de..c2bb99c3b2e 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -290,4 +290,72 @@ class Test_Util extends PHPUnit_Framework_TestCase {
array(array('g1', 'g2', 'g3'), array('g1', 'g2'), array('g1', 'g2', 'g3'), true),
);
}
+
+ /**
+ * Test default apps
+ *
+ * @dataProvider defaultAppsProvider
+ */
+ function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) {
+ $oldDefaultApps = \OCP\Config::getSystemValue('core', 'defaultapp', '');
+ // CLI is doing messy stuff with the webroot, so need to work it around
+ $oldWebRoot = \OC::$WEBROOT;
+ \OC::$WEBROOT = '';
+
+ Dummy_OC_App::setEnabledApps($enabledApps);
+ \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig);
+ $this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl());
+
+ // restore old state
+ \OC::$WEBROOT = $oldWebRoot;
+ Dummy_OC_App::restore();
+ \OCP\Config::setSystemValue('defaultapp', $oldDefaultApps);
+ }
+
+ function defaultAppsProvider() {
+ return array(
+ // none specified, default to files
+ array(
+ '',
+ 'index.php/apps/files/',
+ array('files'),
+ ),
+ // unexisting or inaccessible app specified, default to files
+ array(
+ 'unexist',
+ 'index.php/apps/files/',
+ array('files'),
+ ),
+ // non-standard app
+ array(
+ 'calendar',
+ 'index.php/apps/calendar/',
+ array('files', 'calendar'),
+ ),
+ // non-standard app with fallback
+ array(
+ 'contacts,calendar',
+ 'index.php/apps/calendar/',
+ array('files', 'calendar'),
+ ),
+ );
+ }
+
+}
+
+/**
+ * Dummy OC Apps class to make it possible to override
+ * enabled apps
+ */
+class Dummy_OC_App extends OC_App {
+ private static $enabledAppsCacheBackup;
+
+ public static function setEnabledApps($enabledApps) {
+ self::$enabledAppsCacheBackup = self::$enabledAppsCache;
+ self::$enabledAppsCache = $enabledApps;
+ }
+
+ public static function restore() {
+ self::$enabledAppsCache = self::$enabledAppsCacheBackup;
+ }
}