Skip to content

Commit 3c33f5e

Browse files
Merge pull request #60961 from nextcloud/backport/60458/stable34
[stable34] refactor(NavigationManager): move navigation definitions into apps
2 parents e4805dc + f2eca7f commit 3c33f5e

14 files changed

Lines changed: 248 additions & 324 deletions

File tree

apps/appstore/appinfo/info.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@
1919
<dependencies>
2020
<nextcloud min-version="34" max-version="34"/>
2121
</dependencies>
22+
23+
<navigations>
24+
<navigation role="admin">
25+
<name>Appstore</name>
26+
<route>appstore.page.viewApps</route>
27+
<icon>app.svg</icon>
28+
<order>99</order>
29+
</navigation>
30+
31+
<navigation role="admin">
32+
<name>Apps</name>
33+
<route>appstore.page.viewApps</route>
34+
<icon>app.svg</icon>
35+
<order>5</order>
36+
<type>settings</type>
37+
</navigation>
38+
</navigations>
2239
</info>

apps/appstore/lib/Controller/PageController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use OCP\AppFramework\Services\IInitialState;
2424
use OCP\IConfig;
2525
use OCP\IL10N;
26-
use OCP\INavigationManager;
2726
use OCP\IRequest;
2827
use OCP\IURLGenerator;
2928
use OCP\Server;
@@ -41,7 +40,6 @@ public function __construct(
4140
private readonly IURLGenerator $urlGenerator,
4241
private readonly IInitialState $initialState,
4342
private readonly BundleFetcher $bundleFetcher,
44-
private readonly INavigationManager $navigationManager,
4543
) {
4644
parent::__construct(Application::APP_ID, $request);
4745
}
@@ -51,8 +49,6 @@ public function __construct(
5149
#[FrontpageRoute(verb: 'GET', url: '/settings/apps/{category}', defaults: ['category' => ''], root: '')]
5250
#[FrontpageRoute(verb: 'GET', url: '/settings/apps/{category}/{id}', defaults: ['category' => '', 'id' => ''], root: '')]
5351
public function viewApps(): TemplateResponse {
54-
$this->navigationManager->setActiveEntry('core_apps');
55-
5652
$this->initialState->provideInitialState('appstoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
5753
$this->initialState->provideInitialState('appstoreBundles', $this->getBundles());
5854
$this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual'));

apps/appstore/tests/Controller/PageControllerTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use OCP\AppFramework\Services\IInitialState;
1717
use OCP\IConfig;
1818
use OCP\IL10N;
19-
use OCP\INavigationManager;
2019
use OCP\IRequest;
2120
use OCP\IURLGenerator;
2221
use PHPUnit\Framework\MockObject\MockObject;
@@ -30,8 +29,6 @@ final class PageControllerTest extends TestCase {
3029

3130
private IConfig&MockObject $config;
3231

33-
private INavigationManager&MockObject $navigationManager;
34-
3532
private IAppManager&MockObject $appManager;
3633

3734
private BundleFetcher&MockObject $bundleFetcher;
@@ -54,7 +51,6 @@ protected function setUp(): void {
5451
->method('t')
5552
->willReturnArgument(0);
5653
$this->config = $this->createMock(IConfig::class);
57-
$this->navigationManager = $this->createMock(INavigationManager::class);
5854
$this->appManager = $this->createMock(IAppManager::class);
5955
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
6056
$this->installer = $this->createMock(Installer::class);
@@ -70,7 +66,6 @@ protected function setUp(): void {
7066
$this->urlGenerator,
7167
$this->initialState,
7268
$this->bundleFetcher,
73-
$this->navigationManager,
7469
);
7570
}
7671

@@ -84,10 +79,6 @@ public function testViewApps(): void {
8479
->method('getSystemValueBool')
8580
->with('appstoreenabled', true)
8681
->willReturn(true);
87-
$this->navigationManager
88-
->expects($this->once())
89-
->method('setActiveEntry')
90-
->with('core_apps');
9182

9283
$this->initialState
9384
->expects($this->exactly(4))
@@ -117,10 +108,6 @@ public function testViewAppsAppstoreNotEnabled(): void {
117108
->method('getSystemValueBool')
118109
->with('appstoreenabled', true)
119110
->willReturn(false);
120-
$this->navigationManager
121-
->expects($this->once())
122-
->method('setActiveEntry')
123-
->with('core_apps');
124111

125112
$this->initialState
126113
->expects($this->exactly(4))

apps/profile/lib/AppInfo/Application.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
use OCP\AppFramework\Bootstrap\IRegistrationContext;
1818
use OCP\Collaboration\Reference\RenderReferenceEvent;
19+
use OCP\INavigationManager;
20+
use OCP\IURLGenerator;
21+
use OCP\IUserSession;
22+
use OCP\L10N\IFactory;
23+
use OCP\Server;
1924

2025
class Application extends App implements IBootstrap {
2126
public const APP_ID = 'profile';
@@ -32,5 +37,33 @@ public function register(IRegistrationContext $context): void {
3237

3338
#[\Override]
3439
public function boot(IBootContext $context): void {
40+
$context->injectFn($this->registerNavigationEntry(...));
41+
}
42+
43+
/**
44+
* Registers the navigation entry for the profile app in the user settings.
45+
* Needed as the href is dynamic and thus we cannot use the appinfo/info.xml
46+
*/
47+
public function registerNavigationEntry(
48+
INavigationManager $navigationManager,
49+
IUserSession $userSession,
50+
IURLGenerator $urlGenerator,
51+
): void {
52+
if (!$userSession->isLoggedIn()) {
53+
return;
54+
}
55+
56+
$l = Server::get(IFactory::class)->get('profile');
57+
// Profile
58+
$navigationManager->add([
59+
'type' => 'settings',
60+
'id' => 'profile',
61+
'order' => 1,
62+
'href' => $urlGenerator->linkToRoute(
63+
'profile.ProfilePage.index',
64+
['targetUserId' => $userSession->getUser()->getUID()],
65+
),
66+
'name' => $l->t('View profile'),
67+
]);
3568
}
3669
}

apps/settings/appinfo/info.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,5 @@
7474
<provider>OCA\Settings\Activity\Provider</provider>
7575
<provider>OCA\Settings\Activity\SecurityProvider</provider>
7676
</providers>
77-
7877
</activity>
7978
</info>

apps/settings/appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET' , 'root' => ''],
3434
['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET' , 'root' => ''],
3535
['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info'] , 'root' => ''],
36-
['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server'] , 'root' => ''],
36+
['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'overview'] , 'root' => ''],
3737
['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET' , 'root' => ''],
3838
['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST' , 'root' => ''],
3939
['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST' , 'root' => ''],

apps/settings/lib/AppInfo/Application.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@
9090
use OCP\Group\Events\GroupDeletedEvent;
9191
use OCP\Group\Events\UserAddedEvent;
9292
use OCP\Group\Events\UserRemovedEvent;
93+
use OCP\Group\ISubAdmin;
9394
use OCP\IConfig;
95+
use OCP\IGroupManager;
96+
use OCP\INavigationManager;
9497
use OCP\IURLGenerator;
98+
use OCP\IUserSession;
9599
use OCP\L10N\IFactory;
96100
use OCP\Mail\IMailer;
97101
use OCP\Security\ICrypto;
@@ -226,5 +230,93 @@ public function register(IRegistrationContext $context): void {
226230

227231
#[\Override]
228232
public function boot(IBootContext $context): void {
233+
$context->injectFn($this->registerNavigationEntries(...));
234+
}
235+
236+
/**
237+
* Registers the navigation entries for the user settings.
238+
* Needed as some entries are dynamic and thus we cannot use the appinfo/info.xml
239+
*
240+
* Registers the following entries:
241+
* - Appearance and accessibility
242+
* - Personal settings (named "Settings" for non-admins)
243+
* - Accounts (only for subadmins)
244+
* - Help & privacy (conditionally enabled based on config)
245+
*/
246+
public function registerNavigationEntries(
247+
INavigationManager $navigationManager,
248+
IURLGenerator $urlGenerator,
249+
IUserSession $userSession,
250+
IConfig $config,
251+
): void {
252+
if ($userSession->getUser() === null) {
253+
return;
254+
}
255+
256+
$l = Server::get(IFactory::class)
257+
->get('settings');
258+
$groupManager = Server::get(IGroupManager::class);
259+
$subAdmin = Server::get(ISubAdmin::class);
260+
$isAdmin = $groupManager->isAdmin($userSession->getUser()->getUID());
261+
$isSubAdmin = $subAdmin->isSubAdmin($userSession->getUser());
262+
263+
// Accessibility settings - the URL is dynamic (route parameters) which is currently not supported by appinfo.xml
264+
$navigationManager->add([
265+
'type' => 'settings',
266+
'id' => 'accessibility_settings',
267+
'order' => 2,
268+
'href' => $urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']),
269+
'name' => $l->t('Appearance and accessibility'),
270+
'icon' => $urlGenerator->imagePath('theming', 'accessibility-dark.svg'),
271+
]);
272+
273+
// Personal settings - this entry is dynamic so we cannot use appinfo
274+
$navigationManager->add([
275+
'type' => 'settings',
276+
'id' => 'settings_personal',
277+
'order' => 3,
278+
'href' => $urlGenerator->linkToRoute('settings.PersonalSettings.index'),
279+
'name' => $isAdmin
280+
? $l->t('Personal settings')
281+
: $l->t('Settings'),
282+
'icon' => $isAdmin
283+
? $urlGenerator->imagePath('settings', 'personal.svg')
284+
: $urlGenerator->imagePath('settings', 'admin.svg'),
285+
]);
286+
287+
if ($isAdmin) {
288+
$navigationManager->add([
289+
'type' => 'settings',
290+
'id' => 'settings_administration',
291+
'order' => 4,
292+
'href' => $urlGenerator->linkToRoute('settings.adminSettings.index'),
293+
'name' => $l->t('Administration settings'),
294+
'icon' => $urlGenerator->imagePath('settings', 'admin.svg'),
295+
]);
296+
}
297+
298+
// User management is conditionally enabled for subadmins, but appinfo currently only supports full admins
299+
if ($isSubAdmin) {
300+
$navigationManager->add([
301+
'type' => 'settings',
302+
'id' => 'core_users',
303+
'order' => 6,
304+
'href' => $urlGenerator->linkToRoute('settings.Users.usersList'),
305+
'name' => $l->t('Accounts'),
306+
'icon' => $urlGenerator->imagePath('settings', 'users.svg'),
307+
]);
308+
}
309+
310+
// conditionally enabled navigation entry
311+
if ($config->getSystemValueBool('knowledgebaseenabled', true)) {
312+
$navigationManager->add([
313+
'type' => 'settings',
314+
'id' => 'help',
315+
'order' => 99998,
316+
'href' => $urlGenerator->linkToRoute('settings.Help.help'),
317+
'name' => $l->t('Help & privacy'),
318+
'icon' => $urlGenerator->imagePath('settings', 'help.svg'),
319+
]);
320+
}
229321
}
230322
}

core/AppInfo/Application.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
3333
use OCP\DB\Events\AddMissingIndicesEvent;
3434
use OCP\DB\Events\AddMissingPrimaryKeyEvent;
35+
use OCP\INavigationManager;
36+
use OCP\IURLGenerator;
37+
use OCP\IUserSession;
38+
use OCP\L10N\IFactory;
39+
use OCP\Server;
3540
use OCP\User\Events\BeforeUserDeletedEvent;
3641
use OCP\User\Events\PasswordUpdatedEvent;
3742
use OCP\User\Events\UserDeletedEvent;
@@ -93,7 +98,36 @@ public function register(IRegistrationContext $context): void {
9398

9499
#[\Override]
95100
public function boot(IBootContext $context): void {
96-
// ...
101+
$context->injectFn($this->registerNavigationEntries(...));
102+
}
103+
104+
/**
105+
* Registers the navigation entries for the core app:
106+
* - The logout button in the settings menu
107+
*/
108+
public function registerNavigationEntries(
109+
INavigationManager $navigationManager,
110+
IUserSession $userSession,
111+
IURLGenerator $urlGenerator,
112+
): void {
113+
if (!$userSession->isLoggedIn()) {
114+
return;
115+
}
116+
117+
$l = Server::get(IFactory::class)->get('core');
118+
119+
// Register the logout button in the user settings
120+
$logoutUrl = \OC_User::getLogoutUrl($urlGenerator);
121+
if ($logoutUrl !== '') {
122+
$navigationManager->add([
123+
'type' => 'settings',
124+
'id' => 'logout',
125+
'order' => 99999,
126+
'href' => $logoutUrl,
127+
'name' => $l->t('Log out'),
128+
'icon' => $urlGenerator->imagePath('core', 'actions/logout.svg'),
129+
]);
130+
}
97131
}
98132

99133
}

cypress/e2e/systemtags/admin-settings.cy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Create system tags', () => {
2121

2222
// login as admin and go to admin settings
2323
cy.login(admin)
24-
cy.visit('/settings/admin')
24+
cy.visit('/settings/admin/server')
2525
})
2626

2727
it('Can create a tag', () => {
@@ -48,7 +48,7 @@ describe('Create system tags', () => {
4848
describe('Update system tags', { testIsolation: false }, () => {
4949
before(() => {
5050
cy.login(admin)
51-
cy.visit('/settings/admin')
51+
cy.visit('/settings/admin/server')
5252
})
5353

5454
it('select the tag', () => {
@@ -92,7 +92,7 @@ describe('Update system tags', { testIsolation: false }, () => {
9292
describe('Delete system tags', { testIsolation: false }, () => {
9393
before(() => {
9494
cy.login(admin)
95-
cy.visit('/settings/admin')
95+
cy.visit('/settings/admin/server')
9696
})
9797

9898
it('select the tag', () => {

cypress/e2e/theming/admin-settings_branding.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('Admin theming: Change the login fields then reset them', function() {
154154

155155
it('See the admin theming section', function() {
156156
cy.visit('/settings/admin/theming')
157-
cy.findByRole('heading', { name: /^Theming/ })
157+
cy.findByRole('heading', { name: /^Theming/, level: 2 })
158158
.should('exist')
159159
.scrollIntoView()
160160
})

0 commit comments

Comments
 (0)