Skip to content

Commit 359a780

Browse files
authored
Merge pull request #62989 from nextcloud/unified-sharing-list-type-hints
fix: improve type hinting for unified share listing methods
2 parents 1bb3698 + 995ac97 commit 359a780

7 files changed

Lines changed: 19 additions & 6 deletions

File tree

apps/sharing/lib/Controller/ApiV1Controller.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public function getShare(string $id, ?string $secret = null, array $arguments =
557557
* Get multiple shares.
558558
*
559559
* @param ?class-string<IShareSourceType> $filterSourceTypeClass Source type class to filter by.
560-
* @param ?string $filterSourceTypeValue Source type value to filter by.
560+
* @param ?non-empty-string $filterSourceTypeValue Source type value to filter by.
561561
* @param ?string $lastShareID The ID of the previous share. This is used as an offset and only shares with higher IDs are returned.
562562
* @param int<1, 100> $limit The number of shares to return.
563563
* @return DataResponse<Http::STATUS_OK, list<SharingShare>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, string, array{}>
@@ -578,6 +578,15 @@ public function getShares(?string $filterSourceTypeClass, ?string $filterSourceT
578578
return new DataResponse('The limit is too high.', Http::STATUS_BAD_REQUEST);
579579
}
580580

581+
/** @psalm-suppress TypeDoesNotContainType */
582+
if ($filterSourceTypeValue === '') {
583+
return new DataResponse('Filter source value is empty.', Http::STATUS_BAD_REQUEST);
584+
}
585+
586+
if ($filterSourceTypeClass && !isset($this->registry->getSourceTypes()[$filterSourceTypeClass])) {
587+
return new DataResponse('The filter source type is not registered: ' . $filterSourceTypeClass, Http::STATUS_BAD_REQUEST);
588+
}
589+
581590
try {
582591
$this->dbConnection->beginTransaction();
583592

apps/sharing/openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,8 @@
31103110
"description": "Source type value to filter by.",
31113111
"schema": {
31123112
"type": "string",
3113-
"nullable": true
3113+
"nullable": true,
3114+
"minLength": 1
31143115
}
31153116
},
31163117
{

apps/sharing/tests/Controller/ApiV1ControllerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
declare(strict_types=1);
99

1010
use NCU\Sharing\ISharingManager;
11-
use NCU\Sharing\ISharingRegistry;
1211
use NCU\Sharing\Permission\SharePermission;
1312
use NCU\Sharing\Property\ShareProperty;
1413
use NCU\Sharing\Recipient\ShareRecipient;
@@ -47,7 +46,7 @@ public function testDefaultShareAccessContext(): void {
4746
Server::get(IRequest::class),
4847
Server::get(IUserSession::class),
4948
Server::get(ISharingManager::class),
50-
Server::get(ISharingRegistry::class),
49+
$this->registry,
5150
Server::get(IFactory::class),
5251
Server::get(IURLGenerator::class),
5352
Server::get(IUserManager::class),
@@ -68,7 +67,7 @@ private function executeRequest(ShareAccessContext $accessContext, Closure $clos
6867
Server::get(IRequest::class),
6968
Server::get(IUserSession::class),
7069
Server::get(ISharingManager::class),
71-
Server::get(ISharingRegistry::class),
70+
$this->registry,
7271
Server::get(IFactory::class),
7372
Server::get(IURLGenerator::class),
7473
Server::get(IUserManager::class),

lib/private/Sharing/SharingBackend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ private function hideDisabledUserShares(): bool {
556556

557557
/**
558558
* @param ?class-string<IShareSourceType> $filterSourceTypeClass
559+
* @param ?non-empty-string $filterSourceTypeValue
559560
* @return list<Share>
560561
*/
561562
private function list(ShareAccessContext $accessContext, ?string $filterShareID, ?string $filterSourceTypeClass, ?string $filterSourceTypeValue, ?string $lastShareID, ?int $limit): array {

lib/unstable/Sharing/ISharingBackend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public function getShare(ShareAccessContext $accessContext, string $id): Share;
174174
* Get multiple shares.
175175
*
176176
* @param ?class-string<IShareSourceType> $filterSourceTypeClass
177+
* @param ?non-empty-string $filterSourceTypeValue
177178
* @param ?positive-int $limit
178179
* @return list<Share>
179180
* @experimental 35.0.0

lib/unstable/Sharing/ISharingManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public function getShare(ShareAccessContext $accessContext, string $id): Share;
216216
* Get multiple shares.
217217
*
218218
* @param ?class-string<IShareSourceType> $filterSourceTypeClass
219+
* @param ?non-empty-string $filterSourceTypeValue
219220
* @param ?positive-int $limit
220221
* @return list<Share>
221222
* @experimental 35.0.0

openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39006,7 +39006,8 @@
3900639006
"description": "Source type value to filter by.",
3900739007
"schema": {
3900839008
"type": "string",
39009-
"nullable": true
39009+
"nullable": true,
39010+
"minLength": 1
3901039011
}
3901139012
},
3901239013
{

0 commit comments

Comments
 (0)