Skip to content
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
8 changes: 8 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

use OC\Security\CSP\ContentSecurityPolicy;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files_External_Ethswarm\Listener\PreventExternalStorageDisableListener;
use OCA\Files_External_Ethswarm\Utils\Env;
use OCP\App\Events\AppDisableEvent;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -56,6 +58,12 @@ public function boot(IBootContext $context): void {
public function register(IRegistrationContext $context): void {
$this->loadTelemetry();

// Register the listener to prevent files_external from being disabled
$context->registerEventListener(
AppDisableEvent::class,
PreventExternalStorageDisableListener::class
);

/** @var IEventDispatcher $dispatcher */
$dispatcher = $this->container->get(IEventDispatcher::class);
$dispatcher->addListener(
Expand Down
42 changes: 42 additions & 0 deletions lib/Listener/PreventExternalStorageDisableListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace OCA\Files_External_Ethswarm\Listener;

use Exception;
use OCA\Files_External_Ethswarm\Exception\BaseException;
use OCP\App\Events\AppDisableEvent;
use OCP\App\IAppManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;

class PreventExternalStorageDisableListener implements IEventListener {
private IAppManager $appManager;
private LoggerInterface $logger;

public function __construct(
IAppManager $appManager,
LoggerInterface $logger
) {
$this->appManager = $appManager;
$this->logger = $logger;
}

public function handle(Event $event): void {
if (!$event instanceof AppDisableEvent) {
return;
}

$appId = $event->getAppId();

// Check if files_external is being disabled while our app is enabled
if ('files_external' === $appId && $this->appManager->isEnabledForUser('files_external_ethswarm')) {
$message = 'Cannot disable External Storage app while HejBit Swarm plugin is enabled. Please disable HejBit Swarm plugin first.';

$this->logger->warning($message);

// Throw an exception to prevent the disable and show error message
throw new BaseException($message);
}
}
}
12 changes: 6 additions & 6 deletions vendor-bin/sentry/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.