aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/App/AppManager.php
diff options
context:
space:
mode:
authorGreta Doci <gretadoci@gmail.com>2019-06-25 15:20:06 +0200
committerGreta Doci <gretadoci@gmail.com>2019-06-27 20:17:50 +0200
commit5898e87e0f69ed4a3be73cd044c19d7c4872b639 (patch)
tree5b5c2914f5d8523db948487b814b95262a10ab09 /lib/private/App/AppManager.php
parentdc9e73a6df24136ea18bf630ae07cb333817a8ef (diff)
downloadnextcloud-server-5898e87e0f69ed4a3be73cd044c19d7c4872b639.tar.gz
nextcloud-server-5898e87e0f69ed4a3be73cd044c19d7c4872b639.zip
Remove deleted groups from app restrictions fixes #15823
Signed-off-by: Greta Doci <gretadoci@gmail.com>
Diffstat (limited to 'lib/private/App/AppManager.php')
-rw-r--r--lib/private/App/AppManager.php65
1 files changed, 64 insertions, 1 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php
index 7d4dbbbd34e..77756999c79 100644
--- a/lib/private/App/AppManager.php
+++ b/lib/private/App/AppManager.php
@@ -37,6 +37,7 @@ use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\App\ManagerEvent;
use OCP\ICacheFactory;
+use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
@@ -149,6 +150,36 @@ class AppManager implements IAppManager {
}
/**
+ * @param \OCP\IGroup $group
+ * @return array
+ */
+ public function getEnabledAppsForGroup(IGroup $group): array {
+ $apps = $this->getInstalledAppsValues();
+ $appsForGroups = array_filter($apps, function ($enabled) use ($group) {
+ return $this->checkAppForGroups($enabled, $group);
+ });
+ return array_keys($appsForGroups);
+ }
+
+ /**
+ * @param string $appId
+ * @return array
+ */
+ public function getAppRestriction(string $appId): array {
+ $values = $this->getInstalledAppsValues();
+
+ if (!isset($values[$appId])) {
+ return [];
+ }
+
+ if ($values[$appId] === 'yes' || $values[$appId] === 'no') {
+ return [];
+ }
+ return json_decode($values[$appId]);
+ }
+
+
+ /**
* Check if an app is enabled for user
*
* @param string $appId
@@ -204,11 +235,39 @@ class AppManager implements IAppManager {
}
/**
+ * @param string $enabled
+ * @param IGroup $group
+ * @return bool
+ */
+ private function checkAppForGroups(string $enabled, IGroup $group): bool {
+ if ($enabled === 'yes') {
+ return true;
+ } elseif ($group === null) {
+ return false;
+ } else {
+ if (empty($enabled)) {
+ return false;
+ }
+
+ $groupIds = json_decode($enabled);
+
+ if (!is_array($groupIds)) {
+ $jsonError = json_last_error();
+ \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']);
+ return false;
+ }
+
+ return in_array($group->getGID(), $groupIds);
+ }
+ }
+
+ /**
* Check if an app is enabled in the instance
*
* Notice: This actually checks if the app is enabled and not only if it is installed.
*
* @param string $appId
+ * @param \OCP\IGroup[]|String[] $groups
* @return bool
*/
public function isInstalled($appId) {
@@ -268,14 +327,18 @@ class AppManager implements IAppManager {
$groupIds = array_map(function ($group) {
/** @var \OCP\IGroup $group */
- return $group->getGID();
+ return ($group instanceof IGroup)
+ ? $group->getGID()
+ : $group;
}, $groups);
+
$this->installedAppsCache[$appId] = json_encode($groupIds);
$this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
));
$this->clearAppsCache();
+
}
/**