|
|
|
|
@ -12,6 +12,7 @@ namespace OC\App; |
|
|
|
|
use OCP\App\IAppManager; |
|
|
|
|
use OCP\IAppConfig; |
|
|
|
|
use OCP\IGroupManager; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
use OCP\IUserSession; |
|
|
|
|
|
|
|
|
|
class AppManager implements IAppManager { |
|
|
|
|
@ -49,7 +50,7 @@ class AppManager implements IAppManager { |
|
|
|
|
/** |
|
|
|
|
* @return string[] $appId => $enabled |
|
|
|
|
*/ |
|
|
|
|
private function getInstalledApps() { |
|
|
|
|
private function getInstalledAppsValues() { |
|
|
|
|
if (!$this->installedAppsCache) { |
|
|
|
|
$values = $this->appConfig->getValues(false, 'enabled'); |
|
|
|
|
$this->installedAppsCache = array_filter($values, function ($value) { |
|
|
|
|
@ -60,6 +61,29 @@ class AppManager implements IAppManager { |
|
|
|
|
return $this->installedAppsCache; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* List all installed apps |
|
|
|
|
* |
|
|
|
|
* @return string[] |
|
|
|
|
*/ |
|
|
|
|
public function getInstalledApps() { |
|
|
|
|
return array_keys($this->getInstalledAppsValues()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* List all apps enabled for a user |
|
|
|
|
* |
|
|
|
|
* @param \OCP\IUser $user |
|
|
|
|
* @return string[] |
|
|
|
|
*/ |
|
|
|
|
public function getAppsEnabledForUser(IUser $user) { |
|
|
|
|
$apps = $this->getInstalledAppsValues(); |
|
|
|
|
$appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
|
|
|
return $this->checkAppForUser($enabled, $user); |
|
|
|
|
}); |
|
|
|
|
return array_keys($appsForUser); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Check if an app is enabled for user |
|
|
|
|
* |
|
|
|
|
@ -71,24 +95,32 @@ class AppManager implements IAppManager { |
|
|
|
|
if (is_null($user)) { |
|
|
|
|
$user = $this->userSession->getUser(); |
|
|
|
|
} |
|
|
|
|
$installedApps = $this->getInstalledApps(); |
|
|
|
|
$installedApps = $this->getInstalledAppsValues(); |
|
|
|
|
if (isset($installedApps[$appId])) { |
|
|
|
|
$enabled = $installedApps[$appId]; |
|
|
|
|
if ($enabled === 'yes') { |
|
|
|
|
return true; |
|
|
|
|
} elseif (is_null($user)) { |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
$groupIds = json_decode($enabled); |
|
|
|
|
$userGroups = $this->groupManager->getUserGroupIds($user); |
|
|
|
|
foreach ($userGroups as $groupId) { |
|
|
|
|
if (array_search($groupId, $groupIds) !== false) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return $this->checkAppForUser($installedApps[$appId], $user); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $enabled |
|
|
|
|
* @param IUser $user |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
private function checkAppForUser($enabled, $user) { |
|
|
|
|
if ($enabled === 'yes') { |
|
|
|
|
return true; |
|
|
|
|
} elseif (is_null($user)) { |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
$groupIds = json_decode($enabled); |
|
|
|
|
$userGroups = $this->groupManager->getUserGroupIds($user); |
|
|
|
|
foreach ($userGroups as $groupId) { |
|
|
|
|
if (array_search($groupId, $groupIds) !== false) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -100,7 +132,7 @@ class AppManager implements IAppManager { |
|
|
|
|
* @return bool |
|
|
|
|
*/ |
|
|
|
|
public function isInstalled($appId) { |
|
|
|
|
$installedApps = $this->getInstalledApps(); |
|
|
|
|
$installedApps = $this->getInstalledAppsValues(); |
|
|
|
|
return isset($installedApps[$appId]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|