Skip to content

Commit ca474ef

Browse files
authored
Merge pull request #47893 from nextcloud/backport/47339/stable28
[stable28] fix: Display 'Leave share' instead of 'Delete'
2 parents 8500f0d + 903f717 commit ca474ef

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,27 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
190190
if ($isOwnShare) {
191191
$result['item_permissions'] = $node->getPermissions();
192192
}
193+
194+
// If we're on the recipient side, the node permissions
195+
// are bound to the share permissions. So we need to
196+
// adjust the permissions to the share permissions if necessary.
197+
if (!$isOwnShare) {
198+
$result['item_permissions'] = $share->getPermissions();
199+
200+
// For some reason, single files share are forbidden to have the delete permission
201+
// since we have custom methods to check those, let's adjust straight away.
202+
// DAV permissions does not have that issue though.
203+
if ($this->canDeleteShare($share) || $this->canDeleteShareFromSelf($share)) {
204+
$result['item_permissions'] |= Constants::PERMISSION_DELETE;
205+
}
206+
if ($this->canEditShare($share)) {
207+
$result['item_permissions'] |= Constants::PERMISSION_UPDATE;
208+
}
209+
}
210+
211+
// See MOUNT_ROOT_PROPERTYNAME dav property
212+
$result['is-mount-root'] = $node->getInternalPath() === '';
213+
$result['mount-type'] = $node->getMountPoint()->getMountType();
193214

194215
$result['mimetype'] = $node->getMimetype();
195216
$result['has_preview'] = $this->previewManager->isAvailable($node);

apps/files_sharing/lib/ResponseDefinitions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* file_target: string,
4040
* has_preview: bool,
4141
* hide_download: 0|1,
42+
* is-mount-root: bool,
4243
* id: string,
4344
* item_mtime: int,
4445
* item_permissions?: int,
@@ -48,6 +49,7 @@
4849
* label: string,
4950
* mail_send: 0|1,
5051
* mimetype: string,
52+
* mount-type: string,
5153
* note: string,
5254
* parent: null,
5355
* password?: string,

