From f5310c0c26322b736e8d67399501b11ff299ea11 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 4 Jan 2017 10:40:14 +0100 Subject: [PATCH] Remove group restrictions when those are not allowed anymore Signed-off-by: Joas Schilling --- lib/private/App/AppManager.php | 15 +++++++++++++++ lib/private/legacy/app.php | 8 ++++++++ lib/public/App/IAppManager.php | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index fca5c9b87a..6b819ef7ac 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -220,6 +220,21 @@ class AppManager implements IAppManager { $this->clearAppsCache(); } + /** + * Whether a list of types contains a protected app type + * + * @param string[] $types + * @return bool + */ + public function hasProtectedAppType($types) { + if (empty($types)) { + return false; + } + + $protectedTypes = array_intersect($this->protectedAppTypes, $types); + return !empty($protectedTypes); + } + /** * Enable an app only for specific groups * diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index adf29601ac..8ef7e08c73 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -273,9 +273,17 @@ class OC_App { $appTypes = implode(',', $appData['types']); } else { $appTypes = ''; + $appData['types'] = []; } \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); + + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); + if ($enabled !== 'yes' && $enabled !== 'no') { + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); + } + } } /** diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index 057a964ce0..72c9977712 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -61,6 +61,15 @@ interface IAppManager { */ public function enableApp($appId); + /** + * Whether a list of types contains a protected app type + * + * @param string[] $types + * @return bool + * @since 12.0.0 + */ + public function hasProtectedAppType($types); + /** * Enable an app only for specific groups *