-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathFilteredNavigationManager.php
76 lines (58 loc) · 2.02 KB
/
FilteredNavigationManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Guests;
use OC\NavigationManager;
use OCP\IUser;
class FilteredNavigationManager extends NavigationManager {
/** @var AppWhitelist */
private $whitelist;
/** @var IUser */
private $user;
/** @var NavigationManager */
private $navigationManager;
public function __construct(IUser $user, NavigationManager $navigationManager, AppWhitelist $whitelist) {
$this->whitelist = $whitelist;
$this->user = $user;
$this->navigationManager = $navigationManager;
}
public function getAll(string $type = 'link'): array {
$items = $this->navigationManager->getAll($type);
return array_filter($items, [$this, 'isEntryWhitelisted']);
}
private function isEntryWhitelisted(array $item): bool {
return $this->whitelist->isUrlAllowed($this->user, $item['href']);
}
public function add($entry): void {
$this->navigationManager->add($entry);
}
public function clear($loadDefaultLinks = true): void {
$this->navigationManager->clear($loadDefaultLinks);
}
public function getActiveEntry(): string {
return $this->navigationManager->getActiveEntry();
}
public function setActiveEntry($appId): void {
$this->navigationManager->setActiveEntry($appId);
}
public function setUnreadCounter(string $id, int $unreadCounter): void {
$this->navigationManager->setUnreadCounter($id, $unreadCounter);
}
public function get(string $id): ?array {
return $this->navigationManager->get($id);
}
public function getDefaultEntryIdForUser(?IUser $user = null, bool $withFallbacks = true): string {
return $this->navigationManager->getDefaultEntryIdForUser($user, $withFallbacks);
}
public function getDefaultEntryIds(bool $withFallbacks = true): array {
return $this->navigationManager->getDefaultEntryIds($withFallbacks);
}
/**
* @psalm-suppress MethodSignatureMismatch
*/
public function setDefaultEntryIds(array $ids): void {
$this->navigationManager->setDefaultEntryIds($ids);
}
}