Skip to content

Commit 7d4682d

Browse files
authored
Merge pull request #21379 from nextcloud/fix-share-permission-checkboxes-enabled-when-permissions-can-not-be-set
Fix share permission checkboxes enabled when permissions can not be set
2 parents fab1fdc + 3ffb482 commit 7d4682d

File tree

5 files changed

+283
-28
lines changed

5 files changed

+283
-28
lines changed

apps/files_sharing/js/dist/files_sharing_tab.js

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/files_sharing_tab.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/src/components/SharingEntry.vue

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ref="canEdit"
4141
:checked.sync="canEdit"
4242
:value="permissionsEdit"
43-
:disabled="saving">
43+
:disabled="saving || !canSetEdit">
4444
{{ t('files_sharing', 'Allow editing') }}
4545
</ActionCheckbox>
4646

@@ -50,7 +50,7 @@
5050
ref="canCreate"
5151
:checked.sync="canCreate"
5252
:value="permissionsCreate"
53-
:disabled="saving">
53+
:disabled="saving || !canSetCreate">
5454
{{ t('files_sharing', 'Allow creating') }}
5555
</ActionCheckbox>
5656

@@ -60,7 +60,7 @@
6060
ref="canDelete"
6161
:checked.sync="canDelete"
6262
:value="permissionsDelete"
63-
:disabled="saving">
63+
:disabled="saving || !canSetDelete">
6464
{{ t('files_sharing', 'Allow deleting') }}
6565
</ActionCheckbox>
6666

@@ -69,7 +69,7 @@
6969
ref="canReshare"
7070
:checked.sync="canReshare"
7171
:value="permissionsShare"
72-
:disabled="saving">
72+
:disabled="saving || !canSetReshare">
7373
{{ t('files_sharing', 'Allow resharing') }}
7474
</ActionCheckbox>
7575

@@ -216,6 +216,54 @@ export default {
216216
&& this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
217217
},
218218
219+
/**
220+
* Can the sharer set whether the sharee can edit the file ?
221+
*
222+
* @returns {boolean}
223+
*/
224+
canSetEdit() {
225+
// If the owner revoked the permission after the resharer granted it
226+
// the share still has the permission, and the resharer is still
227+
// allowed to revoke it too (but not to grant it again).
228+
return (this.fileInfo.sharePermissions & OC.PERMISSION_UPDATE) || this.canEdit
229+
},
230+
231+
/**
232+
* Can the sharer set whether the sharee can create the file ?
233+
*
234+
* @returns {boolean}
235+
*/
236+
canSetCreate() {
237+
// If the owner revoked the permission after the resharer granted it
238+
// the share still has the permission, and the resharer is still
239+
// allowed to revoke it too (but not to grant it again).
240+
return (this.fileInfo.sharePermissions & OC.PERMISSION_CREATE) || this.canCreate
241+
},
242+
243+
/**
244+
* Can the sharer set whether the sharee can delete the file ?
245+
*
246+
* @returns {boolean}
247+
*/
248+
canSetDelete() {
249+
// If the owner revoked the permission after the resharer granted it
250+
// the share still has the permission, and the resharer is still
251+
// allowed to revoke it too (but not to grant it again).
252+
return (this.fileInfo.sharePermissions & OC.PERMISSION_DELETE) || this.canDelete
253+
},
254+
255+
/**
256+
* Can the sharer set whether the sharee can reshare the file ?
257+
*
258+
* @returns {boolean}
259+
*/
260+
canSetReshare() {
261+
// If the owner revoked the permission after the resharer granted it
262+
// the share still has the permission, and the resharer is still
263+
// allowed to revoke it too (but not to grant it again).
264+
return (this.fileInfo.sharePermissions & OC.PERMISSION_SHARE) || this.canReshare
265+
},
266+
219267
/**
220268
* Can the sharee edit the shared file ?
221269
*/

