summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2022-06-23 17:45:05 +0200
committerGitHub <noreply@github.com>2022-06-23 17:45:05 +0200
commit3ebde2f6c2efdc490cf45266e72ff57e4653433c (patch)
tree0d723f28be06e8db089266702c63910567bbf2db /lib
parent253ae64fafc214c7fa5e06c3f7b0d5b1c017d79b (diff)
parent6e531b5ab5a29b40fb4ad555eb33374e0c89bdea (diff)
downloadnextcloud-server-3ebde2f6c2efdc490cf45266e72ff57e4653433c.tar.gz
nextcloud-server-3ebde2f6c2efdc490cf45266e72ff57e4653433c.zip
Merge pull request #32980 from nextcloud/fix/32887/dashboard-load-only-enabled-apps
load dashboard widgets of enabled apps only
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AppFramework/Bootstrap/Coordinator.php2
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php4
-rw-r--r--lib/private/Dashboard/Manager.php35
-rw-r--r--lib/public/Dashboard/IManager.php2
4 files changed, 26 insertions, 17 deletions
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php
index b6378830732..3ab6ac4c8b0 100644
--- a/lib/private/AppFramework/Bootstrap/Coordinator.php
+++ b/lib/private/AppFramework/Bootstrap/Coordinator.php
@@ -151,7 +151,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);
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 7b4d24036e8..8f6aff228e1 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -475,10 +475,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(), [
diff --git a/lib/private/Dashboard/Manager.php b/lib/private/Dashboard/Manager.php
index 09525693b4f..2aeedf3174e 100644
--- a/lib/private/Dashboard/Manager.php
+++ b/lib/private/Dashboard/Manager.php
@@ -27,10 +27,11 @@ 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\IServerContainer;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\ContainerInterface;
use Throwable;
use Psr\Log\LoggerInterface;
@@ -42,10 +43,10 @@ class Manager implements IManager {
/** @var IWidget[] */
private $widgets = [];
- /** @var IServerContainer */
- private $serverContainer;
+ private ContainerInterface $serverContainer;
+ private ?IAppManager $appManager = null;
- public function __construct(IServerContainer $serverContainer) {
+ public function __construct(ContainerInterface $serverContainer) {
$this->serverContainer = $serverContainer;
}
@@ -57,17 +58,25 @@ 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) {
+ if ($this->appManager === null) {
+ $this->appManager = $this->serverContainer->get(IAppManager::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.
@@ -90,7 +99,7 @@ class Manager implements IManager {
*/
\OC::$server->get(LoggerInterface::class)->critical(
'Could not register lazy dashboard widget: ' . $e->getMessage(),
- ['excepiton' => $e]
+ ['exception' => $e]
);
}
@@ -111,7 +120,7 @@ class Manager implements IManager {
} catch (Throwable $e) {
\OC::$server->get(LoggerInterface::class)->critical(
'Error during dashboard widget loading: ' . $e->getMessage(),
- ['excepiton' => $e]
+ ['exception' => $e]
);
}
}
diff --git a/lib/public/Dashboard/IManager.php b/lib/public/Dashboard/IManager.php
index 396624876ef..d9e73c89eb9 100644
--- a/lib/public/Dashboard/IManager.php
+++ b/lib/public/Dashboard/IManager.php
@@ -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