Skip to content

Commit

Permalink
Merge pull request #49904 from nextcloud/enh/noid/navigationentryevent
Browse files Browse the repository at this point in the history
feat(Navigation): emit dedicated event for loading additional entries
  • Loading branch information
blizzz authored Dec 18, 2024
2 parents db683da + 13fefc4 commit d2923aa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/files/lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use OC\NavigationManager;
use OCA\Files\Service\ChunkedUploadConfig;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\INavigationManager;
Expand All @@ -36,6 +37,7 @@ public static function getNavigationManager(): INavigationManager {
Server::get(IGroupManager::class),
Server::get(IConfig::class),
Server::get(LoggerInterface::class),
Server::get(IEventDispatcher::class),
);
self::$navigationManager->clear(false);
}
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php',
'OCP\\Migration\\SimpleMigrationStep' => $baseDir . '/lib/public/Migration/SimpleMigrationStep.php',
'OCP\\Navigation\\Events\\LoadAdditionalEntriesEvent' => $baseDir . '/lib/public/Navigation/Events/LoadAdditionalEntriesEvent.php',
'OCP\\Notification\\AlreadyProcessedException' => $baseDir . '/lib/public/Notification/AlreadyProcessedException.php',
'OCP\\Notification\\IAction' => $baseDir . '/lib/public/Notification/IAction.php',
'OCP\\Notification\\IApp' => $baseDir . '/lib/public/Notification/IApp.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php',
'OCP\\Migration\\SimpleMigrationStep' => __DIR__ . '/../../..' . '/lib/public/Migration/SimpleMigrationStep.php',
'OCP\\Navigation\\Events\\LoadAdditionalEntriesEvent' => __DIR__ . '/../../..' . '/lib/public/Navigation/Events/LoadAdditionalEntriesEvent.php',
'OCP\\Notification\\AlreadyProcessedException' => __DIR__ . '/../../..' . '/lib/public/Notification/AlreadyProcessedException.php',
'OCP\\Notification\\IAction' => __DIR__ . '/../../..' . '/lib/public/Notification/IAction.php',
'OCP\\Notification\\IApp' => __DIR__ . '/../../..' . '/lib/public/Notification/IApp.php',
Expand Down
4 changes: 4 additions & 0 deletions lib/private/NavigationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use OC\App\AppManager;
use OC\Group\Manager;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -56,6 +58,7 @@ public function __construct(
IGroupManager $groupManager,
IConfig $config,
LoggerInterface $logger,
protected IEventDispatcher $eventDispatcher,
) {
$this->appManager = $appManager;
$this->urlGenerator = $urlGenerator;
Expand Down Expand Up @@ -318,6 +321,7 @@ private function init() {
]);
}
}
$this->eventDispatcher->dispatchTyped(new LoadAdditionalEntriesEvent());

if ($this->userSession->isLoggedIn()) {
$user = $this->userSession->getUser();
Expand Down
17 changes: 17 additions & 0 deletions lib/public/Navigation/Events/LoadAdditionalEntriesEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Navigation\Events;

use OCP\EventDispatcher\Event;

/**
* @since 31.0.0
*/
class LoadAdditionalEntriesEvent extends Event {
}
17 changes: 17 additions & 0 deletions tests/lib/NavigationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;

class NavigationManagerTest extends TestCase {
Expand All @@ -34,6 +37,8 @@ class NavigationManagerTest extends TestCase {
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $config;

protected IEVentDispatcher|MockObject $dispatcher;

/** @var \OC\NavigationManager */
protected $navigationManager;
protected LoggerInterface $logger;
Expand All @@ -48,6 +53,7 @@ protected function setUp(): void {
$this->groupManager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->navigationManager = new NavigationManager(
$this->appManager,
$this->urlGenerator,
Expand All @@ -56,6 +62,7 @@ protected function setUp(): void {
$this->groupManager,
$this->config,
$this->logger,
$this->dispatcher,
);

$this->navigationManager->clear(false);
Expand Down Expand Up @@ -256,6 +263,11 @@ public function testWithAppManager($expected, $navigation, $isAdmin = false): vo
$this->groupManager->expects($this->any())->method('getSubAdmin')->willReturn($subadmin);

$this->navigationManager->clear();
$this->dispatcher->expects($this->once())
->method('dispatchTyped')
->willReturnCallback(function ($event) {
$this->assertInstanceOf(LoadAdditionalEntriesEvent::class, $event);
});
$entries = $this->navigationManager->getAll('all');
$this->assertEquals($expected, $entries);
}
Expand Down Expand Up @@ -558,6 +570,11 @@ function (string $userId, string $appName, string $key, mixed $default = '') use
$this->groupManager->expects($this->any())->method('getSubAdmin')->willReturn($subadmin);

$this->navigationManager->clear();
$this->dispatcher->expects($this->once())
->method('dispatchTyped')
->willReturnCallback(function ($event) {
$this->assertInstanceOf(LoadAdditionalEntriesEvent::class, $event);
});
$entries = $this->navigationManager->getAll();
$this->assertEquals($expected, $entries);
}
Expand Down

0 comments on commit d2923aa

Please sign in to comment.