From 6fc59f85b69af3ab6a8b979b7b6240cc4920efc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 16 Oct 2015 16:30:29 +0200 Subject: [PATCH 1/3] Store list of apps which cannot be disabled in shipped.json --- core/shipped.json | 4 +++ lib/private/app.php | 20 +----------- lib/private/app/appmanager.php | 59 ++++++++++++++++++++++++++-------- lib/public/app/iappmanager.php | 7 ++++ 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/core/shipped.json b/core/shipped.json index 7d506c3401..b6f08a8b96 100644 --- a/core/shipped.json +++ b/core/shipped.json @@ -31,5 +31,9 @@ "user_ldap", "user_shibboleth", "windows_network_drive" + ], + "alwaysEnabled": [ + "files", + "dav" ] } diff --git a/lib/private/app.php b/lib/private/app.php index 718adcd25c..a95019ac02 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -61,7 +61,6 @@ class OC_App { static private $appTypes = array(); static private $loadedApps = array(); static private $altLogin = array(); - private static $shippedApps = null; const officialApp = 200; /** @@ -223,18 +222,7 @@ class OC_App { * Check if an app that is installed is a shipped app or installed from the appstore. */ public static function isShipped($appId) { - if (is_null(self::$shippedApps)) { - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; - if (file_exists($shippedJson)) { - self::$shippedApps = json_decode(file_get_contents($shippedJson), true); - self::$shippedApps = self::$shippedApps['shippedApps']; - } else { - self::$shippedApps = ['files', 'encryption', 'files_external', - 'files_sharing', 'files_trashbin', 'files_versions', 'provisioning_api', - 'user_ldap', 'user_webdavauth']; - } - } - return in_array($appId, self::$shippedApps); + return \OC::$server->getAppManager()->isShipped($appId); } /** @@ -285,9 +273,6 @@ class OC_App { * This function checks whether or not an app is enabled. */ public static function isEnabled($app) { - if ('files' == $app) { - return true; - } return \OC::$server->getAppManager()->isEnabledForUser($app); } @@ -368,9 +353,6 @@ class OC_App { $app = self::getInternalAppIdByOcs($app); } - if($app === 'files') { - throw new \Exception("files can't be disabled."); - } self::$enabledAppsCache = array(); // flush // check if app is a shipped app or not. if not delete \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 8fb197e73f..a121b8ab86 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -33,29 +33,28 @@ use OCP\IUser; use OCP\IUserSession; class AppManager implements IAppManager { - /** - * @var \OCP\IUserSession - */ + + /** @var \OCP\IUserSession */ private $userSession; - /** - * @var \OCP\IAppConfig - */ + /** @var \OCP\IAppConfig */ private $appConfig; - /** - * @var \OCP\IGroupManager - */ + /** @var \OCP\IGroupManager */ private $groupManager; /** @var \OCP\ICacheFactory */ private $memCacheFactory; - /** - * @var string[] $appId => $enabled - */ + /** @var string[] $appId => $enabled */ private $installedAppsCache; + /** @var string[] */ + private $shippedApps; + + /** @var string[] */ + private $alwaysEnabled; + /** * @param \OCP\IUserSession $userSession * @param \OCP\IAppConfig $appConfig @@ -117,6 +116,9 @@ class AppManager implements IAppManager { * @return bool */ public function isEnabledForUser($appId, $user = null) { + if ($this->isAlwaysEnabled($appId)) { + return true; + } if (is_null($user)) { $user = $this->userSession->getUser(); } @@ -134,6 +136,9 @@ class AppManager implements IAppManager { * @return bool */ private function checkAppForUser($enabled, $user) { + if ($this->isAlwaysEnabled($enabled)) { + return true; + } if ($enabled === 'yes') { return true; } elseif (is_null($user)) { @@ -195,8 +200,8 @@ class AppManager implements IAppManager { * @throws \Exception if app can't be disabled */ public function disableApp($appId) { - if ($appId === 'files') { - throw new \Exception("files can't be disabled."); + if ($this->isAlwaysEnabled($appId)) { + throw new \Exception("$appId can't be disabled."); } unset($this->installedAppsCache[$appId]); $this->appConfig->setValue($appId, 'enabled', 'no'); @@ -279,4 +284,30 @@ class AppManager implements IAppManager { return $incompatibleApps; } + public function isShipped($appId) { + $this->loadShippedJson(); + return in_array($appId, $this->shippedApps); + } + + private function isAlwaysEnabled($appId) { + $this->loadShippedJson(); + return in_array($appId, $this->alwaysEnabled); + } + + private function loadShippedJson() { + if (is_null($this->shippedApps)) { + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; + if (file_exists($shippedJson)) { + $content = json_decode(file_get_contents($shippedJson), true); + $this->shippedApps = $content['shippedApps']; + $this->alwaysEnabled = $content['alwaysEnabled']; + } else { + $this->shippedApps = ['files', 'encryption', 'files_external', + 'files_sharing', 'files_trashbin', 'files_versions', 'provisioning_api', + 'user_ldap', 'user_webdavauth']; + $this->alwaysEnabled = ['files', 'dav']; + } + } + } + } diff --git a/lib/public/app/iappmanager.php b/lib/public/app/iappmanager.php index d8f261660c..afbd64d281 100644 --- a/lib/public/app/iappmanager.php +++ b/lib/public/app/iappmanager.php @@ -98,4 +98,11 @@ interface IAppManager { * @since 8.1.0 */ public function clearAppsCache(); + + /** + * @param string $appId + * @return boolean + * @since 9.0.0 + */ + public function isShipped($appId); } From 5a5bcccd0d612bbb23214777d33a6439b75ffb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 16 Oct 2015 16:38:43 +0200 Subject: [PATCH 2/3] Don't show apps which are always enabled in the app manager --- lib/private/app.php | 6 ++---- lib/private/app/appmanager.php | 17 ++++++++++++----- lib/public/app/iappmanager.php | 6 ++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/private/app.php b/lib/private/app.php index a95019ac02..d7e62dfd85 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -768,12 +768,9 @@ class OC_App { if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { $apps[] = $file; - } - } } - } return $apps; @@ -793,7 +790,8 @@ class OC_App { //TODO which apps do we want to blacklist and how do we integrate // blacklisting with the multi apps folder feature? - $blacklist = array('files'); //we don't want to show configuration for these + //we don't want to show configuration for these + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); $appList = array(); $l = \OC::$server->getL10N('core'); diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index a121b8ab86..5a932b7dc3 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -136,9 +136,6 @@ class AppManager implements IAppManager { * @return bool */ private function checkAppForUser($enabled, $user) { - if ($this->isAlwaysEnabled($enabled)) { - return true; - } if ($enabled === 'yes') { return true; } elseif (is_null($user)) { @@ -284,14 +281,17 @@ class AppManager implements IAppManager { return $incompatibleApps; } + /** + * @inheritdoc + */ public function isShipped($appId) { $this->loadShippedJson(); return in_array($appId, $this->shippedApps); } private function isAlwaysEnabled($appId) { - $this->loadShippedJson(); - return in_array($appId, $this->alwaysEnabled); + $alwaysEnabled = $this->getAlwaysEnabledApps(); + return in_array($appId, $alwaysEnabled); } private function loadShippedJson() { @@ -310,4 +310,11 @@ class AppManager implements IAppManager { } } + /** + * @inheritdoc + */ + public function getAlwaysEnabledApps() { + $this->loadShippedJson(); + return $this->alwaysEnabled; + } } diff --git a/lib/public/app/iappmanager.php b/lib/public/app/iappmanager.php index afbd64d281..09b6bd3f2b 100644 --- a/lib/public/app/iappmanager.php +++ b/lib/public/app/iappmanager.php @@ -105,4 +105,10 @@ interface IAppManager { * @since 9.0.0 */ public function isShipped($appId); + + /** + * @return string[] + * @since 9.0.0 + */ + public function getAlwaysEnabledApps(); } From 2038b2ec34ff44165932ab9d94db54bc6f924577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 26 Oct 2015 09:52:47 +0100 Subject: [PATCH 3/3] Fail hard if shipped.json is missing --- lib/private/app/appmanager.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 5a932b7dc3..1f993d8538 100644 --- a/lib/private/app/appmanager.php +++ b/lib/private/app/appmanager.php @@ -297,16 +297,12 @@ class AppManager implements IAppManager { private function loadShippedJson() { if (is_null($this->shippedApps)) { $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; - if (file_exists($shippedJson)) { - $content = json_decode(file_get_contents($shippedJson), true); - $this->shippedApps = $content['shippedApps']; - $this->alwaysEnabled = $content['alwaysEnabled']; - } else { - $this->shippedApps = ['files', 'encryption', 'files_external', - 'files_sharing', 'files_trashbin', 'files_versions', 'provisioning_api', - 'user_ldap', 'user_webdavauth']; - $this->alwaysEnabled = ['files', 'dav']; + if (!file_exists($shippedJson)) { + throw new \Exception("File not found: $shippedJson"); } + $content = json_decode(file_get_contents($shippedJson), true); + $this->shippedApps = $content['shippedApps']; + $this->alwaysEnabled = $content['alwaysEnabled']; } }