diff options
author | provokateurin <kate@provokateurin.de> | 2024-08-27 12:14:09 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-09-09 11:04:36 +0200 |
commit | 70ed08daf1d6845af5df3a4a0b06eb73d190c6cf (patch) | |
tree | 4537190b9b1a700e0ce819d80c19ac4c693b3796 /lib/private | |
parent | b0baaaed9dfdce8c2630255d0d1921679579761d (diff) | |
download | nextcloud-server-70ed08daf1d6845af5df3a4a0b06eb73d190c6cf.tar.gz nextcloud-server-70ed08daf1d6845af5df3a4a0b06eb73d190c6cf.zip |
refactor(AppManager): Deprecated default apps handling
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/App/AppManager.php | 82 |
1 files changed, 36 insertions, 46 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 2f129ca77fa..fe2f7b74b22 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -6,7 +6,6 @@ */ namespace OC\App; -use InvalidArgumentException; use OC\AppConfig; use OC\AppFramework\Bootstrap\Coordinator; use OC\ServerNotAvailableException; @@ -24,6 +23,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; +use OCP\INavigationManager; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; @@ -67,6 +67,7 @@ class AppManager implements IAppManager { private ?AppConfig $appConfig = null; private ?IURLGenerator $urlGenerator = null; + private ?INavigationManager $navigationManager = null; /** * Be extremely careful when injecting classes here. The AppManager is used by the installer, @@ -82,6 +83,13 @@ class AppManager implements IAppManager { ) { } + private function getNavigationManager(): INavigationManager { + if ($this->navigationManager === null) { + $this->navigationManager = \OCP\Server::get(INavigationManager::class); + } + return $this->navigationManager; + } + public function getAppIcon(string $appId, bool $dark = false): ?string { $possibleIcons = $dark ? [$appId . '-dark.svg', 'app-dark.svg'] : [$appId . '.svg', 'app.svg']; $icon = null; @@ -820,60 +828,42 @@ class AppManager implements IAppManager { return $this->defaultEnabled; } + /** + * @inheritdoc + */ public function getDefaultAppForUser(?IUser $user = null, bool $withFallbacks = true): string { - // Set fallback to always-enabled files app - $appId = $withFallbacks ? 'files' : ''; - $defaultApps = explode(',', $this->config->getSystemValueString('defaultapp', '')); - $defaultApps = array_filter($defaultApps); - - $user ??= $this->userSession->getUser(); - - if ($user !== null) { - $userDefaultApps = explode(',', $this->config->getUserValue($user->getUID(), 'core', 'defaultapp')); - $defaultApps = array_filter(array_merge($userDefaultApps, $defaultApps)); - if (empty($defaultApps) && $withFallbacks) { - /* Fallback on user defined apporder */ - $customOrders = json_decode($this->config->getUserValue($user->getUID(), 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR); - if (!empty($customOrders)) { - // filter only entries with app key (when added using closures or NavigationManager::add the app is not guranteed to be set) - $customOrders = array_filter($customOrders, fn ($entry) => isset($entry['app'])); - // sort apps by order - usort($customOrders, fn ($a, $b) => $a['order'] - $b['order']); - // set default apps to sorted apps - $defaultApps = array_map(fn ($entry) => $entry['app'], $customOrders); - } - } - } - - if (empty($defaultApps) && $withFallbacks) { - $defaultApps = ['dashboard','files']; - } - - // Find the first app that is enabled for the current user - foreach ($defaultApps as $defaultApp) { - $defaultApp = \OC_App::cleanAppId(strip_tags($defaultApp)); - if ($this->isEnabledForUser($defaultApp, $user)) { - $appId = $defaultApp; - break; - } - } - - return $appId; + $id = $this->getNavigationManager()->getDefaultEntryIdForUser($user, $withFallbacks); + $entry = $this->getNavigationManager()->get($id); + return (string)$entry['app']; } + /** + * @inheritdoc + */ public function getDefaultApps(): array { - return explode(',', $this->config->getSystemValueString('defaultapp', 'dashboard,files')); + $ids = $this->getNavigationManager()->getDefaultEntryIds(); + + return array_values(array_unique(array_map(function (string $id) { + $entry = $this->getNavigationManager()->get($id); + return (string)$entry['app']; + }, $ids))); } + /** + * @inheritdoc + */ public function setDefaultApps(array $defaultApps): void { - foreach ($defaultApps as $app) { - if (!$this->isInstalled($app)) { - $this->logger->debug('Can not set not installed app as default app', ['missing_app' => $app]); - throw new InvalidArgumentException('App is not installed'); + $entries = $this->getNavigationManager()->getAll(); + $ids = []; + foreach ($defaultApps as $defaultApp) { + foreach ($entries as $entry) { + if ((string)$entry['app'] === $defaultApp) { + $ids[] = (string)$entry['id']; + break; + } } } - - $this->config->setSystemValue('defaultapp', join(',', $defaultApps)); + $this->getNavigationManager()->setDefaultEntryIds($ids); } public function isBackendRequired(string $backend): bool { |