load widgets only of enabled apps

- per design, all enabled apps have their registration run
- limitations, e.g. enabled by group, are not considered in that state,
  because we do not have a session (and might need apps?)
- before instantiation of widget it has to be checked whether the providing
  app is actually enabled for the logged in user.
- a public interface is being changed, but it is not meant to be
  implemented or used outside of the core handling. Therefore save to
  backport.

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
pull/32980/head
Arthur Schiwon 2 years ago
parent b282fe1e6f
commit 523572fcea
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
  1. 2
      lib/private/AppFramework/Bootstrap/Coordinator.php
  2. 4
      lib/private/AppFramework/Bootstrap/RegistrationContext.php
  3. 33
      lib/private/Dashboard/Manager.php
  4. 2
      lib/public/Dashboard/IManager.php

@ -151,7 +151,7 @@ class Coordinator {
*/ */
$this->registrationContext->delegateCapabilityRegistrations($apps); $this->registrationContext->delegateCapabilityRegistrations($apps);
$this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry);
$this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager); $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager);
$this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher);
$this->registrationContext->delegateContainerRegistrations($apps); $this->registrationContext->delegateContainerRegistrations($apps);
$this->registrationContext->delegateMiddlewareRegistrations($apps); $this->registrationContext->delegateMiddlewareRegistrations($apps);

@ -475,10 +475,10 @@ class RegistrationContext {
/** /**
* @param App[] $apps * @param App[] $apps
*/ */
public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void {
while (($panel = array_shift($this->dashboardPanels)) !== null) { while (($panel = array_shift($this->dashboardPanels)) !== null) {
try { try {
$dashboardManager->lazyRegisterWidget($panel->getService()); $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId());
} catch (Throwable $e) { } catch (Throwable $e) {
$appId = $panel->getAppId(); $appId = $panel->getAppId();
$this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [ $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [

@ -27,10 +27,11 @@ declare(strict_types=1);
namespace OC\Dashboard; namespace OC\Dashboard;
use InvalidArgumentException; use InvalidArgumentException;
use OCP\AppFramework\QueryException; use OCP\App\IAppManager;
use OCP\Dashboard\IManager; use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget; use OCP\Dashboard\IWidget;
use OCP\IServerContainer; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Throwable; use Throwable;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -42,11 +43,12 @@ class Manager implements IManager {
/** @var IWidget[] */ /** @var IWidget[] */
private $widgets = []; private $widgets = [];
/** @var IServerContainer */ private ContainerInterface $serverContainer;
private $serverContainer; private IAppManager $appManager;
public function __construct(IServerContainer $serverContainer) { public function __construct(ContainerInterface $serverContainer, IAppManager $appManager) {
$this->serverContainer = $serverContainer; $this->serverContainer = $serverContainer;
$this->appManager = $appManager;
} }
private function registerWidget(IWidget $widget): void { private function registerWidget(IWidget $widget): void {
@ -57,17 +59,22 @@ class Manager implements IManager {
$this->widgets[$widget->getId()] = $widget; $this->widgets[$widget->getId()] = $widget;
} }
public function lazyRegisterWidget(string $widgetClass): void { public function lazyRegisterWidget(string $widgetClass, string $appId): void {
$this->lazyWidgets[] = $widgetClass; $this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId];
} }
public function loadLazyPanels(): void { public function loadLazyPanels(): void {
$classes = $this->lazyWidgets; $services = $this->lazyWidgets;
foreach ($classes as $class) { foreach ($services as $service) {
/** @psalm-suppress InvalidCatch */
try { try {
if (!$this->appManager->isEnabledForUser($service['appId'])) {
// all apps are registered, but some may not be enabled for the user
continue;
}
/** @var IWidget $widget */ /** @var IWidget $widget */
$widget = $this->serverContainer->query($class); $widget = $this->serverContainer->get($service['class']);
} catch (QueryException $e) { } catch (ContainerExceptionInterface $e) {
/* /*
* There is a circular dependency between the logger and the registry, so * There is a circular dependency between the logger and the registry, so
* we can not inject it. Thus the static call. * we can not inject it. Thus the static call.
@ -90,7 +97,7 @@ class Manager implements IManager {
*/ */
\OC::$server->get(LoggerInterface::class)->critical( \OC::$server->get(LoggerInterface::class)->critical(
'Could not register lazy dashboard widget: ' . $e->getMessage(), 'Could not register lazy dashboard widget: ' . $e->getMessage(),
['excepiton' => $e] ['exception' => $e]
); );
} }
@ -111,7 +118,7 @@ class Manager implements IManager {
} catch (Throwable $e) { } catch (Throwable $e) {
\OC::$server->get(LoggerInterface::class)->critical( \OC::$server->get(LoggerInterface::class)->critical(
'Error during dashboard widget loading: ' . $e->getMessage(), 'Error during dashboard widget loading: ' . $e->getMessage(),
['excepiton' => $e] ['exception' => $e]
); );
} }
} }

@ -36,7 +36,7 @@ interface IManager {
* @param string $widgetClass * @param string $widgetClass
* @since 20.0.0 * @since 20.0.0
*/ */
public function lazyRegisterWidget(string $widgetClass): void; public function lazyRegisterWidget(string $widgetClass, string $appId): void;
/** /**
* @since 20.0.0 * @since 20.0.0

Loading…
Cancel
Save