Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/private/NavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function add($entry) {
$this->closureEntries[] = $entry;
return;
}
$this->init();
$this->init(false);

$id = $entry['id'];

Expand Down Expand Up @@ -123,10 +123,6 @@ private function updateDefaultEntries() {
*/
public function getAll(string $type = 'link'): array {
$this->init();
foreach ($this->closureEntries as $c) {
$this->add($c());
}
$this->closureEntries = [];

$result = $this->entries;
if ($type !== 'all') {
Expand Down Expand Up @@ -212,7 +208,13 @@ public function getActiveEntry() {
return $this->activeEntry;
}

private function init() {
private function init(bool $resolveClosures = true): void {
if ($resolveClosures) {
while ($c = array_pop($this->closureEntries)) {
$this->add($c());
}
}

if ($this->init) {
return;
}
Expand Down Expand Up @@ -420,11 +422,6 @@ public function setUnreadCounter(string $id, int $unreadCounter): void {

public function get(string $id): ?array {
$this->init();
foreach ($this->closureEntries as $c) {
$this->add($c());
}
$this->closureEntries = [];

return $this->entries[$id];
}

Expand Down
5 changes: 5 additions & 0 deletions lib/private/URLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ public function linkToDefaultPageUrl(): string {
if ($href === '') {
throw new \InvalidArgumentException('Default navigation entry is missing href: ' . $entryId);
}

if (str_starts_with($href, $this->getBaseUrl())) {
return $href;
}

if (str_starts_with($href, '/index.php/') && ($this->config->getSystemValueBool('htaccess.IgnoreFrontController', false) || getenv('front_controller_active') === 'true')) {
$href = substr($href, 10);
}
Expand Down
40 changes: 37 additions & 3 deletions tests/lib/NavigationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,30 +704,64 @@ public static function provideDefaultEntries(): array {
true,
'settings',
],
// closure navigation entries are also resolved
[
'closure2',
'',
'',
true,
'closure2',
],
[
'',
'closure2',
'',
true,
'closure2',
],
[
'',
'',
'{"closure2":{"order":1,"app":"closure2","href":"/closure2"}}',
true,
'closure2',
],
];
}

/**
* @dataProvider provideDefaultEntries
*/
public function testGetDefaultEntryIdForUser($defaultApps, $userDefaultApps, $userApporder, $withFallbacks, $expectedApp): void {
public function testGetDefaultEntryIdForUser(string $defaultApps, string $userDefaultApps, string $userApporder, bool $withFallbacks, string $expectedApp): void {
$this->navigationManager->add([
'id' => 'files',
]);
$this->navigationManager->add([
'id' => 'settings',
]);
$this->navigationManager->add(static function (): array {
return [
'id' => 'closure1',
'href' => '/closure1',
];
});
$this->navigationManager->add(static function (): array {
return [
'id' => 'closure2',
'href' => '/closure2',
];
});

$this->appManager->method('getEnabledApps')->willReturn([]);

$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user1');

$this->userSession->expects($this->once())
$this->userSession->expects($this->atLeastOnce())
->method('getUser')
->willReturn($user);

$this->config->expects($this->once())
$this->config->expects($this->atLeastOnce())
->method('getSystemValueString')
->with('defaultapp', $this->anything())
->willReturn($defaultApps);
Expand Down
Loading