Skip to content

Commit 1bc2943

Browse files
authored
Adding a message on disabling external storage without disabling hejb… (#143)
* Adding a message on disabling external storage without disabling hejbit plug-in * chore: fix code style * Using BaseException instead of Exception * chore: fix code style --------- Co-authored-by: JoaoSRaposo <[email protected]>
1 parent 2198c72 commit 1bc2943

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

lib/AppInfo/Application.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
use OC\Security\CSP\ContentSecurityPolicy;
2727
use OCA\Files\Event\LoadAdditionalScriptsEvent;
28+
use OCA\Files_External_Ethswarm\Listener\PreventExternalStorageDisableListener;
2829
use OCA\Files_External_Ethswarm\Utils\Env;
30+
use OCP\App\Events\AppDisableEvent;
2931
use OCP\AppFramework\Bootstrap\IBootContext;
3032
use OCP\AppFramework\Bootstrap\IRegistrationContext;
3133
use OCP\EventDispatcher\IEventDispatcher;
@@ -56,6 +58,12 @@ public function boot(IBootContext $context): void {
5658
public function register(IRegistrationContext $context): void {
5759
$this->loadTelemetry();
5860

61+
// Register the listener to prevent files_external from being disabled
62+
$context->registerEventListener(
63+
AppDisableEvent::class,
64+
PreventExternalStorageDisableListener::class
65+
);
66+
5967
/** @var IEventDispatcher $dispatcher */
6068
$dispatcher = $this->container->get(IEventDispatcher::class);
6169
$dispatcher->addListener(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace OCA\Files_External_Ethswarm\Listener;
4+
5+
use Exception;
6+
use OCA\Files_External_Ethswarm\Exception\BaseException;
7+
use OCP\App\Events\AppDisableEvent;
8+
use OCP\App\IAppManager;
9+
use OCP\EventDispatcher\Event;
10+
use OCP\EventDispatcher\IEventListener;
11+
use Psr\Log\LoggerInterface;
12+
13+
class PreventExternalStorageDisableListener implements IEventListener {
14+
private IAppManager $appManager;
15+
private LoggerInterface $logger;
16+
17+
public function __construct(
18+
IAppManager $appManager,
19+
LoggerInterface $logger
20+
) {
21+
$this->appManager = $appManager;
22+
$this->logger = $logger;
23+
}
24+
25+
public function handle(Event $event): void {
26+
if (!$event instanceof AppDisableEvent) {
27+
return;
28+
}
29+
30+
$appId = $event->getAppId();
31+
32+
// Check if files_external is being disabled while our app is enabled
33+
if ('files_external' === $appId && $this->appManager->isEnabledForUser('files_external_ethswarm')) {
34+
$message = 'Cannot disable External Storage app while HejBit Swarm plugin is enabled. Please disable HejBit Swarm plugin first.';
35+
36+
$this->logger->warning($message);
37+
38+
// Throw an exception to prevent the disable and show error message
39+
throw new BaseException($message);
40+
}
41+
}
42+
}

vendor-bin/sentry/composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)