diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2025-04-29 16:42:09 +0200 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2025-04-29 21:26:50 +0200 |
commit | b1a44b4d72cd0e02c32a8fae75d248e1c65383c5 (patch) | |
tree | 3302a4fdd3131223667b02d2b1a5d840e817b556 | |
parent | 84e9aff8471785b8623106b4848721a5a680a2bb (diff) | |
download | nextcloud-server-fix/public-owner-scope.tar.gz nextcloud-server-fix/public-owner-scope.zip |
fix(dav): check the owner displayName scope before giving attributefix/public-owner-scope
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesPlugin.php | 21 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/ServerFactory.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/Server.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php | 5 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue | 6 |
6 files changed, 36 insertions, 4 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 34f48384e12..b886534f9de 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -11,6 +11,7 @@ use OC\AppFramework\Http\Request; use OC\FilesMetadata\Model\FilesMetadata; use OCA\DAV\Connector\Sabre\Exception\InvalidPath; use OCA\Files_Sharing\External\Mount as SharingExternalMount; +use OCP\Accounts\IAccountManager; use OCP\Constants; use OCP\Files\ForbiddenException; use OCP\Files\IFilenameValidator; @@ -91,6 +92,7 @@ class FilesPlugin extends ServerPlugin { private IPreview $previewManager, private IUserSession $userSession, private IFilenameValidator $validator, + private IAccountManager $accountManager, private bool $isPublic = false, private bool $downloadAttachment = true, ) { @@ -361,9 +363,26 @@ class FilesPlugin extends ServerPlugin { $owner = $node->getOwner(); if (!$owner) { return null; - } else { + } + + // Get current user to see if we're in a public share or not + $user = $this->userSession->getUser(); + + // If the user is logged in, we can return the display name + if ($user !== null) { return $owner->getDisplayName(); } + + // Check if the user published their display name + $ownerAccount = $this->accountManager->getAccount($owner); + $ownerNameProperty = $ownerAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME); + + // Since we are not logged in, we need to have at least the published scope + if ($ownerNameProperty->getScope() === IAccountManager::SCOPE_PUBLISHED) { + return $owner->getDisplayName(); + } + + return null; }); $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index f035ff8d625..55cbb416457 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -14,6 +14,7 @@ use OCA\DAV\DAV\CustomPropertiesBackend; use OCA\DAV\DAV\ViewOnlyPlugin; use OCA\DAV\Files\BrowserErrorPagePlugin; use OCA\Theming\ThemingDefaults; +use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\Comments\ICommentsManager; use OCP\EventDispatcher\IEventDispatcher; @@ -128,6 +129,7 @@ class ServerFactory { $this->previewManager, $this->userSession, \OCP\Server::get(IFilenameValidator::class), + \OCP\Server::get(IAccountManager::class), false, !$this->config->getSystemValue('debug', false) ) diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 9ea18c029c8..f1595bab391 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -64,6 +64,7 @@ use OCA\DAV\SystemTag\SystemTagPlugin; use OCA\DAV\Upload\ChunkingPlugin; use OCA\DAV\Upload\ChunkingV2Plugin; use OCA\Theming\ThemingDefaults; +use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Utility\ITimeFactory; @@ -287,6 +288,7 @@ class Server { \OCP\Server::get(IPreview::class), \OCP\Server::get(IUserSession::class), \OCP\Server::get(IFilenameValidator::class), + \OCP\Server::get(IAccountManager::class), false, $config->getSystemValueBool('debug', false) === false, ) diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php index db07165ebf0..1cdc9ab660d 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php @@ -13,6 +13,7 @@ use OCA\DAV\Connector\Sabre\Exception\InvalidPath; use OCA\DAV\Connector\Sabre\File; use OCA\DAV\Connector\Sabre\FilesPlugin; use OCA\DAV\Connector\Sabre\Node; +use OCP\Accounts\IAccountManager; use OCP\Files\FileInfo; use OCP\Files\IFilenameValidator; use OCP\Files\InvalidPathException; @@ -43,6 +44,7 @@ class FilesPluginTest extends TestCase { private IPreview&MockObject $previewManager; private IUserSession&MockObject $userSession; private IFilenameValidator&MockObject $filenameValidator; + private IAccountManager&MockObject $accountManager; private FilesPlugin $plugin; protected function setUp(): void { @@ -57,6 +59,7 @@ class FilesPluginTest extends TestCase { $this->previewManager = $this->createMock(IPreview::class); $this->userSession = $this->createMock(IUserSession::class); $this->filenameValidator = $this->createMock(IFilenameValidator::class); + $this->accountManager = $this->createMock(IAccountManager::class); $this->plugin = new FilesPlugin( $this->tree, @@ -65,6 +68,7 @@ class FilesPluginTest extends TestCase { $this->previewManager, $this->userSession, $this->filenameValidator, + $this->accountManager, ); $response = $this->getMockBuilder(ResponseInterface::class) @@ -215,6 +219,7 @@ class FilesPluginTest extends TestCase { $this->previewManager, $this->userSession, $this->filenameValidator, + $this->accountManager, true, ); $this->plugin->initialize($this->server); diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php index 8b169dcd46f..33b61eac48d 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php @@ -11,6 +11,7 @@ use OC\Files\View; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\FilesPlugin; use OCA\DAV\Connector\Sabre\FilesReportPlugin as FilesReportPluginImplementation; +use OCP\Accounts\IAccountManager; use OCP\App\IAppManager; use OCP\Files\File; use OCP\Files\FileInfo; @@ -23,6 +24,7 @@ use OCP\IRequest; use OCP\ITagManager; use OCP\ITags; use OCP\IUser; +use OCP\IUserManager; use OCP\IUserSession; use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; @@ -389,6 +391,7 @@ class FilesReportPluginTest extends \Test\TestCase { ->getMock(); $validator = $this->createMock(IFilenameValidator::class); + $accountManager = $this->createMock(IAccountManager::class); $this->server->addPlugin( new FilesPlugin( @@ -398,6 +401,7 @@ class FilesReportPluginTest extends \Test\TestCase { $this->previewManager, $this->createMock(IUserSession::class), $validator, + $accountManager, ) ); $this->plugin->initialize($this->server); diff --git a/apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue b/apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue index 31b66741698..ec6348606fb 100644 --- a/apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue +++ b/apps/files_sharing/src/views/FilesHeaderNoteToRecipient.vue @@ -6,7 +6,7 @@ <NcNoteCard v-if="note.length > 0" class="note-to-recipient" type="info"> - <p v-if="user" class="note-to-recipient__heading"> + <p v-if="displayName" class="note-to-recipient__heading"> {{ t('files_sharing', 'Note from') }} <NcUserBubble :user="user.id" :display-name="user.displayName" /> </p> @@ -28,13 +28,13 @@ import NcUserBubble from '@nextcloud/vue/components/NcUserBubble' const folder = ref<Folder>() const note = computed<string>(() => folder.value?.attributes.note ?? '') +const displayName = computed<string>(() => folder.value?.attributes['owner-display-name'] ?? '') const user = computed(() => { const id = folder.value?.owner - const displayName = folder.value?.attributes?.['owner-display-name'] if (id !== getCurrentUser()?.uid) { return { id, - displayName, + displayName: displayName.value, } } return null |