Skip to content

Commit

Permalink
fix(files_versions): Explicitly check for user or owner before call g…
Browse files Browse the repository at this point in the history
…etUserFolder

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Fix typo

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Fix

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Fix

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Fix

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Optimize DI

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>

Switch to DI

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
  • Loading branch information
solracsf committed Nov 27, 2023
1 parent 28e0ccf commit 24e136a
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions apps/files_versions/lib/Listener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,21 @@
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;

class FileEventsListener implements IEventListener {
private IRootFolder $rootFolder;
private IVersionManager $versionManager;
/**
* @var array<int, array>
*/
private array $writeHookInfo = [];
/**
* @var array<int, Node>
*/
private array $nodesTouched = [];
/**
* @var array<string, Node>
*/
private array $versionsDeleted = [];
private IMimeTypeLoader $mimeTypeLoader;
private LoggerInterface $logger;

public function __construct(
IRootFolder $rootFolder,
IVersionManager $versionManager,
IMimeTypeLoader $mimeTypeLoader,
LoggerInterface $logger,
private IRootFolder $rootFolder,
private IVersionManager $versionManager,
private IMimeTypeLoader $mimeTypeLoader,
private IUserSession $userSession,
private LoggerInterface $logger,
) {
$this->rootFolder = $rootFolder;
$this->versionManager = $versionManager;
$this->mimeTypeLoader = $mimeTypeLoader;
$this->logger = $logger;
}

public function handle(Event $event): void {
Expand Down Expand Up @@ -354,18 +339,20 @@ public function pre_renameOrCopy_hook(Node $source, Node $target): void {
* If no user is connected, try to use the node's owner.
*/
private function getPathForNode(Node $node): ?string {
try {
$user = $this->userSession?->getUser()?->getUID();

Check failure on line 342 in apps/files_versions/lib/Listener/FileEventsListener.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TypeDoesNotContainNull

apps/files_versions/lib/Listener/FileEventsListener.php:342:11: TypeDoesNotContainNull: OCP\IUserSession does not contain null (see https://psalm.dev/090)

Check failure on line 342 in apps/files_versions/lib/Listener/FileEventsListener.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

apps/files_versions/lib/Listener/FileEventsListener.php:342:11: RedundantCondition: Type OCP\IUserSession for $__tmp_nullsafe__11007 is never null (see https://psalm.dev/122)

Check failure

Code scanning / Psalm

TypeDoesNotContainNull Error

OCP\IUserSession does not contain null

Check failure

Code scanning / Psalm

RedundantCondition Error

Type OCP\IUserSession for $__tmp_nullsafe__11007 is never null
if ($user) {
return $this->rootFolder
->getUserFolder(\OC_User::getUser())
->getUserFolder($user)
->getRelativePath($node->getPath());
} catch (\Throwable $ex) {
$owner = $node->getOwner();
if ($owner === null) {
return null;
}
}

$owner = $node->getOwner()?->getUid();
if ($owner) {
return $this->rootFolder
->getUserFolder($owner->getUid())
->getUserFolder($owner)
->getRelativePath($node->getPath());
}

return null;
}
}

0 comments on commit 24e136a

Please sign in to comment.