Skip to content
Open
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
17 changes: 17 additions & 0 deletions apps/appstore/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,21 @@
<dependencies>
<nextcloud min-version="34" max-version="34"/>
</dependencies>

<navigations>
<navigation role="admin">
<name>Appstore</name>
<route>appstore.page.viewApps</route>
<icon>app.svg</icon>
<order>99</order>
</navigation>

<navigation role="admin">
<name>Apps</name>
<route>appstore.page.viewApps</route>
<icon>app.svg</icon>
<order>5</order>
<type>settings</type>
</navigation>
</navigations>
</info>
4 changes: 0 additions & 4 deletions apps/appstore/lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Server;
Expand All @@ -41,7 +40,6 @@ public function __construct(
private readonly IURLGenerator $urlGenerator,
private readonly IInitialState $initialState,
private readonly BundleFetcher $bundleFetcher,
private readonly INavigationManager $navigationManager,
) {
parent::__construct(Application::APP_ID, $request);
}
Expand All @@ -51,8 +49,6 @@ public function __construct(
#[FrontpageRoute(verb: 'GET', url: '/settings/apps/{category}', defaults: ['category' => ''], root: '')]
#[FrontpageRoute(verb: 'GET', url: '/settings/apps/{category}/{id}', defaults: ['category' => '', 'id' => ''], root: '')]
public function viewApps(): TemplateResponse {
$this->navigationManager->setActiveEntry('core_apps');

$this->initialState->provideInitialState('appstoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
$this->initialState->provideInitialState('appstoreBundles', $this->getBundles());
$this->initialState->provideInitialState('appstoreDeveloperDocs', $this->urlGenerator->linkToDocs('developer-manual'));
Expand Down
13 changes: 0 additions & 13 deletions apps/appstore/tests/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -30,8 +29,6 @@ final class PageControllerTest extends TestCase {

private IConfig&MockObject $config;

private INavigationManager&MockObject $navigationManager;

private IAppManager&MockObject $appManager;

private BundleFetcher&MockObject $bundleFetcher;
Expand All @@ -54,7 +51,6 @@ protected function setUp(): void {
->method('t')
->willReturnArgument(0);
$this->config = $this->createMock(IConfig::class);
$this->navigationManager = $this->createMock(INavigationManager::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
$this->installer = $this->createMock(Installer::class);
Expand All @@ -70,7 +66,6 @@ protected function setUp(): void {
$this->urlGenerator,
$this->initialState,
$this->bundleFetcher,
$this->navigationManager,
);
}

Expand All @@ -84,10 +79,6 @@ public function testViewApps(): void {
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);
$this->navigationManager
->expects($this->once())
->method('setActiveEntry')
->with('core_apps');

$this->initialState
->expects($this->exactly(4))
Expand Down Expand Up @@ -117,10 +108,6 @@ public function testViewAppsAppstoreNotEnabled(): void {
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(false);
$this->navigationManager
->expects($this->once())
->method('setActiveEntry')
->with('core_apps');

$this->initialState
->expects($this->exactly(4))
Expand Down
33 changes: 33 additions & 0 deletions apps/profile/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Server;

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

#[\Override]
public function boot(IBootContext $context): void {
$context->injectFn($this->registerNavigationEntry(...));
}

/**
* Registers the navigation entry for the profile app in the user settings.
* Needed as the href is dynamic and thus we cannot use the appinfo/info.xml
*/
public function registerNavigationEntry(
INavigationManager $navigationManager,
IUserSession $userSession,
IURLGenerator $urlGenerator,
): void {
if (!$userSession->isLoggedIn()) {
return;
}

$l = Server::get(IFactory::class)->get('profile');
// Profile
$navigationManager->add([
'type' => 'settings',
'id' => 'profile',
'order' => 1,
'href' => $urlGenerator->linkToRoute(
'profile.ProfilePage.index',
['targetUserId' => $userSession->getUser()->getUID()],
),
'name' => $l->t('View profile'),
]);
}
}
1 change: 0 additions & 1 deletion apps/settings/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,5 @@
<provider>OCA\Settings\Activity\Provider</provider>
<provider>OCA\Settings\Activity\SecurityProvider</provider>
</providers>

</activity>
</info>
2 changes: 1 addition & 1 deletion apps/settings/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET' , 'root' => ''],
['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET' , 'root' => ''],
['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info'] , 'root' => ''],
['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server'] , 'root' => ''],
['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'overview'] , 'root' => ''],
['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET' , 'root' => ''],
['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST' , 'root' => ''],
['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST' , 'root' => ''],
Expand Down
92 changes: 92 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Group\ISubAdmin;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OCP\Security\ICrypto;
Expand Down Expand Up @@ -226,5 +230,93 @@ public function register(IRegistrationContext $context): void {

#[\Override]
public function boot(IBootContext $context): void {
$context->injectFn($this->registerNavigationEntries(...));
}

/**
* Registers the navigation entries for the user settings.
* Needed as some entries are dynamic and thus we cannot use the appinfo/info.xml
*
* Registers the following entries:
* - Appearance and accessibility
* - Personal settings (named "Settings" for non-admins)
* - Accounts (only for subadmins)
* - Help & privacy (conditionally enabled based on config)
*/
public function registerNavigationEntries(
INavigationManager $navigationManager,
IURLGenerator $urlGenerator,
IUserSession $userSession,
IConfig $config,
): void {
if ($userSession->getUser() === null) {
return;
}

$l = Server::get(IFactory::class)
->get('settings');
$groupManager = Server::get(IGroupManager::class);
$subAdmin = Server::get(ISubAdmin::class);
$isAdmin = $groupManager->isAdmin($userSession->getUser()->getUID());
$isSubAdmin = $subAdmin->isSubAdmin($userSession->getUser());

// Accessibility settings - the URL is dynamic (route parameters) which is currently not supported by appinfo.xml
$navigationManager->add([
'type' => 'settings',
'id' => 'accessibility_settings',
'order' => 2,
'href' => $urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']),
'name' => $l->t('Appearance and accessibility'),
'icon' => $urlGenerator->imagePath('theming', 'accessibility-dark.svg'),
]);

// Personal settings - this entry is dynamic so we cannot use appinfo
$navigationManager->add([
'type' => 'settings',
'id' => 'settings_personal',
'order' => 3,
'href' => $urlGenerator->linkToRoute('settings.PersonalSettings.index'),
'name' => $isAdmin
? $l->t('Personal settings')
: $l->t('Settings'),
'icon' => $isAdmin
? $urlGenerator->imagePath('settings', 'personal.svg')
: $urlGenerator->imagePath('settings', 'admin.svg'),
]);

if ($isAdmin) {
$navigationManager->add([
'type' => 'settings',
'id' => 'settings_administration',
'order' => 4,
'href' => $urlGenerator->linkToRoute('settings.adminSettings.index'),
'name' => $l->t('Administration settings'),
'icon' => $urlGenerator->imagePath('settings', 'admin.svg'),
]);
}

// User management is conditionally enabled for subadmins, but appinfo currently only supports full admins
if ($isSubAdmin) {
$navigationManager->add([
'type' => 'settings',
'id' => 'core_users',
'order' => 6,
'href' => $urlGenerator->linkToRoute('settings.Users.usersList'),
'name' => $l->t('Accounts'),
'icon' => $urlGenerator->imagePath('settings', 'users.svg'),
]);
}

// conditionally enabled navigation entry
if ($config->getSystemValueBool('knowledgebaseenabled', true)) {
$navigationManager->add([
'type' => 'settings',
'id' => 'help',
'order' => 99998,
'href' => $urlGenerator->linkToRoute('settings.Help.help'),
'name' => $l->t('Help & privacy'),
'icon' => $urlGenerator->imagePath('settings', 'help.svg'),
]);
}
}
}
36 changes: 35 additions & 1 deletion core/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\DB\Events\AddMissingPrimaryKeyEvent;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Server;
use OCP\User\Events\BeforeUserDeletedEvent;
use OCP\User\Events\PasswordUpdatedEvent;
use OCP\User\Events\UserDeletedEvent;
Expand Down Expand Up @@ -93,7 +98,36 @@ public function register(IRegistrationContext $context): void {

#[\Override]
public function boot(IBootContext $context): void {
// ...
$context->injectFn($this->registerNavigationEntries(...));
}

/**
* Registers the navigation entries for the core app:
* - The logout button in the settings menu
*/
public function registerNavigationEntries(
INavigationManager $navigationManager,
IUserSession $userSession,
IURLGenerator $urlGenerator,
): void {
if (!$userSession->isLoggedIn()) {
return;
}

$l = Server::get(IFactory::class)->get('core');

// Register the logout button in the user settings
$logoutUrl = \OC_User::getLogoutUrl($urlGenerator);
if ($logoutUrl !== '') {
$navigationManager->add([
'type' => 'settings',
'id' => 'logout',
'order' => 99999,
'href' => $logoutUrl,
'name' => $l->t('Log out'),
'icon' => $urlGenerator->imagePath('core', 'actions/logout.svg'),
]);
}
}

}
47 changes: 40 additions & 7 deletions cypress/e2e/core/header_app-menu.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ const getAppMenu = () => getNextcloudHeader().find('.app-menu')
// the next-best stable selectors.
const getWaffleTrigger = () => getAppMenu().find('.app-menu__waffle')

describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
beforeEach(() => {
clearState()
})
before(clearState)

describe('Open and click', () => {
describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
describe('Normal user', () => {
beforeEach(() => {
cy.createRandomUser().then(($user) => {
cy.login($user)
cy.visit('/')
})
})

it('opens the popover and navigates when a tile is clicked', () => {
it('Open and click opens the popover and navigates when a tile is clicked', () => {
getWaffleTrigger().click()
cy.get('.app-menu__popover').should('be.visible')
getWaffleTrigger().should('have.attr', 'aria-expanded', 'true')
Expand All @@ -39,9 +37,16 @@ describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
cy.location('pathname').should('include', '/apps/')
})
})

it('has all correct app navigation items', () => {
waffleMenuShouldContainApps([
{ name: 'Files', href: '/apps/files' },
{ name: 'Dashboard', href: '/apps/dashboard' },
])
})
})

describe('Admin gating: "More apps" tile', () => {
describe('Admin', () => {
const admin = new User('admin', 'admin')

beforeEach(() => {
Expand All @@ -54,5 +59,33 @@ describe('Header: App menu (waffle launcher)', { testIsolation: true }, () => {
cy.get('.app-menu__popover').should('be.visible')
cy.findByRole('menuitem', { name: 'More apps' }).should('be.visible')
})

it('has all correct app navigation items', () => {
waffleMenuShouldContainApps([
{ name: 'Files', href: '/apps/files' },
{ name: 'Dashboard', href: '/apps/dashboard' },
{ name: 'Appstore', href: '/settings/apps' },
])
})
})
})

/**
* Check that the waffle menu contains the given apps, by name and href.
*
* @param apps - The apps that should be present in the waffle menu, with their expected name and href.
*/
function waffleMenuShouldContainApps(apps: { name: string, href: string }[]) {
getWaffleTrigger().click()
getWaffleTrigger().should('have.attr', 'aria-expanded', 'true')
cy.findByRole('menu', { name: 'Apps' }).should('be.visible')

cy.findAllByRole('menuitem')
.then((items) => {
apps.forEach((app) => {
const item = items.toArray().find((i) => i.textContent?.includes(app.name))
expect(item, `App menu should contain ${app.name}`).to.exist
expect(item?.getAttribute('href')).to.match(new RegExp(`${app.href}(\\?.+|/?$)`))
})
})
}
Loading
Loading