Skip to content

Commit 24fc1dc

Browse files
Merge pull request #15102 from nextcloud/backport/15095/stable31
[stable31] feat(sharing): Allow richdocuments to hide-download for public talk share links
2 parents 8714ee4 + 5a858b1 commit 24fc1dc

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

lib/Chat/Parser/SystemMessage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\DAV\CardDAV\PhotoCache;
1313
use OCA\Talk\Chat\ChatManager;
1414
use OCA\Talk\Events\MessageParseEvent;
15+
use OCA\Talk\Events\OverwritePublicSharePropertiesEvent;
1516
use OCA\Talk\Exceptions\ParticipantNotFoundException;
1617
use OCA\Talk\Federation\Authenticator;
1718
use OCA\Talk\GuestManager;
@@ -26,6 +27,7 @@
2627
use OCP\Comments\IComment;
2728
use OCP\Comments\ICommentsManager;
2829
use OCP\EventDispatcher\Event;
30+
use OCP\EventDispatcher\IEventDispatcher;
2931
use OCP\EventDispatcher\IEventListener;
3032
use OCP\Federation\ICloudIdManager;
3133
use OCP\Files\FileInfo;
@@ -82,6 +84,7 @@ public function __construct(
8284
protected IURLGenerator $url,
8385
protected FilesMetadataCache $metadataCache,
8486
protected Authenticator $federationAuthenticator,
87+
protected IEventDispatcher $dispatcher,
8588
) {
8689
}
8790

@@ -824,6 +827,7 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin
824827
$node = $share->getNodeCacheEntry();
825828
} else {
826829
$node = $share->getNode();
830+
$this->dispatcher->dispatchTyped(new OverwritePublicSharePropertiesEvent($share));
827831
}
828832

829833
$name = $node->getName();
@@ -853,6 +857,7 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin
853857
'permissions' => (string)$node->getPermissions(),
854858
'mimetype' => $node->getMimeType(),
855859
'preview-available' => $isPreviewAvailable ? 'yes' : 'no',
860+
'hide-download' => $share->getHideDownload() ? 'yes' : 'no',
856861
];
857862

858863
// If a preview is available, check if we can get the dimensions of the file from the metadata API
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Talk\Events;
10+
11+
use OCP\EventDispatcher\Event;
12+
use OCP\Share\IShare;
13+
14+
/**
15+
* @internal
16+
*/
17+
class OverwritePublicSharePropertiesEvent extends Event {
18+
public function __construct(
19+
protected IShare $share,
20+
) {
21+
parent::__construct();
22+
}
23+
24+
public function getShare(): IShare {
25+
return $this->share;
26+
}
27+
}

src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
</template>
122122
{{ t('spreed', 'Go to file') }}
123123
</NcActionLink>
124-
<NcActionLink :href="linkToFileDownload" :download="messageFile.name">
124+
<NcActionLink v-if="!hideDownloadOption" :href="linkToFileDownload" :download="messageFile.name">
125125
<template #icon>
126126
<IconDownload :size="20" />
127127
</template>
@@ -413,6 +413,7 @@ export default {
413413
isCurrentUserOwnMessage,
414414
isFileShare,
415415
isFileShareWithoutCaption,
416+
hideDownloadOption,
416417
isConversationReadOnly,
417418
isConversationModifiable,
418419
} = useMessageInfo(message)
@@ -426,6 +427,7 @@ export default {
426427
isCurrentUserOwnMessage,
427428
isFileShare,
428429
isFileShareWithoutCaption,
430+
hideDownloadOption,
429431
isDeleteable,
430432
isConversationReadOnly,
431433
isConversationModifiable,

src/composables/useMessageInfo.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function useMessageInfo(message = ref({})) {
3939
isConversationReadOnly: computed(() => false),
4040
isFileShareWithoutCaption: computed(() => false),
4141
isFileShare: computed(() => false),
42+
hideDownloadOption: computed(() => true),
4243
remoteServer: computed(() => ''),
4344
lastEditor: computed(() => ''),
4445
actorDisplayName: computed(() => ''),
@@ -80,6 +81,8 @@ export function useMessageInfo(message = ref({})) {
8081

8182
const isFileShare = computed(() => Object.keys(Object(message.value.messageParameters)).some(key => key.startsWith('file')))
8283

84+
const hideDownloadOption = computed(() => Object.values(Object(message.value.messageParameters)).some((value) => value.type === 'file' && value['hide-download'] === 'yes'))
85+
8386
const isFileShareWithoutCaption = computed(() => message.value.message === '{file}' && isFileShare.value)
8487

8588
const isDeleteable = computed(() =>
@@ -134,6 +137,7 @@ export function useMessageInfo(message = ref({})) {
134137
isConversationReadOnly,
135138
isFileShareWithoutCaption,
136139
isFileShare,
140+
hideDownloadOption,
137141
remoteServer,
138142
lastEditor,
139143
actorDisplayName,

tests/php/Chat/Parser/SystemMessageTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCA\Talk\Share\RoomShareProvider;
2525
use OCP\AppFramework\Services\IAppConfig;
2626
use OCP\Comments\IComment;
27+
use OCP\EventDispatcher\IEventDispatcher;
2728
use OCP\Federation\ICloudId;
2829
use OCP\Federation\ICloudIdManager;
2930
use OCP\Files\Folder;
@@ -59,6 +60,7 @@ class SystemMessageTest extends TestCase {
5960
protected ICloudIdManager&MockObject $cloudIdManager;
6061
protected FilesMetadataCache&MockObject $filesMetadataCache;
6162
protected Authenticator&MockObject $federationAuthenticator;
63+
protected IEventDispatcher&MockObject $dispatcher;
6264
protected IL10N&MockObject $l;
6365

6466
public function setUp(): void {
@@ -77,6 +79,7 @@ public function setUp(): void {
7779
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
7880
$this->filesMetadataCache = $this->createMock(FilesMetadataCache::class);
7981
$this->federationAuthenticator = $this->createMock(Authenticator::class);
82+
$this->dispatcher = $this->createMock(IEventDispatcher::class);
8083
$this->l = $this->createMock(IL10N::class);
8184
$this->l->method('t')
8285
->willReturnCallback(function ($text, $parameters = []) {
@@ -110,6 +113,7 @@ protected function getParser(array $methods = []): SystemMessage {
110113
$this->url,
111114
$this->filesMetadataCache,
112115
$this->federationAuthenticator,
116+
$this->dispatcher,
113117
])
114118
->onlyMethods($methods)
115119
->getMock();
@@ -130,6 +134,7 @@ protected function getParser(array $methods = []): SystemMessage {
130134
$this->url,
131135
$this->filesMetadataCache,
132136
$this->federationAuthenticator,
137+
$this->dispatcher,
133138
);
134139
}
135140

@@ -741,6 +746,7 @@ public function testGetFileFromShareForGuest(): void {
741746
'permissions' => '27',
742747
'mimetype' => 'image/png',
743748
'preview-available' => 'yes',
749+
'hide-download' => 'no',
744750
'width' => '1234',
745751
'height' => '4567',
746752
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23', false]));
@@ -817,6 +823,7 @@ public function testGetFileFromShareForGuestWithBlurhash(): void {
817823
'permissions' => '27',
818824
'mimetype' => 'image/png',
819825
'preview-available' => 'yes',
826+
'hide-download' => 'no',
820827
'width' => '1234',
821828
'height' => '4567',
822829
'blurhash' => 'LEHV9uae2yk8pyo0adR*.7kCMdnj',
@@ -897,6 +904,7 @@ public function testGetFileFromShareForOwner(): void {
897904
'permissions' => '27',
898905
'mimetype' => 'httpd/unix-directory',
899906
'preview-available' => 'no',
907+
'hide-download' => 'no',
900908
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23', false]));
901909
}
902910

@@ -982,6 +990,7 @@ public function testGetFileFromShareForRecipient(): void {
982990
'permissions' => '27',
983991
'mimetype' => 'application/octet-stream',
984992
'preview-available' => 'no',
993+
'hide-download' => 'no',
985994
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23', false]));
986995
}
987996

tests/php/EventDocumentationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function testEventDocumentation(string $eventClass): void {
3939
self::assertTrue(true, 'Deprecated event ' . $eventClass . ' does not have to be documented');
4040
return;
4141
}
42+
if (is_string($classDocBlock) && str_contains($classDocBlock, '@internal')) {
43+
self::assertTrue(true, 'Internal event ' . $eventClass . ' does not have to be documented');
44+
return;
45+
}
4246

4347
$docs = file_get_contents(__DIR__ . '/../../docs/events.md');
4448
$eventIsDocumented = str_contains($docs, 'Before event: `' . $eventClass . '`')

0 commit comments

Comments
 (0)