Skip to content

Commit 962d4f9

Browse files
provokateurinbackportbot[bot]
authored andcommitted
fix(files_sharing): Fail on sharing file with create or delete permission before failing on increased permissions
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 1b7576d commit 962d4f9

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

apps/files_sharing/lib/Listener/RestrictInteractionListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ public function handle(Event $event): void {
5656
}
5757

5858
if ($event->action->filesSharingPermissions !== null) {
59-
if (($event->action->filesSharingPermissions & ~$event->resource->getNodePermissions()) !== 0) {
60-
$path = $userFolder->getRelativePath($event->resource->getNode()->getPath());
61-
throw new InteractionRestrictedException('Cannot share node with more permissions than the node already has.', $this->l10n->t('You cannot share "%s" with more permission than you have yourself.', [$path]));
62-
}
63-
6459
if ($event->resource->getNode() instanceof File) {
6560
if (($event->action->filesSharingPermissions & Constants::PERMISSION_DELETE) === Constants::PERMISSION_DELETE) {
6661
throw new InteractionRestrictedException('Cannot share file node with delete permission.', $this->l10n->t('File cannot be shared with delete permission.'));
@@ -83,6 +78,11 @@ public function handle(Event $event): void {
8378
&& !$this->manager->shareApiLinkAllowPublicUpload()) {
8479
throw new InteractionRestrictedException('Public upload is not allowed.', $this->l10n->t('Public upload is not allowed.'));
8580
}
81+
82+
if (($event->action->filesSharingPermissions & ~$event->resource->getNodePermissions()) !== 0) {
83+
$path = $userFolder->getRelativePath($event->resource->getNode()->getPath());
84+
throw new InteractionRestrictedException('Cannot share node with more permissions than the node already has.', $this->l10n->t('You cannot share "%s" with more permission than you have yourself.', [$path]));
85+
}
8686
}
8787
}
8888
}

apps/files_sharing/tests/Listener/RestrictInteractionListenerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ public function testNodeResourceShareActionIncreasePermission(): void {
9595
}
9696
}
9797

98+
public function testNodeResourceShareActionIncreasePermissionFileDelete(): void {
99+
$userFolder = Server::get(IRootFolder::class)->getUserFolder($this->user->getUID());
100+
101+
$node = $userFolder->newFile('foo.txt', 'bar');
102+
$node->getStorage()->getCache()->update($node->getId(), ['permissions' => Constants::PERMISSION_READ | Constants::PERMISSION_SHARE]);
103+
104+
$event = new RestrictInteractionEvent($this->user->getUID(), $this->user, new NodeResource($node->getId(), $this->user->getUID(), $node), new ShareAction(Constants::PERMISSION_READ | Constants::PERMISSION_SHARE | Constants::PERMISSION_DELETE), null);
105+
$this->assertEquals('File cannot be shared with delete permission.', $event->isInteractionRestricted());
106+
}
107+
108+
public function testNodeResourceShareActionIncreasePermissionFileCreate(): void {
109+
$userFolder = Server::get(IRootFolder::class)->getUserFolder($this->user->getUID());
110+
111+
$node = $userFolder->newFile('foo.txt', 'bar');
112+
$node->getStorage()->getCache()->update($node->getId(), ['permissions' => Constants::PERMISSION_READ | Constants::PERMISSION_SHARE]);
113+
114+
$event = new RestrictInteractionEvent($this->user->getUID(), $this->user, new NodeResource($node->getId(), $this->user->getUID(), $node), new ShareAction(Constants::PERMISSION_READ | Constants::PERMISSION_SHARE | Constants::PERMISSION_CREATE), null);
115+
$this->assertEquals('File cannot be shared with create permission.', $event->isInteractionRestricted());
116+
}
117+
98118
public function testNodeResourceShareActionFileHasDeletePermission(): void {
99119
$userFolder = Server::get(IRootFolder::class)->getUserFolder($this->user->getUID());
100120

0 commit comments

Comments
 (0)