tests/acceptance/features/app-files-sharing.feature

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,86 @@ Feature: app-files-sharing
294294
And I open the "Sharing" tab in the details view
295295
And I see that the "Sharing" tab in the details view is eventually loaded
296296
And I see that resharing the file is not allowed
297+
298+
Scenario: sharee can not reshare a file with edit permission if the sharer disables it
299+
Given I act as John
300+
And I am logged in as the admin
301+
And I act as Jane
302+
And I am logged in
303+
And I act as John
304+
And I rename "welcome.txt" to "farewell.txt"
305+
And I see that the file list contains a file named "farewell.txt"
306+
And I share "farewell.txt" with "user0"
307+
And I see that the file is shared with "user0"
308+
And I set the share with "user0" as not editable
309+
And I see that "user0" can not edit the share
310+
When I act as Jane
311+
# The Files app is open again to reload the file list
312+
And I open the Files app
313+
And I share "farewell.txt" with "user1"
314+
Then I see that the file is shared with "user1"
315+
And I see that "user1" can not edit the share
316+
And I see that "user1" can not be allowed to edit the share
317+
318+
Scenario: sharee can not reshare a folder with create permission if the sharer disables it
319+
Given I act as John
320+
And I am logged in as the admin
321+
And I act as Jane
322+
And I am logged in
323+
And I act as John
324+
And I create a new folder named "Shared folder"
325+
And I see that the file list contains a file named "Shared folder"
326+
And I share "Shared folder" with "user0"
327+
And I see that the file is shared with "user0"
328+
And I set the share with "user0" as not creatable
329+
And I see that "user0" can not create in the share
330+
When I act as Jane
331+
# The Files app is open again to reload the file list
332+
And I open the Files app
333+
And I share "Shared folder" with "user1"
334+
Then I see that the file is shared with "user1"
335+
And I see that "user1" can not create in the share
336+
And I see that "user1" can not be allowed to create in the share
337+
338+
Scenario: sharee can revoke create permission from reshare after the sharer disabled it
339+
Given I act as John
340+
And I am logged in as the admin
341+
And I act as Jane
342+
And I am logged in
343+
And I act as Jim
344+
And I am logged in as "user1"
345+
And I act as John
346+
And I create a new folder named "Shared folder"
347+
And I see that the file list contains a file named "Shared folder"
348+
And I share "Shared folder" with "user0"
349+
And I see that the file is shared with "user0"
350+
And I act as Jane
351+
# The Files app is open again to reload the file list
352+
And I open the Files app
353+
And I share "Shared folder" with "user1"
354+
And I see that the file is shared with "user1"
355+
And I act as John
356+
And I set the share with "user0" as not creatable
357+
And I see that "user0" can not create in the share
358+
And I act as Jim
359+
# The Files app is open again to reload the file list
360+
And I open the Files app
361+
And I enter in the folder named "Shared folder"
362+
# Creation is still allowed in already created reshares
363+
And I create a new folder named "Subfolder"
364+
And I see that the file list contains a file named "Subfolder"
365+
When I act as Jane
366+
# The Files app is open again to reload the file list
367+
And I open the Files app
368+
And I open the details view for "Shared folder"
369+
And I see that the details view is open
370+
And I open the "Sharing" tab in the details view
371+
And I see that the "Sharing" tab in the details view is eventually loaded
372+
And I set the share with "user1" as not creatable
373+
Then I see that "user1" can not create in the share
374+
And I see that "user1" can not be allowed to create in the share
375+
And I act as Jim
376+
# The Files app is open again to reload the file list
377+
And I open the Files app
378+
And I enter in the folder named "Shared folder"
379+
And I see that it is not possible to create new files

tests/acceptance/features/bootstrap/FilesAppSharingContext.php

