Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable23] load dashboard widgets of enabled apps only #33156

Merged
merged 3 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/AppFramework/Bootstrap/Coordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function registerApps(array $appIds): void {
*/
$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);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/AppFramework/Bootstrap/RegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ public function delegateCrashReporterRegistrations(array $apps, Registry $regist
/**
* @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(), [
Expand Down
32 changes: 22 additions & 10 deletions lib/private/Dashboard/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
namespace OC\Dashboard;

use InvalidArgumentException;
use OCP\AppFramework\QueryException;
use OCP\App\IAppManager;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
use OCP\ILogger;
use OCP\IServerContainer;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Throwable;

class Manager implements IManager {
Expand All @@ -42,10 +43,13 @@ class Manager implements IManager {
/** @var IWidget[] */
private $widgets = [];

/** @var IServerContainer */
/** @var ContainerInterface */
private $serverContainer;

public function __construct(IServerContainer $serverContainer) {
/** @var ?IAppManager */
private $appManager = null;

public function __construct(ContainerInterface $serverContainer) {
$this->serverContainer = $serverContainer;
}

Expand All @@ -57,17 +61,25 @@ private function registerWidget(IWidget $widget): void {
$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.
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Dashboard/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down