Skip to content

Commit b616741

Browse files
committed
refactor: use IUser for IShareSourceType::getSourceInteractionResource instead of user id string
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f2a0bb5 commit b616741

6 files changed

Lines changed: 14 additions & 9 deletions

File tree

apps/files/lib/Sharing/Source/NodeShareSourceType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use OCP\Interaction\InteractionResource;
2828
use OCP\Interaction\Resources\NodeResource;
2929
use OCP\IURLGenerator;
30+
use OCP\IUser;
3031
use OCP\L10N\IFactory;
3132

3233
/**
@@ -72,8 +73,8 @@ public function getSourceIcon(string $source): ShareIconURL {
7273
}
7374

7475
#[\Override]
75-
public function getSourceInteractionResource(string $userId, string $source): InteractionResource {
76-
return new NodeResource((int)$source, $userId);
76+
public function getSourceInteractionResource(IUser $user, string $source): InteractionResource {
77+
return new NodeResource((int)$source, $user);
7778
}
7879

7980
#[\Override]

lib/private/Sharing/SharingManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ private function validateInteraction(ShareAccessContext $accessContext, Share $s
733733
continue;
734734
}
735735

736-
$resources[] = $sourceType->getSourceInteractionResource($userToCheck->getUID(), $source->value);
736+
$resources[] = $sourceType->getSourceInteractionResource($userToCheck, $source->value);
737737
}
738738

739739
$event = new RestrictInteractionEvent($userToCheck->getUID(), $userToCheck, $resources, $action, $receivers);

lib/public/Interaction/Resources/NodeResource.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\Files\Mount\IMovableMount;
1616
use OCP\Files\Node;
1717
use OCP\Interaction\InteractionResource;
18+
use OCP\IUser;
1819
use OCP\Server;
1920
use RuntimeException;
2021

@@ -30,7 +31,7 @@ final class NodeResource implements InteractionResource {
3031
*/
3132
public function __construct(
3233
public readonly int $nodeId,
33-
private readonly string $userId,
34+
private readonly IUser $user,
3435
private ?Node $node = null,
3536
/** @var ?int-mask-of<Constants::PERMISSION_*> $nodePermissions */
3637
private ?int $nodePermissions = null,
@@ -47,7 +48,7 @@ public function getNode(): Node {
4748
return $this->node;
4849
}
4950

50-
$node = Server::get(IRootFolder::class)->getUserFolder($this->userId)->getFirstNodeById($this->nodeId);
51+
$node = Server::get(IRootFolder::class)->getUserFolder($this->user->getUID())->getFirstNodeById($this->nodeId);
5152
if ($node === null) {
5253
throw new RuntimeException('Node does not exist: ' . $this->nodeId);
5354
}
@@ -66,7 +67,7 @@ public function getNodePermissions(): int {
6667
return $this->nodePermissions;
6768
}
6869

69-
$nodes = Server::get(IRootFolder::class)->getUserFolder($this->userId)->getById($this->nodeId);
70+
$nodes = Server::get(IRootFolder::class)->getUserFolder($this->user->getUID())->getById($this->nodeId);
7071
if ($nodes === []) {
7172
throw new RuntimeException('Node does not exist: ' . $this->nodeId);
7273
}

lib/unstable/Sharing/Source/IShareSourceType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use NCU\Sharing\Icon\ShareIconURL;
1414
use OCP\AppFramework\Attribute\Implementable;
1515
use OCP\Interaction\InteractionResource;
16+
use OCP\IUser;
1617
use OCP\L10N\IFactory;
1718

1819
/**
@@ -52,9 +53,9 @@ public function getSourceDisplayName(string $source): ?string;
5253
public function getSourceIcon(string $source): null|ShareIconSVG|ShareIconURL;
5354

5455
/**
55-
* @param non-empty-string $userId
56+
* @param IUser $user
5657
* @param non-empty-string $source
5758
* @experimental 35.0.0
5859
*/
59-
public function getSourceInteractionResource(string $userId, string $source): InteractionResource;
60+
public function getSourceInteractionResource(IUser $user, string $source): InteractionResource;
6061
}

tests/lib/Sharing/TestInteractionResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Test\Sharing;
1111

1212
use OCP\Interaction\InteractionResource;
13+
use OCP\IUser;
1314

1415
final readonly class TestInteractionResource implements InteractionResource {
1516
public function __construct(

tests/lib/Sharing/TestShareSourceType1.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use NCU\Sharing\Icon\ShareIconURL;
1414
use NCU\Sharing\Source\IShareSourceType;
1515
use OCP\Interaction\InteractionResource;
16+
use OCP\IUser;
1617
use OCP\L10N\IFactory;
1718

1819
class TestShareSourceType1 implements IShareSourceType {
@@ -45,7 +46,7 @@ public function getSourceIcon(string $source): null|ShareIconSVG|ShareIconURL {
4546
}
4647

4748
#[\Override]
48-
public function getSourceInteractionResource(string $userId, string $source): InteractionResource {
49+
public function getSourceInteractionResource(IUser $user, string $source): InteractionResource {
4950
return new TestInteractionResource($source);
5051
}
5152
}

0 commit comments

Comments
 (0)