Skip to content

Commit

Permalink
Merge pull request #3672 from nextcloud/fix/no-fileaction-if-disabled
Browse files Browse the repository at this point in the history
fix: Avoid loading file actions if app is disabled for users
  • Loading branch information
blizzz committed May 8, 2024
2 parents a54d59b + b2b93ff commit 4218f6f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Listener/LoadAdditionalListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
namespace OCA\Richdocuments\Listener;

use OCA\Richdocuments\AppInfo\Application;
use OCA\Richdocuments\PermissionManager;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

/** @template-implements IEventListener<LoadAdditionalScriptsEvent> */
class LoadAdditionalListener implements IEventListener {
public function __construct(
private PermissionManager $permissionManager,
private ?string $userId,
) {
}

public function handle(Event $event): void {
// If not a LoadAdditionalScriptsEvent, we should do nothing
if (!($event instanceof LoadAdditionalScriptsEvent)) {
return;
}

// If we can add an init script, we add the file-actions script
if (method_exists(Util::class, 'addInitScript')) {
if ($this->permissionManager->isEnabledForUser() && $this->userId !== null) {
Util::addInitScript(Application::APPNAME, 'richdocuments-fileActions');
}
}
Expand Down

0 comments on commit 4218f6f

Please sign in to comment.