Skip to content

Commit 927e7fc

Browse files
committed
fix(AppManager): Ensure that app manager can handle empty app keys on the navigation entries
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 54a3012 commit 927e7fc

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

lib/private/App/AppManager.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,12 @@ public function getDefaultAppForUser(?IUser $user = null, bool $withFallbacks =
838838
/* Fallback on user defined apporder */
839839
$customOrders = json_decode($this->config->getUserValue($user->getUID(), 'core', 'apporder', '[]'), true, flags:JSON_THROW_ON_ERROR);
840840
if (!empty($customOrders)) {
841-
uasort($customOrders, function ($a, $b) {
842-
return $a['order'] - $b['order'];
843-
});
844-
$defaultApps = array_keys($customOrders);
841+
// filter only entries with app key (when added using closures or NavigationManager::add the app is not guranteed to be set)
842+
$customOrders = array_filter($customOrders, fn ($entry) => isset($entry['app']));
843+
// sort apps by order
844+
usort($customOrders, fn ($a, $b) => $a['order'] - $b['order']);
845+
// set default apps to sorted apps
846+
$defaultApps = array_map(fn ($entry) => $entry['app'], $customOrders);
845847
}
846848
}
847849
}

lib/public/App/IAppManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ public function getAppRestriction(string $appId): array;
250250
*
251251
* @param ?IUser $user User to query default app for
252252
* @param bool $withFallbacks Include fallback values if no default app was configured manually
253+
* Before falling back to predefined default apps,
254+
* the user defined app order is considered and the first app would be used as the fallback.
253255
*
254256
* @since 25.0.6
255257
* @since 28.0.0 Added optional $withFallbacks parameter

tests/lib/App/AppManagerTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,17 @@ public function provideDefaultApps(): array {
660660
true,
661661
'settings',
662662
],
663+
// system default app and user apporder
664+
[
665+
// system default is settings
666+
'unexist,settings',
667+
'',
668+
// apporder says default app is files (order is lower)
669+
'{"files_id":{"app":"files","order":1},"settings_id":{"app":"settings","order":2}}',
670+
true,
671+
// system default should override apporder
672+
'settings'
673+
],
663674
// user-customized defaultapp
664675
[
665676
'',
@@ -680,18 +691,26 @@ public function provideDefaultApps(): array {
680691
[
681692
'unexist,settings',
682693
'files',
683-
'{"settings":{"app":"settings","order":1},"files":{"app":"files","order":2}}',
694+
'{"settings_id":{"app":"settings","order":1},"files_id":{"app":"files","order":2}}',
684695
true,
685696
'files',
686697
],
687698
// user-customized apporder fallback
688699
[
689700
'',
690701
'',
691-
'{"settings":{"app":"settings","order":1},"files":{"app":"files","order":2}}',
702+
'{"settings_id":{"app":"settings","order":1},"files":{"app":"files","order":2}}',
692703
true,
693704
'settings',
694705
],
706+
// user-customized apporder fallback with missing app key (entries added by closures does not always have an app key set (Nextcloud 27 spreed app for example))
707+
[
708+
'',
709+
'',
710+
'{"spreed":{"order":1},"files":{"app":"files","order":2}}',
711+
true,
712+
'files',
713+
],
695714
// user-customized apporder, but called without fallback
696715
[
697716
'',
@@ -700,6 +719,14 @@ public function provideDefaultApps(): array {
700719
false,
701720
'',
702721
],
722+
// user-customized apporder with an app that has multiple routes
723+
[
724+
'',
725+
'',
726+
'{"settings_id":{"app":"settings","order":1},"settings_id_2":{"app":"settings","order":3},"id_files":{"app":"files","order":2}}',
727+
true,
728+
'settings',
729+
],
703730
];
704731
}
705732

0 commit comments

Comments
 (0)