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="35" max-version="35"/>
</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'),
]);
}
}
12 changes: 11 additions & 1 deletion apps/settings/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
<provider>OCA\Settings\Activity\Provider</provider>
<provider>OCA\Settings\Activity\SecurityProvider</provider>
</providers>

</activity>

<navigations>
<!-- Personal settings depends on if the user is also an admin, so that entry is dynamically registered in Application.php -->
<navigation role="admin">
<name>Administration settings</name>
<route>settings.AdminSettings.index</route>
<icon>admin.svg</icon>
<order>4</order>
<type>settings</type>
</navigation>
</navigations>
</info>
80 changes: 80 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
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 +229,82 @@ 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);
$isAdmin = $groupManager->isAdmin($userSession->getUser()->getUID());

// 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'),
]);

// User management is conditionally enabled for subadmins, but appinfo currently only supports full admins
/** @var \OC\Group\Manager $groupManager */
$isSubAdmin = $groupManager->getSubAdmin()->isSubAdmin($userSession->getUser());
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'),
]);
}
}

}
Loading
Loading