Browse Source

feat(Navigation): emit dedicated event for loading additional entries

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
pull/49904/head
Arthur Schiwon 10 months ago
parent
commit
13fefc4612
No known key found for this signature in database GPG Key ID: 7424F1874854DF23
  1. 2
      apps/files/lib/App.php
  2. 1
      lib/composer/composer/autoload_classmap.php
  3. 1
      lib/composer/composer/autoload_static.php
  4. 4
      lib/private/NavigationManager.php
  5. 17
      lib/public/Navigation/Events/LoadAdditionalEntriesEvent.php
  6. 17
      tests/lib/NavigationManagerTest.php

2
apps/files/lib/App.php

@ -10,6 +10,7 @@ namespace OCA\Files;
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;
@ -36,6 +37,7 @@ class App {
Server::get(IGroupManager::class),
Server::get(IConfig::class),
Server::get(LoggerInterface::class),
Server::get(IEventDispatcher::class),
);
self::$navigationManager->clear(false);
}

1
lib/composer/composer/autoload_classmap.php

@ -640,6 +640,7 @@ return array(
'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',

1
lib/composer/composer/autoload_static.php

@ -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',

4
lib/private/NavigationManager.php

@ -11,6 +11,7 @@ use InvalidArgumentException;
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;
@ -18,6 +19,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
use Psr\Log\LoggerInterface;
/**
@ -56,6 +58,7 @@ class NavigationManager implements INavigationManager {
IGroupManager $groupManager,
IConfig $config,
LoggerInterface $logger,
protected IEventDispatcher $eventDispatcher,
) {
$this->appManager = $appManager;
$this->urlGenerator = $urlGenerator;
@ -318,6 +321,7 @@ class NavigationManager implements INavigationManager {
]);
}
}
$this->eventDispatcher->dispatchTyped(new LoadAdditionalEntriesEvent());
if ($this->userSession->isLoggedIn()) {
$user = $this->userSession->getUser();

17
lib/public/Navigation/Events/LoadAdditionalEntriesEvent.php

@ -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
tests/lib/NavigationManagerTest.php

@ -11,6 +11,7 @@ use OC\App\AppManager;
use OC\Group\Manager;
use OC\NavigationManager;
use OC\SubAdmin;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
@ -18,6 +19,8 @@ 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 {
@ -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;
@ -48,6 +53,7 @@ class NavigationManagerTest extends TestCase {
$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,
@ -56,6 +62,7 @@ class NavigationManagerTest extends TestCase {
$this->groupManager,
$this->config,
$this->logger,
$this->dispatcher,
);
$this->navigationManager->clear(false);
@ -256,6 +263,11 @@ class NavigationManagerTest extends TestCase {
$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);
}
@ -558,6 +570,11 @@ class NavigationManagerTest extends TestCase {
$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);
}

Loading…
Cancel
Save