apps/files_sharing/openapi.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@
480480
"file_target",
481481
"has_preview",
482482
"hide_download",
483+
"is-mount-root",
483484
"id",
484485
"item_mtime",
485486
"item_size",
@@ -488,6 +489,7 @@
488489
"label",
489490
"mail_send",
490491
"mimetype",
492+
"mount-type",
491493
"note",
492494
"parent",
493495
"path",
@@ -543,6 +545,9 @@
543545
1
544546
]
545547
},
548+
"is-mount-root": {
549+
"type": "boolean"
550+
},
546551
"id": {
547552
"type": "string"
548553
},
@@ -591,6 +596,9 @@
591596
"mimetype": {
592597
"type": "string"
593598
},
599+
"mount-type": {
600+
"type": "string"
601+
},
594602
"note": {
595603
"type": "string"
596604
},

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,6 +3757,12 @@ public function dataFormatShare() {
37573757
$folder->method('getStorage')->willReturn($storage);
37583758
$fileWithPreview->method('getStorage')->willReturn($storage);
37593759

3760+
3761+
$mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
3762+
$mountPoint->method('getMountType')->willReturn('');
3763+
$file->method('getMountPoint')->willReturn($mountPoint);
3764+
$folder->method('getMountPoint')->willReturn($mountPoint);
3765+
37603766
$owner = $this->getMockBuilder(IUser::class)->getMock();
37613767
$owner->method('getDisplayName')->willReturn('ownerDN');
37623768
$initiator = $this->getMockBuilder(IUser::class)->getMock();
@@ -3911,6 +3917,8 @@ public function dataFormatShare() {
39113917
'can_delete' => false,
39123918
'item_size' => 123456,
39133919
'item_mtime' => 1234567890,
3920+
'is-mount-root' => false,
3921+
'mount-type' => '',
39143922
'attributes' => null,
39153923
], $share, [], false
39163924
];
@@ -3962,6 +3970,8 @@ public function dataFormatShare() {
39623970
'can_delete' => true,
39633971
'item_size' => 123456,
39643972
'item_mtime' => 1234567890,
3973+
'is-mount-root' => false,
3974+
'mount-type' => '',
39653975
'attributes' => null,
39663976
], $share, [], false
39673977
];
@@ -4014,6 +4024,8 @@ public function dataFormatShare() {
40144024
'can_delete' => false,
40154025
'item_size' => 123456,
40164026
'item_mtime' => 1234567890,
4027+
'is-mount-root' => false,
4028+
'mount-type' => '',
40174029
'attributes' => null,
40184030
], $share, [], false
40194031
];
@@ -4063,6 +4075,8 @@ public function dataFormatShare() {
40634075
'can_delete' => false,
40644076
'item_size' => 123456,
40654077
'item_mtime' => 1234567890,
4078+
'is-mount-root' => false,
4079+
'mount-type' => '',
40664080
'attributes' => null,
40674081
], $share, [], false
40684082
];
@@ -4119,6 +4133,8 @@ public function dataFormatShare() {
41194133
'can_delete' => false,
41204134
'item_size' => 123456,
41214135
'item_mtime' => 1234567890,
4136+
'is-mount-root' => false,
4137+
'mount-type' => '',
41224138
'attributes' => null,
41234139
], $share, [], false
41244140
];
@@ -4175,6 +4191,8 @@ public function dataFormatShare() {
41754191
'can_delete' => false,
41764192
'item_size' => 123456,
41774193
'item_mtime' => 1234567890,
4194+
'is-mount-root' => false,
4195+
'mount-type' => '',
41784196
'attributes' => null,
41794197
], $share, [], false
41804198
];
@@ -4225,6 +4243,8 @@ public function dataFormatShare() {
42254243
'can_delete' => false,
42264244
'item_size' => 123456,
42274245
'item_mtime' => 1234567890,
4246+
'is-mount-root' => false,
4247+
'mount-type' => '',
42284248
'attributes' => null,
42294249
], $share, [], false
42304250
];
@@ -4275,6 +4295,8 @@ public function dataFormatShare() {
42754295
'can_delete' => false,
42764296
'item_size' => 123456,
42774297
'item_mtime' => 1234567890,
4298+
'is-mount-root' => false,
4299+
'mount-type' => '',
42784300
'attributes' => null,
42794301
], $share, [], false
42804302
];
@@ -4328,6 +4350,8 @@ public function dataFormatShare() {
43284350
'can_delete' => false,
43294351
'item_size' => 123456,
43304352
'item_mtime' => 1234567890,
4353+
'is-mount-root' => false,
4354+
'mount-type' => '',
43314355
'attributes' => null,
43324356
], $share, [], false
43334357
];
@@ -4378,6 +4402,8 @@ public function dataFormatShare() {
43784402
'can_delete' => false,
43794403
'item_size' => 123456,
43804404
'item_mtime' => 1234567890,
4405+
'is-mount-root' => false,
4406+
'mount-type' => '',
43814407
'attributes' => null,
43824408
], $share, [], false
43834409
];
@@ -4428,6 +4454,8 @@ public function dataFormatShare() {
44284454
'can_delete' => false,
44294455
'item_size' => 123456,
44304456
'item_mtime' => 1234567890,
4457+
'is-mount-root' => false,
4458+
'mount-type' => '',
44314459
'attributes' => null,
44324460
], $share, [], false
44334461
];
@@ -4495,6 +4523,8 @@ public function dataFormatShare() {
44954523
'password_expiration_time' => null,
44964524
'item_size' => 123456,
44974525
'item_mtime' => 1234567890,
4526+
'is-mount-root' => false,
4527+
'mount-type' => '',
44984528
'attributes' => null,
44994529
], $share, [], false
45004530
];
@@ -4548,6 +4578,8 @@ public function dataFormatShare() {
45484578
'password_expiration_time' => null,
45494579
'item_size' => 123456,
45504580
'item_mtime' => 1234567890,
4581+
'is-mount-root' => false,
4582+
'mount-type' => '',
45514583
'attributes' => null,
45524584
], $share, [], false
45534585
];
@@ -4599,6 +4631,8 @@ public function dataFormatShare() {
45994631
'can_delete' => true,
46004632
'item_size' => 123456,
46014633
'item_mtime' => 1234567890,
4634+
'is-mount-root' => false,
4635+
'mount-type' => '',
46024636
'attributes' => null,
46034637
], $share, [], false
46044638
];
@@ -4702,6 +4736,10 @@ public function dataFormatRoomShare() {
47024736
$file->method('getSize')->willReturn(123456);
47034737
$file->method('getMTime')->willReturn(1234567890);
47044738

4739+
$mountPoint = $this->getMockBuilder(IMountPoint::class)->getMock();
4740+
$mountPoint->method('getMountType')->willReturn('');
4741+
$file->method('getMountPoint')->willReturn($mountPoint);
4742+
47054743
$cache = $this->getMockBuilder('OCP\Files\Cache\ICache')->getMock();
47064744
$cache->method('getNumericStorageId')->willReturn(100);
47074745
$storage = $this->createMock(Storage::class);
@@ -4757,6 +4795,8 @@ public function dataFormatRoomShare() {
47574795
'can_delete' => false,
47584796
'item_size' => 123456,
47594797
'item_mtime' => 1234567890,
4798+
'is-mount-root' => false,
4799+
'mount-type' => '',
47604800
'attributes' => null,
47614801
], $share, false, []
47624802
];
@@ -4806,6 +4846,8 @@ public function dataFormatRoomShare() {
48064846
'can_delete' => false,
48074847
'item_size' => 123456,
48084848
'item_mtime' => 1234567890,
4849+
'is-mount-root' => false,
4850+
'mount-type' => '',
48094851
'attributes' => null,
48104852
], $share, true, [
48114853
'share_with_displayname' => 'recipientRoomName'

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,86 @@ Scenario: Creating a new share of a file you own shows the file permissions
3939
And the HTTP status code should be "200"
4040
And Share fields of last share match with
4141
| item_permissions | 27 |
42+
43+
Scenario: Receiving a share of a file gives no create permission
44+
Given user "user0" exists
45+
And user "user1" exists
46+
And As an "user0"
47+
And parameter "shareapi_default_permissions" of app "core" is set to "31"
48+
And file "welcome.txt" of user "user0" is shared with user "user1"
49+
And sending "GET" to "/apps/files_sharing/api/v1/shares"
50+
And share 0 is returned with
51+
| path | /welcome.txt |
52+
| permissions | 19 |
53+
| item_permissions | 27 |
54+
When As an "user1"
55+
And user "user1" accepts last share
56+
And sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true"
57+
Then the list of returned shares has 1 shares
58+
And share 0 is returned with
59+
| path | /welcome (2).txt |
60+
| permissions | 19 |
61+
| item_permissions | 27 |
62+
63+
Scenario: Receiving a share of a folder gives create permission
64+
Given user "user0" exists
65+
And user "user1" exists
66+
And As an "user0"
67+
And parameter "shareapi_default_permissions" of app "core" is set to "31"
68+
And file "PARENT/CHILD" of user "user0" is shared with user "user1"
69+
And sending "GET" to "/apps/files_sharing/api/v1/shares"
70+
And share 0 is returned with
71+
| path | /PARENT/CHILD |
72+
| permissions | 31 |
73+
| item_permissions | 31 |
74+
When As an "user1"
75+
And user "user1" accepts last share
76+
And sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true"
77+
Then the list of returned shares has 1 shares
78+
And share 0 is returned with
79+
| path | /CHILD |
80+
| permissions | 31 |
81+
| item_permissions | 31 |
82+
83+
# User can remove itself from a share
84+
Scenario: Receiving a share of a file without delete permission gives delete permission anyway
85+
Given user "user0" exists
86+
And user "user1" exists
87+
And As an "user0"
88+
And parameter "shareapi_default_permissions" of app "core" is set to "23"
89+
And file "welcome.txt" of user "user0" is shared with user "user1"
90+
And sending "GET" to "/apps/files_sharing/api/v1/shares"
91+
And share 0 is returned with
92+
| path | /welcome.txt |
93+
| permissions | 19 |
94+
| item_permissions | 27 |
95+
When As an "user1"
96+
And user "user1" accepts last share
97+
And sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true"
98+
Then the list of returned shares has 1 shares
99+
And share 0 is returned with
100+
| path | /welcome (2).txt |
101+
| permissions | 19 |
102+
| item_permissions | 27 |
103+
104+
Scenario: Receiving a share of a file without delete permission gives delete permission anyway
105+
Given user "user0" exists
106+
And user "user1" exists
107+
And As an "user0"
108+
And group "group1" exists
109+
And user "user1" belongs to group "group1"
110+
And parameter "shareapi_default_permissions" of app "core" is set to "23"
111+
And file "welcome.txt" of user "user0" is shared with group "group1"
112+
And sending "GET" to "/apps/files_sharing/api/v1/shares"
113+
And share 0 is returned with
114+
| path | /welcome.txt |
115+
| permissions | 19 |
116+
| item_permissions | 27 |
117+
When As an "user1"
118+
And user "user1" accepts last share
119+
And sending "GET" to "/apps/files_sharing/api/v1/shares?shared_with_me=true"
120+
Then the list of returned shares has 1 shares
121+
And share 0 is returned with
122+
| path | /welcome (2).txt |
123+
| permissions | 19 |
124+
| item_permissions | 27 |

0 commit comments

Comments
 (0)