From dfe8f642cdd9b0da29f03ec9607a385cfc3d53d6 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 12 Oct 2024 17:51:56 +0200 Subject: [PATCH 1/2] fix(share): Return empty string if no label is set * Resolves: https://github.com/nextcloud/server/issues/48629 While the database supports NULL, the typing has always said it only returns *string*. So to not break any apps that might trust the typings we should return `''` if the database is set to `NULL`. Signed-off-by: Ferdinand Thiessen --- lib/private/Share20/DefaultShareProvider.php | 4 +-- .../lib/Share20/DefaultShareProviderTest.php | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 7ed4aeefe8f1c..e0ff2ff703858 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -988,7 +988,7 @@ public function getShareByToken($token) { $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) )) - ->execute(); + ->executeQuery(); $data = $cursor->fetch(); @@ -1021,7 +1021,7 @@ private function createShare($data) { ->setNote((string)$data['note']) ->setMailSend((bool)$data['mail_send']) ->setStatus((int)$data['accepted']) - ->setLabel($data['label']); + ->setLabel($data['label'] ?? ''); $shareTime = new \DateTime(); $shareTime->setTimestamp((int)$data['stime']); diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index e498d497427cc..e89157d29b23d 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -884,6 +884,7 @@ public function testGetShareByToken() { 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13), 'token' => $qb->expr()->literal('secrettoken'), + 'label' => $qb->expr()->literal('the label'), ]); $qb->execute(); $id = $qb->getLastInsertId(); @@ -899,10 +900,43 @@ public function testGetShareByToken() { $this->assertSame('sharedBy', $share->getSharedBy()); $this->assertSame('secrettoken', $share->getToken()); $this->assertSame('password', $share->getPassword()); + $this->assertSame('the label', $share->getLabel()); $this->assertSame(true, $share->getSendPasswordByTalk()); $this->assertSame(null, $share->getSharedWith()); } + /** + * Assert that if no label is provided the label is correctly, + * as types on IShare, a string and not null + */ + public function testGetShareByTokenNullLabel(): void { + $qb = $this->dbConn->getQueryBuilder(); + + $qb->insert('share') + ->values([ + 'share_type' => $qb->expr()->literal(IShare::TYPE_LINK), + 'password' => $qb->expr()->literal('password'), + 'password_by_talk' => $qb->expr()->literal(true), + 'uid_owner' => $qb->expr()->literal('shareOwner'), + 'uid_initiator' => $qb->expr()->literal('sharedBy'), + 'item_type' => $qb->expr()->literal('file'), + 'file_source' => $qb->expr()->literal(42), + 'file_target' => $qb->expr()->literal('myTarget'), + 'permissions' => $qb->expr()->literal(13), + 'token' => $qb->expr()->literal('secrettoken'), + ]); + $qb->executeStatement(); + $id = $qb->getLastInsertId(); + + $file = $this->createMock(File::class); + + $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); + $this->rootFolder->method('getFirstNodeById')->with(42)->willReturn($file); + + $share = $this->provider->getShareByToken('secrettoken'); + $this->assertEquals($id, $share->getId()); + $this->assertSame('', $share->getLabel()); + } public function testGetShareByTokenNotFound() { $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class); From d7d6874242fa98335bd93e2436e1edc15e9c8a72 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 14 Oct 2024 15:16:13 +0200 Subject: [PATCH 2/2] revert: "fix(files_sharing): Make share labels nullable" This reverts commit 01c4fa3ba8a7311da331e6a2b70fc866b0a9b39c. Signed-off-by: Ferdinand Thiessen --- apps/files_sharing/lib/ResponseDefinitions.php | 2 +- apps/files_sharing/openapi.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/lib/ResponseDefinitions.php b/apps/files_sharing/lib/ResponseDefinitions.php index 774e4c17e001b..d412b93a1355d 100644 --- a/apps/files_sharing/lib/ResponseDefinitions.php +++ b/apps/files_sharing/lib/ResponseDefinitions.php @@ -29,7 +29,7 @@ * item_size: float|int, * item_source: int, * item_type: 'file'|'folder', - * label: ?string, + * label: string, * mail_send: 0|1, * mimetype: string, * mount-type: string, diff --git a/apps/files_sharing/openapi.json b/apps/files_sharing/openapi.json index c5777e0253998..4932a7e14e447 100644 --- a/apps/files_sharing/openapi.json +++ b/apps/files_sharing/openapi.json @@ -583,8 +583,7 @@ ] }, "label": { - "type": "string", - "nullable": true + "type": "string" }, "mail_send": { "type": "integer",