Merge pull request #19837 from owncloud/always-enabled-apps

Store list of apps which cannot be disabled in shipped.json
This commit is contained in:
Thomas Müller 2015-10-26 17:14:29 +01:00
commit 40ba8d267f
4 changed files with 68 additions and 37 deletions

View File

@ -31,5 +31,9 @@
"user_ldap", "user_ldap",
"user_shibboleth", "user_shibboleth",
"windows_network_drive" "windows_network_drive"
],
"alwaysEnabled": [
"files",
"dav"
] ]
} }

View File

@ -61,7 +61,6 @@ class OC_App {
static private $appTypes = array(); static private $appTypes = array();
static private $loadedApps = array(); static private $loadedApps = array();
static private $altLogin = array(); static private $altLogin = array();
private static $shippedApps = null;
const officialApp = 200; 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. * Check if an app that is installed is a shipped app or installed from the appstore.
*/ */
public static function isShipped($appId) { public static function isShipped($appId) {
if (is_null(self::$shippedApps)) { return \OC::$server->getAppManager()->isShipped($appId);
$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);
} }
/** /**
@ -285,9 +273,6 @@ class OC_App {
* This function checks whether or not an app is enabled. * This function checks whether or not an app is enabled.
*/ */
public static function isEnabled($app) { public static function isEnabled($app) {
if ('files' == $app) {
return true;
}
return \OC::$server->getAppManager()->isEnabledForUser($app); return \OC::$server->getAppManager()->isEnabledForUser($app);
} }
@ -368,9 +353,6 @@ class OC_App {
$app = self::getInternalAppIdByOcs($app); $app = self::getInternalAppIdByOcs($app);
} }
if($app === 'files') {
throw new \Exception("files can't be disabled.");
}
self::$enabledAppsCache = array(); // flush self::$enabledAppsCache = array(); // flush
// check if app is a shipped app or not. if not delete // check if app is a shipped app or not. if not delete
\OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app));
@ -786,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')) { if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
$apps[] = $file; $apps[] = $file;
} }
} }
} }
} }
return $apps; return $apps;
@ -811,7 +790,8 @@ class OC_App {
//TODO which apps do we want to blacklist and how do we integrate //TODO which apps do we want to blacklist and how do we integrate
// blacklisting with the multi apps folder feature? // 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(); $appList = array();
$l = \OC::$server->getL10N('core'); $l = \OC::$server->getL10N('core');

View File

@ -33,29 +33,28 @@ use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
class AppManager implements IAppManager { class AppManager implements IAppManager {
/**
* @var \OCP\IUserSession /** @var \OCP\IUserSession */
*/
private $userSession; private $userSession;
/** /** @var \OCP\IAppConfig */
* @var \OCP\IAppConfig
*/
private $appConfig; private $appConfig;
/** /** @var \OCP\IGroupManager */
* @var \OCP\IGroupManager
*/
private $groupManager; private $groupManager;
/** @var \OCP\ICacheFactory */ /** @var \OCP\ICacheFactory */
private $memCacheFactory; private $memCacheFactory;
/** /** @var string[] $appId => $enabled */
* @var string[] $appId => $enabled
*/
private $installedAppsCache; private $installedAppsCache;
/** @var string[] */
private $shippedApps;
/** @var string[] */
private $alwaysEnabled;
/** /**
* @param \OCP\IUserSession $userSession * @param \OCP\IUserSession $userSession
* @param \OCP\IAppConfig $appConfig * @param \OCP\IAppConfig $appConfig
@ -117,6 +116,9 @@ class AppManager implements IAppManager {
* @return bool * @return bool
*/ */
public function isEnabledForUser($appId, $user = null) { public function isEnabledForUser($appId, $user = null) {
if ($this->isAlwaysEnabled($appId)) {
return true;
}
if (is_null($user)) { if (is_null($user)) {
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
} }
@ -195,8 +197,8 @@ class AppManager implements IAppManager {
* @throws \Exception if app can't be disabled * @throws \Exception if app can't be disabled
*/ */
public function disableApp($appId) { public function disableApp($appId) {
if ($appId === 'files') { if ($this->isAlwaysEnabled($appId)) {
throw new \Exception("files can't be disabled."); throw new \Exception("$appId can't be disabled.");
} }
unset($this->installedAppsCache[$appId]); unset($this->installedAppsCache[$appId]);
$this->appConfig->setValue($appId, 'enabled', 'no'); $this->appConfig->setValue($appId, 'enabled', 'no');
@ -279,4 +281,36 @@ class AppManager implements IAppManager {
return $incompatibleApps; return $incompatibleApps;
} }
/**
* @inheritdoc
*/
public function isShipped($appId) {
$this->loadShippedJson();
return in_array($appId, $this->shippedApps);
}
private function isAlwaysEnabled($appId) {
$alwaysEnabled = $this->getAlwaysEnabledApps();
return in_array($appId, $alwaysEnabled);
}
private function loadShippedJson() {
if (is_null($this->shippedApps)) {
$shippedJson = \OC::$SERVERROOT . '/core/shipped.json';
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'];
}
}
/**
* @inheritdoc
*/
public function getAlwaysEnabledApps() {
$this->loadShippedJson();
return $this->alwaysEnabled;
}
} }

View File

@ -98,4 +98,17 @@ interface IAppManager {
* @since 8.1.0 * @since 8.1.0
*/ */
public function clearAppsCache(); public function clearAppsCache();
/**
* @param string $appId
* @return boolean
* @since 9.0.0
*/
public function isShipped($appId);
/**
* @return string[]
* @since 9.0.0
*/
public function getAlwaysEnabledApps();
} }