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: Dispatch event instead of hook for audit logging #3969

Merged
merged 1 commit into from
Sep 2, 2024
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
61 changes: 13 additions & 48 deletions lib/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
namespace OCA\Richdocuments;

use Exception;
use OC\Files\Filesystem;
use OCA\Files_Sharing\SharedStorage;
use OCA\Richdocuments\Db\Direct;
use OCA\Richdocuments\Db\Wopi;
use OCA\Richdocuments\Db\WopiMapper;
use OCA\Richdocuments\Service\CapabilitiesService;
use OCA\Richdocuments\WOPI\Parser;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\Node\BeforeNodeReadEvent;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
Expand All @@ -28,49 +28,18 @@
use OCP\Util;

class TokenManager {
/** @var IRootFolder */
private $rootFolder;
/** @var IManager */
private $shareManager;
/** @var IURLGenerator */
private $urlGenerator;
/** @var Parser */
private $wopiParser;
/** @var string */
private $userId;
/** @var WopiMapper */
private $wopiMapper;
/** @var IL10N */
private $trans;
/** @var CapabilitiesService */
private $capabilitiesService;
/** @var Helper */
private $helper;
/** @var PermissionManager */
private $permissionManager;

public function __construct(
IRootFolder $rootFolder,
IManager $shareManager,
IURLGenerator $urlGenerator,
Parser $wopiParser,
CapabilitiesService $capabilitiesService,
$UserId,
WopiMapper $wopiMapper,
IL10N $trans,
Helper $helper,
PermissionManager $permissionManager
private IRootFolder $rootFolder,
private IManager $shareManager,
private IURLGenerator $urlGenerator,
private Parser $wopiParser,
private ?string $userId,
private WopiMapper $wopiMapper,
private IL10N $trans,
private Helper $helper,
private PermissionManager $permissionManager,
private IEventDispatcher $eventDispatcher,
) {
$this->rootFolder = $rootFolder;
$this->shareManager = $shareManager;
$this->urlGenerator = $urlGenerator;
$this->wopiParser = $wopiParser;
$this->capabilitiesService = $capabilitiesService;
$this->trans = $trans;
$this->userId = $UserId;
$this->wopiMapper = $wopiMapper;
$this->helper = $helper;
$this->permissionManager = $permissionManager;
}

/**
Expand Down Expand Up @@ -178,11 +147,7 @@ public function generateWopiToken(string $fileId, ?string $shareToken = null, ?s
}

// force read operation to trigger possible audit logging
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_read,
[Filesystem::signal_param_path => $file->getPath()]
);
$this->eventDispatcher->dispatchTyped(new BeforeNodeReadEvent($file));

$serverHost = $this->urlGenerator->getAbsoluteURL('/');
$guestName = $editoruid === null ? $this->prepareGuestName($this->helper->getGuestNameFromCookie()) : null;
Expand Down
5 changes: 1 addition & 4 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<file src="lib/AppConfig.php">
<InvalidArgument>
<code><![CDATA[[]]]></code>
Expand Down Expand Up @@ -89,9 +89,6 @@
<MissingDependency>
<code><![CDATA[Image]]></code>
</MissingDependency>
<UndefinedThisPropertyAssignment>
<code><![CDATA[$this->capabilitites]]></code>
</UndefinedThisPropertyAssignment>
</file>
<file src="lib/Service/ConnectivityService.php">
<UndefinedClass>
Expand Down
Loading