Skip to content

Commit

Permalink
fix: Dispatch event instead of hook for audit logging
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot[bot] committed Sep 2, 2024
1 parent f079a6f commit 5f71414
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 52 deletions.
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

0 comments on commit 5f71414

Please sign in to comment.