aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-10-14 19:10:12 +0200
committerGitHub <noreply@github.com>2024-10-14 19:10:12 +0200
commitb964e053125fb03fd9c90c4faceb138ed4039421 (patch)
treebb82c275742e2c79b43e03c9696d75b2f34d2cfc
parent3d2039f04104c7ad2ae90dd646cfc7880b2c4b17 (diff)
parent64dd4ce0ee2ebbf4937a106dfd6c0fde2c961213 (diff)
downloadnextcloud-server-b964e053125fb03fd9c90c4faceb138ed4039421.tar.gz
nextcloud-server-b964e053125fb03fd9c90c4faceb138ed4039421.zip
Merge pull request #48673 from nextcloud/fix/null-label
fix(share): Return empty string if no label is set
-rw-r--r--apps/files_sharing/lib/ResponseDefinitions.php2
-rw-r--r--apps/files_sharing/openapi.json3
-rw-r--r--lib/private/Share20/DefaultShareProvider.php4
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php34
4 files changed, 38 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/ResponseDefinitions.php b/apps/files_sharing/lib/ResponseDefinitions.php
index 774e4c17e00..d412b93a135 100644
--- a/apps/files_sharing/lib/ResponseDefinitions.php
+++ b/apps/files_sharing/lib/ResponseDefinitions.php
@@ -29,7 +29,7 @@ namespace OCA\Files_Sharing;
* 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 362e9aefc32..9f38223bca3 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",
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index 3ea429dfe3d..af993b7f314 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -991,7 +991,7 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
))
- ->execute();
+ ->executeQuery();
$data = $cursor->fetch();
@@ -1024,7 +1024,7 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
->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 5bed54cc18f..5effaea8cf9 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -884,6 +884,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
'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 @@ class DefaultShareProviderTest extends \Test\TestCase {
$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(): void {
$this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);