-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor share permissions handling #35884
Conversation
b6abaf2
to
ab8b0af
Compare
Codecov Report
@@ Coverage Diff @@
## master #35884 +/- ##
=============================================
- Coverage 65.8% 49.03% -16.77%
=============================================
Files 1229 109 -1120
Lines 70856 10535 -60321
Branches 1289 1289
=============================================
- Hits 46626 5166 -41460
+ Misses 23852 4991 -18861
Partials 378 378
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #35884 +/- ##
============================================
- Coverage 66.43% 65.44% -0.99%
+ Complexity 20183 20172 -11
============================================
Files 1233 1296 +63
Lines 68965 76359 +7394
Branches 0 1301 +1301
============================================
+ Hits 45814 49972 +4158
- Misses 23151 26002 +2851
- Partials 0 385 +385
Continue to review full report at Codecov.
|
ab8b0af
to
d2bc7fc
Compare
I haven't seen the whole code in depth, but on a general perspective I think it's better to move the permission calculation to a different class, so the share manager can rely on it. This way, we can unittest this new class completely, increase the code coverage, and also simplify the code in the share manager. Side note, I don't like protected methods unless there is a reason for it. |
d2bc7fc
to
c4f5dc5
Compare
When I looking to failing unit tests, I discovered that, when a user shares a file with In this PR's implementation, this bug is also seems resolved. One of the failing test scenarios was using this wrong behavior. I believe, I corrected the test scenario with this commit: c4f5dc5. @phil-davis , @individual-it please correct me, if I am wrong about the intended behaviour on this acceptance test. |
774f53f
to
f47efdb
Compare
Correct, that scenario tried to create a share of a file and give So that scenario should never have worked, because the I will make some tests, in another PR, that test attempting to create a share of a file like that. That will confirm the current (probably wrong) behaviour. Then the work in this PR can correct whatever is wrong. |
@jvillafanez I used protected-private methods to give descriptive names for chunks of code and shorten method lines. The class has also similar protected validate methods. If we move permission calculations to another class, we should move the rest of the validation methods too. However, I'm not sure this effort worths. Recently, we faced lots of issues about share permission calculations. Some of them are still waiting to be resolved. As far as I see, some of the features about permissions are working just in luck and they may have undiscovered bugs. The main focus of this PR is unifying share permission checks and fixing these bugs as I described above. We covered lots of the issues with acceptance tests and the CI is now green. Please, help by reviewing in-depth to do not miss anything. |
PR #35921 has been merged. That adds more share permissions scenarios. |
f47efdb
to
cba2952
Compare
I rebased the PR to test against newly added acceptance tests. Looks like some of them failed. I will have a look what's wrong there. |
cba2952
to
d08cc36
Compare
33f35fc
to
dd72b9f
Compare
Finally, the CI is green again. @phil-davis your review, especially about acceptance tests, would help us to not miss anything in here. There are some changes related to removing default read permission. |
Scenario: sharee comments on upload-only shared file | ||
Given the user has uploaded file "filesForUpload/textfile.txt" to "/myFileToComment.txt" | ||
Scenario: sharee comments on upload-only shared folder | ||
Given the user has created folder "/FOLDER_TO_SHARE" | ||
And the user has created a share with settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the reason for changing this is that the old scenario created a share of a file with only create
permission.
That is not a valid thing to do anyway, and so the When
step was failing anyway, because the share may not have existed at all.
So using a folder in the scenario is better/valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in apps/files_sharing/tests/ShareTest.php
testFileSharePermissions()
the comment says:
shared files should never have delete permissions
but now all the dataProviderTestFileSharePermissions()
cases are true
.
I think that is because $this->share()
now does not throw exceptions like it did before. Maybe the requested delete permission gets masked out and the share is created OK, just without delete permission?
And there could be test cases for PERMISSION_CREATE
also, because that is a special permission that does not apply to sharing a single file.
tests/acceptance/features/apiShareManagementBasic/createShare.feature
Outdated
Show resolved
Hide resolved
tests/acceptance/features/apiShareManagementBasic/createShare.feature
Outdated
Show resolved
Hide resolved
tests/acceptance/features/apiShareManagementBasic/createShare.feature
Outdated
Show resolved
Hide resolved
Congratulations on adjusting all those scenarios, refactoring lots of stuff and also getting green CI! A good example of TDD. |
dd72b9f
to
0868e22
Compare
@phil-davis You are right about your prediction. In this test, shares are created correctly with the current desired behavior. Even so, I changed |
0868e22
to
5611a4d
Compare
No codecov came. I rebased to get a fresh run of CI, and maybe get codecov numbers? |
@phil-davis I guess, we need #35973 for fully green CI. I will rebase this when it merged. |
5611a4d
to
1f88e7b
Compare
1f88e7b
to
c89d230
Compare
Tried two times Codecov is not willing to come. We saw fully green CI before, I guess we can merge this with the power of one of the repo god. |
Description
This PR moves some of the validation on Share20Controlller to the share manager instead and changes permission calculation on re-shares.
Currently, permission handling different for
update
andcreate
share operations, also two different classes(Share20OcsController.php
andManager
) are responsible from this permission checks. This situation causes issues such as a scenario that works well in one operation does not work in another. (https://github.com/owncloud/enterprise/issues/3299 only affectingupdate
share and the another is only affectingcreate
share).In a clean approach, Share manager should take care of all sorts of validations and logics instead of controller. I unified these logics under Share Manager and applied this unified checks for both
update
andcreate
operations.Also, with this PR re-share permission will be calculated based on share permission of re-share mount point node's.
IMHO, most of the permission exceptions should return
403
. However, to keep acceptance test and behavior changes minimal, I did not touch return codes and I kept them as it is.I removed many unit tests. Some of them were duplicate and redundant. I will add more unit tests after reviews.
Share API, no longer set read permission as default. Clients should include this permission to their requests. We need to test this behavior on clients to ensure there is no regression.
Related Issue
fixes https://github.com/owncloud/enterprise/issues/3299
fixes https://github.com/owncloud/enterprise/issues/3404
fixes #35922
Motivation and Context
To get rid of from bugs. To have a cleaner code. Next time we will know where we should look at on a share permission issue.
How Has This Been Tested?
Acceptance tests, Also it resolves described scenarios in these tickets:
Types of changes
Checklist:
Open tasks: