Skip to content

Commit f8b4f37

Browse files
committed
fix(dav): check the owner displayName scope before giving attribute
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 84e9aff commit f8b4f37

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OC\FilesMetadata\Model\FilesMetadata;
1212
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
1313
use OCA\Files_Sharing\External\Mount as SharingExternalMount;
14+
use OCP\Accounts\IAccountManager;
1415
use OCP\Constants;
1516
use OCP\Files\ForbiddenException;
1617
use OCP\Files\IFilenameValidator;
@@ -91,6 +92,7 @@ public function __construct(
9192
private IPreview $previewManager,
9293
private IUserSession $userSession,
9394
private IFilenameValidator $validator,
95+
private IAccountManager $accountManager,
9496
private bool $isPublic = false,
9597
private bool $downloadAttachment = true,
9698
) {
@@ -361,9 +363,26 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
361363
$owner = $node->getOwner();
362364
if (!$owner) {
363365
return null;
364-
} else {
366+
}
367+
368+
// Get current user to see if we're in a public share or not
369+
$user = $this->userSession->getUser();
370+
371+
// If the user is logged in, we can return the display name
372+
if ($user !== null) {
365373
return $owner->getDisplayName();
366374
}
375+
376+
// Check if the user published their display name
377+
$ownerAccount = $this->accountManager->getAccount($owner);
378+
$ownerNameProperty = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME);
379+
380+
// If not logged in, we need to have at least the published scope
381+
if ($user === null && $ownerNameProperty->getScope() === IAccountManager::SCOPE_PUBLISHED) {
382+
return $owner->getDisplayName();
383+
}
384+
385+
return null;
367386
});
368387

369388
$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {

apps/dav/lib/Connector/Sabre/ServerFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCA\DAV\DAV\ViewOnlyPlugin;
1515
use OCA\DAV\Files\BrowserErrorPagePlugin;
1616
use OCA\Theming\ThemingDefaults;
17+
use OCP\Accounts\IAccountManager;
1718
use OCP\App\IAppManager;
1819
use OCP\Comments\ICommentsManager;
1920
use OCP\EventDispatcher\IEventDispatcher;
@@ -128,6 +129,7 @@ public function createServer(string $baseUri,
128129
$this->previewManager,
129130
$this->userSession,
130131
\OCP\Server::get(IFilenameValidator::class),
132+
\OCP\Server::get(IAccountManager::class),
131133
false,
132134
!$this->config->getSystemValue('debug', false)
133135
)

apps/dav/lib/Server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
use OCP\ISession;
8686
use OCP\ITagManager;
8787
use OCP\IURLGenerator;
88+
use OCP\IUserManager;
8889
use OCP\IUserSession;
8990
use OCP\Mail\IMailer;
9091
use OCP\Profiler\IProfiler;
@@ -287,6 +288,7 @@ public function __construct(
287288
\OCP\Server::get(IPreview::class),
288289
\OCP\Server::get(IUserSession::class),
289290
\OCP\Server::get(IFilenameValidator::class),
291+
\OCP\Server::get(IUserManager::class),
290292
false,
291293
$config->getSystemValueBool('debug', false) === false,
292294
)

apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\DAV\Connector\Sabre\File;
1414
use OCA\DAV\Connector\Sabre\FilesPlugin;
1515
use OCA\DAV\Connector\Sabre\Node;
16+
use OCP\Accounts\IAccountManager;
1617
use OCP\Files\FileInfo;
1718
use OCP\Files\IFilenameValidator;
1819
use OCP\Files\InvalidPathException;
@@ -43,6 +44,7 @@ class FilesPluginTest extends TestCase {
4344
private IPreview&MockObject $previewManager;
4445
private IUserSession&MockObject $userSession;
4546
private IFilenameValidator&MockObject $filenameValidator;
47+
private IAccountManager&MockObject $accountManager;
4648
private FilesPlugin $plugin;
4749

4850
protected function setUp(): void {
@@ -57,6 +59,7 @@ protected function setUp(): void {
5759
$this->previewManager = $this->createMock(IPreview::class);
5860
$this->userSession = $this->createMock(IUserSession::class);
5961
$this->filenameValidator = $this->createMock(IFilenameValidator::class);
62+
$this->accountManager = $this->createMock(IAccountManager::class);
6063

6164
$this->plugin = new FilesPlugin(
6265
$this->tree,
@@ -65,6 +68,7 @@ protected function setUp(): void {
6568
$this->previewManager,
6669
$this->userSession,
6770
$this->filenameValidator,
71+
$this->accountManager,
6872
);
6973

7074
$response = $this->getMockBuilder(ResponseInterface::class)
@@ -215,6 +219,7 @@ public function testGetPublicPermissions(): void {
215219
$this->previewManager,
216220
$this->userSession,
217221
$this->filenameValidator,
222+
$this->accountManager,
218223
true,
219224
);
220225
$this->plugin->initialize($this->server);

apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\DAV\Connector\Sabre\Directory;
1212
use OCA\DAV\Connector\Sabre\FilesPlugin;
1313
use OCA\DAV\Connector\Sabre\FilesReportPlugin as FilesReportPluginImplementation;
14+
use OCP\Accounts\IAccountManager;
1415
use OCP\App\IAppManager;
1516
use OCP\Files\File;
1617
use OCP\Files\FileInfo;
@@ -23,6 +24,7 @@
2324
use OCP\ITagManager;
2425
use OCP\ITags;
2526
use OCP\IUser;
27+
use OCP\IUserManager;
2628
use OCP\IUserSession;
2729
use OCP\SystemTag\ISystemTag;
2830
use OCP\SystemTag\ISystemTagManager;
@@ -389,6 +391,7 @@ public function testPrepareResponses(): void {
389391
->getMock();
390392

391393
$validator = $this->createMock(IFilenameValidator::class);
394+
$accountManager = $this->createMock(IAccountManager::class);
392395

393396
$this->server->addPlugin(
394397
new FilesPlugin(
@@ -398,6 +401,7 @@ public function testPrepareResponses(): void {
398401
$this->previewManager,
399402
$this->createMock(IUserSession::class),
400403
$validator,
404+
$accountManager,
401405
)
402406
);
403407
$this->plugin->initialize($this->server);

apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<NcNoteCard v-if="note.length > 0"
77
class="note-to-recipient"
88
type="info">
9-
<p v-if="user" class="note-to-recipient__heading">
9+
<p v-if="displayName" class="note-to-recipient__heading">
1010
{{ t('files_sharing', 'Note from') }}
1111
<NcUserBubble :user="user.id" :display-name="user.displayName" />
1212
</p>
@@ -28,13 +28,13 @@ import NcUserBubble from '@nextcloud/vue/components/NcUserBubble'
2828
2929
const folder = ref<Folder>()
3030
const note = computed<string>(() => folder.value?.attributes.note ?? '')
31+
const displayName = computed<string>(() => folder.value?.attributes['owner-display-name'] ?? '')
3132
const user = computed(() => {
3233
const id = folder.value?.owner
33-
const displayName = folder.value?.attributes?.['owner-display-name']
3434
if (id !== getCurrentUser()?.uid) {
3535
return {
3636
id,
37-
displayName,
37+
displayName: displayName.value,
3838
}
3939
}
4040
return null

0 commit comments

Comments
 (0)