]> source.dussan.org Git - nextcloud-server.git/commitdiff
load widgets only of enabled apps
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 22 Jun 2022 13:53:12 +0000 (15:53 +0200)
committerVincent Petry (Rebase PR Action) <PVince81@users.noreply.github.com>
Wed, 27 Jul 2022 15:11:50 +0000 (15:11 +0000)
- 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>
lib/private/AppFramework/Bootstrap/Coordinator.php
lib/private/AppFramework/Bootstrap/RegistrationContext.php
lib/private/Dashboard/Manager.php
lib/public/Dashboard/IManager.php

index 6e05b7fdc8802c5283e8330f7493d776553e66da..d68f9d507f12e3d5394f75a0e36ab15ce3891c5a 100644 (file)
@@ -143,7 +143,7 @@ class Coordinator {
                 */
                $this->registrationContext->delegateCapabilityRegistrations($apps);
                $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry);
-               $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager);
+               $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager);
                $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher);
                $this->registrationContext->delegateContainerRegistrations($apps);
                $this->registrationContext->delegateMiddlewareRegistrations($apps);
index 6a9073b576bccdc02a826e9821640b4fa2ba1d99..292d453d614904604a41339c781aa88450d59a64 100644 (file)
@@ -394,10 +394,10 @@ class RegistrationContext {
        /**
         * @param App[] $apps
         */
-       public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
+       public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void {
                while (($panel = array_shift($this->dashboardPanels)) !== null) {
                        try {
-                               $dashboardManager->lazyRegisterWidget($panel->getService());
+                               $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId());
                        } catch (Throwable $e) {
                                $appId = $panel->getAppId();
                                $this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [
index a77c389cdebb2fa5c80b81f1290b5035b7fd89fe..8c596f470fb378480d51b3b384f6e3d0d0b63d78 100644 (file)
@@ -27,7 +27,7 @@ declare(strict_types=1);
 namespace OC\Dashboard;
 
 use InvalidArgumentException;
-use OCP\AppFramework\QueryException;
+use OCP\App\IAppManager;
 use OCP\Dashboard\IManager;
 use OCP\Dashboard\IWidget;
 use OCP\ILogger;
@@ -42,11 +42,12 @@ class Manager implements IManager {
        /** @var IWidget[] */
        private $widgets = [];
 
-       /** @var IServerContainer */
-       private $serverContainer;
+       private ContainerInterface $serverContainer;
+       private IAppManager $appManager;
 
-       public function __construct(IServerContainer $serverContainer) {
+       public function __construct(ContainerInterface $serverContainer, IAppManager $appManager) {
                $this->serverContainer = $serverContainer;
+               $this->appManager = $appManager;
        }
 
        private function registerWidget(IWidget $widget): void {
@@ -57,17 +58,22 @@ class Manager implements IManager {
                $this->widgets[$widget->getId()] = $widget;
        }
 
-       public function lazyRegisterWidget(string $widgetClass): void {
-               $this->lazyWidgets[] = $widgetClass;
+       public function lazyRegisterWidget(string $widgetClass, string $appId): void {
+               $this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId];
        }
 
        public function loadLazyPanels(): void {
-               $classes = $this->lazyWidgets;
-               foreach ($classes as $class) {
+               $services = $this->lazyWidgets;
+               foreach ($services as $service) {
+                       /** @psalm-suppress InvalidCatch */
                        try {
+                               if (!$this->appManager->isEnabledForUser($service['appId'])) {
+                                       // all apps are registered, but some may not be enabled for the user
+                                       continue;
+                               }
                                /** @var IWidget $widget */
-                               $widget = $this->serverContainer->query($class);
-                       } catch (QueryException $e) {
+                               $widget = $this->serverContainer->get($service['class']);
+                       } catch (ContainerExceptionInterface $e) {
                                /*
                                 * There is a circular dependency between the logger and the registry, so
                                 * we can not inject it. Thus the static call.
index 396624876ef31dbc7b43cba5c515eec8fe5e22eb..d9e73c89eb971d6f336a03812cdb359811cb0d97 100644 (file)
@@ -36,7 +36,7 @@ interface IManager {
         * @param string $widgetClass
         * @since 20.0.0
         */
-       public function lazyRegisterWidget(string $widgetClass): void;
+       public function lazyRegisterWidget(string $widgetClass, string $appId): void;
 
        /**
         * @since 20.0.0