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

fix: Avoid loading file actions if app is disabled for users #3672

Merged
merged 1 commit into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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