Lines changed: 133 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,64 @@ public static function shareWithMenu($sharedWithName) {
103103
/**
104104
* @return Locator
105105
*/
106-
public static function canReshareCheckbox($sharedWithName) {
107-
// forThe()->checkbox("Can reshare") can not be used here; that would
108-
// return the checkbox itself, but the element that the user interacts
109-
// with is the label.
110-
return Locator::forThe()->xpath("//label[normalize-space() = 'Allow resharing']")->
106+
public static function permissionCheckboxFor($sharedWithName, $itemText) {
107+
// forThe()->checkbox($itemText) can not be used here; that would return
108+
// the checkbox itself, but the element that the user interacts with is
109+
// the label.
110+
return Locator::forThe()->xpath("//label[normalize-space() = '$itemText']")->
111111
descendantOf(self::shareWithMenu($sharedWithName))->
112-
describedAs("Allow resharing checkbox in the share with $sharedWithName menu in the details view in Files app");
112+
describedAs("$itemText checkbox in the share with $sharedWithName menu in the details view in Files app");
113113
}
114114

115115
/**
116116
* @return Locator
117117
*/
118-
public static function canReshareCheckboxInput($sharedWithName) {
119-
return Locator::forThe()->checkbox("Allow resharing")->
118+
public static function permissionCheckboxInputFor($sharedWithName, $itemText) {
119+
return Locator::forThe()->checkbox($itemText)->
120120
descendantOf(self::shareWithMenu($sharedWithName))->
121-
describedAs("Allow resharing checkbox input in the share with $sharedWithName menu in the details view in Files app");
121+
describedAs("$itemText checkbox input in the share with $sharedWithName menu in the details view in Files app");
122+
}
123+
124+
/**
125+
* @return Locator
126+
*/
127+
public static function canEditCheckbox($sharedWithName) {
128+
return self::permissionCheckboxFor($sharedWithName, 'Allow editing');
129+
}
130+
131+
/**
132+
* @return Locator
133+
*/
134+
public static function canEditCheckboxInput($sharedWithName) {
135+
return self::permissionCheckboxInputFor($sharedWithName, 'Allow editing');
136+
}
137+
138+
/**
139+
* @return Locator
140+
*/
141+
public static function canCreateCheckbox($sharedWithName) {
142+
return self::permissionCheckboxFor($sharedWithName, 'Allow creating');
143+
}
144+
145+
/**
146+
* @return Locator
147+
*/
148+
public static function canCreateCheckboxInput($sharedWithName) {
149+
return self::permissionCheckboxInputFor($sharedWithName, 'Allow creating');
150+
}
151+
152+
/**
153+
* @return Locator
154+
*/
155+
public static function canReshareCheckbox($sharedWithName) {
156+
return self::permissionCheckboxFor($sharedWithName, 'Allow resharing');
157+
}
158+
159+
/**
160+
* @return Locator
161+
*/
162+
public static function canReshareCheckboxInput($sharedWithName) {
163+
return self::permissionCheckboxInputFor($sharedWithName, 'Allow resharing');
122164
}
123165

124166
/**
@@ -358,6 +400,28 @@ public function iSetThePasswordOfTheSharedLinkAsNotProtectedByTalk() {
358400
$this->actor->find(self::passwordProtectByTalkCheckbox(), 2)->click();
359401
}
360402

403+
/**
404+
* @When I set the share with :shareWithName as not editable
405+
*/
406+
public function iSetTheShareWithAsNotEditable($shareWithName) {
407+
$this->showShareWithMenuIfNeeded($shareWithName);
408+
409+
$this->iSeeThatCanEditTheShare($shareWithName);
410+
411+
$this->actor->find(self::canEditCheckbox($shareWithName), 2)->click();
412+
}
413+
414+
/**
415+
* @When I set the share with :shareWithName as not creatable
416+
*/
417+
public function iSetTheShareWithAsNotCreatable($shareWithName) {
418+
$this->showShareWithMenuIfNeeded($shareWithName);
419+
420+
$this->iSeeThatCanCreateInTheShare($shareWithName);
421+
422+
$this->actor->find(self::canCreateCheckbox($shareWithName), 2)->click();
423+
}
424+
361425
/**
362426
* @When I set the share with :shareWithName as not reshareable
363427
*/
@@ -395,6 +459,66 @@ public function iSeeThatResharingTheFileIsNotAllowed() {
395459
$this->actor->find(self::shareWithInput(), 10)->getWrappedElement()->getAttribute("placeholder"), "Resharing is not allowed");
396460
}
397461

462+
/**
463+
* @Then I see that :sharedWithName can not be allowed to edit the share
464+
*/
465+
public function iSeeThatCanNotBeAllowedToEditTheShare($sharedWithName) {
466+
$this->showShareWithMenuIfNeeded($sharedWithName);
467+
468+
PHPUnit_Framework_Assert::assertEquals(
469+
$this->actor->find(self::canEditCheckboxInput($sharedWithName), 10)->getWrappedElement()->getAttribute("disabled"), "disabled");
470+
}
471+
472+
/**
473+
* @Then I see that :sharedWithName can edit the share
474+
*/
475+
public function iSeeThatCanEditTheShare($sharedWithName) {
476+
$this->showShareWithMenuIfNeeded($sharedWithName);
477+
478+
PHPUnit_Framework_Assert::assertTrue(
479+
$this->actor->find(self::canEditCheckboxInput($sharedWithName), 10)->isChecked());
480+
}
481+
482+
/**
483+
* @Then I see that :sharedWithName can not edit the share
484+
*/
485+
public function iSeeThatCanNotEditTheShare($sharedWithName) {
486+
$this->showShareWithMenuIfNeeded($sharedWithName);
487+
488+
PHPUnit_Framework_Assert::assertFalse(
489+
$this->actor->find(self::canEditCheckboxInput($sharedWithName), 10)->isChecked());
490+
}
491+
492+
/**
493+
* @Then I see that :sharedWithName can not be allowed to create in the share
494+
*/
495+
public function iSeeThatCanNotBeAllowedToCreateInTheShare($sharedWithName) {
496+
$this->showShareWithMenuIfNeeded($sharedWithName);
497+
498+
PHPUnit_Framework_Assert::assertEquals(
499+
$this->actor->find(self::canCreateCheckboxInput($sharedWithName), 10)->getWrappedElement()->getAttribute("disabled"), "disabled");
500+
}
501+
502+
/**
503+
* @Then I see that :sharedWithName can create in the share
504+
*/
505+
public function iSeeThatCanCreateInTheShare($sharedWithName) {
506+
$this->showShareWithMenuIfNeeded($sharedWithName);
507+
508+
PHPUnit_Framework_Assert::assertTrue(
509+
$this->actor->find(self::canCreateCheckboxInput($sharedWithName), 10)->isChecked());
510+
}
511+
512+
/**
513+
* @Then I see that :sharedWithName can not create in the share
514+
*/
515+
public function iSeeThatCanNotCreateInTheShare($sharedWithName) {
516+
$this->showShareWithMenuIfNeeded($sharedWithName);
517+
518+
PHPUnit_Framework_Assert::assertFalse(
519+
$this->actor->find(self::canCreateCheckboxInput($sharedWithName), 10)->isChecked());
520+
}
521+
398522
/**
399523
* @Then I see that :sharedWithName can reshare the share
400524
*/

0 commit comments

Comments
 (0)