diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-16 16:30:29 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-26 09:53:04 +0100 |
commit | 6fc59f85b69af3ab6a8b979b7b6240cc4920efc7 (patch) | |
tree | 55c1de1372d91fec11d9f1abb35e72415a757b7d /lib/private/app | |
parent | 1f32a3e485e33c56c559fc8f354ab82b0e5f7736 (diff) | |
download | nextcloud-server-6fc59f85b69af3ab6a8b979b7b6240cc4920efc7.tar.gz nextcloud-server-6fc59f85b69af3ab6a8b979b7b6240cc4920efc7.zip |
Store list of apps which cannot be disabled in shipped.json
Diffstat (limited to 'lib/private/app')
-rw-r--r-- | lib/private/app/appmanager.php | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/lib/private/app/appmanager.php b/lib/private/app/appmanager.php index 8fb197e73ff..a121b8ab861 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']; + } + } + } + } |