Skip to content

Commit d617f88

Browse files
Merge pull request #59794 from nextcloud/backport/59792/stable32
2 parents fa5e37e + 9ff02f6 commit d617f88

5 files changed

Lines changed: 46 additions & 8 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
class ShareAPIController extends OCSController {
7878

7979
private ?Node $lockedNode = null;
80+
/** @var array<bool> $trustedServerCache */
8081
private array $trustedServerCache = [];
8182

8283
/**
@@ -237,6 +238,10 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
237238
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
238239
}
239240

241+
$currentUserPermissions = $recipientNode?->getPermissions() ?? Constants::PERMISSION_ALL;
242+
$userHasEnoughPermissions = ($currentUserPermissions & $share->getPermissions()) === $share->getPermissions();
243+
$token = $userHasEnoughPermissions ? $share->getToken() : null;
244+
240245
if ($share->getShareType() === IShare::TYPE_USER) {
241246
$sharedWith = $this->userManager->get($share->getSharedWith());
242247
$result['share_with'] = $share->getSharedWith();
@@ -262,6 +267,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
262267
$result['share_with'] = $share->getSharedWith();
263268
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
264269
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
270+
$url = $token ? $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]) : null;
265271

266272
// "share_with" and "share_with_displayname" for passwords of link
267273
// shares was deprecated in Nextcloud 15, use "password" instead.
@@ -272,23 +278,23 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
272278

273279
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
274280

275-
$result['token'] = $share->getToken();
276-
$result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]);
281+
$result['token'] = $token;
282+
$result['url'] = $url;
277283
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
278284
$result['share_with'] = $share->getSharedWith();
279285
$result['share_with_displayname'] = $this->getCachedFederatedDisplayName($share->getSharedWith());
280-
$result['token'] = $share->getToken();
286+
$result['token'] = $token;
281287
} elseif ($share->getShareType() === IShare::TYPE_REMOTE_GROUP) {
282288
$result['share_with'] = $share->getSharedWith();
283289
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD');
284-
$result['token'] = $share->getToken();
290+
$result['token'] = $token;
285291
} elseif ($share->getShareType() === IShare::TYPE_EMAIL) {
286292
$result['share_with'] = $share->getSharedWith();
287293
$result['password'] = $share->getPassword();
288294
$result['password_expiration_time'] = $share->getPasswordExpirationTime() !== null ? $share->getPasswordExpirationTime()->format(\DateTime::ATOM) : null;
289295
$result['send_password_by_talk'] = $share->getSendPasswordByTalk();
290296
$result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
291-
$result['token'] = $share->getToken();
297+
$result['token'] = $token;
292298
} elseif ($share->getShareType() === IShare::TYPE_CIRCLE) {
293299
// getSharedWith() returns either "name (type, owner)" or
294300
// "name (type, owner) [id]", depending on the Teams app version.

apps/files_sharing/lib/ResponseDefinitions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* token: ?string,
5555
* uid_file_owner: string,
5656
* uid_owner: string,
57-
* url?: string,
57+
* url?: string|null,
5858
* }
5959
*
6060
* @psalm-type Files_SharingDeletedShare = array{

apps/files_sharing/openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,8 @@
700700
"type": "string"
701701
},
702702
"url": {
703-
"type": "string"
703+
"type": "string",
704+
"nullable": true
704705
}
705706
}
706707
},

build/integration/sharing_features/sharing-v1-part2.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@ Feature: sharing
2323
And User "user2" should be included in the response
2424
And User "user3" should not be included in the response
2525

26+
Scenario: getting all shares of a file with reshares with link share with less permissions
27+
Given user "user0" exists
28+
And user "user1" exists
29+
When as "user0" creating a share with
30+
| path | textfile0.txt |
31+
| shareType | 0 |
32+
| shareWith | user1 |
33+
| permissions | 17 |
34+
Then the OCS status code should be "100"
35+
And the HTTP status code should be "200"
36+
When as "user0" creating a share with
37+
| path | textfile0.txt |
38+
| shareType | 3 |
39+
| permissions | 19 |
40+
Then the OCS status code should be "100"
41+
And the HTTP status code should be "200"
42+
And last link share can be downloaded
43+
When As an "user1"
44+
And sending "GET" to "/apps/files_sharing/api/v1/shares?reshares=true&path=textfile0 (2).txt"
45+
Then the OCS status code should be "100"
46+
And the HTTP status code should be "200"
47+
And User "user1" should not be included in the response
48+
Then the list of returned shares has 1 shares
49+
And share 0 is returned with
50+
| share_type | 3 |
51+
| uid_owner | user0 |
52+
| token | |
53+
| url | |
54+
| permissions | 19 |
55+
2656
Scenario: getting all shares of a file with a received share after revoking the resharing rights
2757
Given user "user0" exists
2858
And user "user1" exists

openapi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2798,7 +2798,8 @@
27982798
"type": "string"
27992799
},
28002800
"url": {
2801-
"type": "string"
2801+
"type": "string",
2802+
"nullable": true
28022803
}
28032804
}
28042805
},

0 commit comments

Comments
 (0)