diff options
author | provokateurin <kate@provokateurin.de> | 2024-09-04 17:48:30 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-09-09 11:04:36 +0200 |
commit | d5e98cd190249906aa7547528b3e7123fb6cb94b (patch) | |
tree | d44477ca2d45a090e8452d21e0cb7d2fcf7b97eb /lib/private/NavigationManager.php | |
parent | 0a3093d05da92036684afb5814a4925b443468f7 (diff) | |
download | nextcloud-server-d5e98cd190249906aa7547528b3e7123fb6cb94b.tar.gz nextcloud-server-d5e98cd190249906aa7547528b3e7123fb6cb94b.zip |
fix(NavigationManager): Skip invalid default navigation entries
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'lib/private/NavigationManager.php')
-rw-r--r-- | lib/private/NavigationManager.php | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index e1fbb02fda4..169c7aaf350 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -44,8 +44,6 @@ class NavigationManager implements INavigationManager { private $groupManager; /** @var IConfig */ private $config; - /** The default entry for the current user (cached for the `add` function) */ - private ?string $defaultEntry; /** User defined app order (cached for the `add` function) */ private array $customAppOrder; private LoggerInterface $logger; @@ -66,8 +64,6 @@ class NavigationManager implements INavigationManager { $this->groupManager = $groupManager; $this->config = $config; $this->logger = $logger; - - $this->defaultEntry = null; } /** @@ -100,13 +96,22 @@ class NavigationManager implements INavigationManager { $entry['app'] = $id; } - // This is the default app that will always be shown first - $entry['default'] = ($entry['id'] ?? false) === $this->defaultEntry; // Set order from user defined app order $entry['order'] = (int)($this->customAppOrder[$id]['order'] ?? $entry['order'] ?? 100); } $this->entries[$id] = $entry; + + // Needs to be done after adding the new entry to account for the default entries containing this new entry. + $this->updateDefaultEntries(); + } + + private function updateDefaultEntries() { + foreach ($this->entries as $id => $entry) { + if ($entry['type'] === 'link') { + $this->entries[$id]['default'] = $id === $this->getDefaultEntryIdForUser($this->userSession->getUser(), false); + } + } } /** @@ -221,8 +226,6 @@ class NavigationManager implements INavigationManager { ]); } - $this->defaultEntry = $this->getDefaultEntryIdForUser($this->userSession->getUser(), false); - if ($this->userSession->isLoggedIn()) { // Profile $this->add([ @@ -422,8 +425,8 @@ class NavigationManager implements INavigationManager { public function getDefaultEntryIdForUser(?IUser $user = null, bool $withFallbacks = true): string { $this->init(); - $defaultEntryIds = explode(',', $this->config->getSystemValueString('defaultapp', '')); - $defaultEntryIds = array_filter($defaultEntryIds); + // Disable fallbacks here, as we need to override them with the user defaults if none are configured. + $defaultEntryIds = $this->getDefaultEntryIds(false); $user ??= $this->userSession->getUser(); @@ -461,8 +464,18 @@ class NavigationManager implements INavigationManager { return $withFallbacks ? 'files' : ''; } - public function getDefaultEntryIds(): array { - return explode(',', $this->config->getSystemValueString('defaultapp', 'dashboard,files')); + public function getDefaultEntryIds(bool $withFallbacks = true): array { + $this->init(); + $storedIds = explode(',', $this->config->getSystemValueString('defaultapp', $withFallbacks ? 'dashboard,files' : '')); + $ids = []; + $entryIds = array_keys($this->entries); + foreach ($storedIds as $id) { + if (in_array($id, $entryIds, true)) { + $ids[] = $id; + break; + } + } + return array_filter($ids); } public function setDefaultEntryIds(array $ids): void { |