Skip to content

Commit

Permalink
refactor(files_sharing): Handle access to shares using the direct dow…
Browse files Browse the repository at this point in the history
…nload endpoint

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Oct 7, 2024
1 parent 4bcbe8a commit bf63db1
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

namespace OCA\Files_Sharing\Listener;

use OCA\Files_Sharing\Services\ShareAccessService;
use OCA\Files_Sharing\ViewOnly;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
use OCP\Files\IRootFolder;
use OCP\Files\Storage\ISharedStorage;
use OCP\IUserSession;

/**
Expand All @@ -24,6 +26,7 @@ class BeforeDirectFileDownloadListener implements IEventListener {
public function __construct(
private IUserSession $userSession,
private IRootFolder $rootFolder,
private ShareAccessService $accessService,
) {
}

Expand All @@ -42,6 +45,19 @@ public function handle(Event $event): void {
if (!$viewOnlyHandler->check($pathsToCheck)) {
$event->setSuccessful(false);
$event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');
return;
}
}

$node = $event->getNode();
if ($node !== null) {
$storage = $node->getStorage();
if ($storage->instanceOfStorage(ISharedStorage::class)) {
/** @var ISharedStorage $storage */
$share = $storage->getShare();
$this->accessService->shareDownloaded($share);
// All we now need to do is log the download
$this->accessService->sharedFileDownloaded($share, $node);
}
}
}
Expand Down

0 comments on commit bf63db1

Please sign in to comment.