Skip to content
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

fix restore behavior of the trashbin API #1795

Merged
merged 5 commits into from
Jun 23, 2021
Merged

Conversation

C0rby
Copy link
Contributor

@C0rby C0rby commented Jun 15, 2021

  • The precondition were not checked before doing a trashbin restore in the ownCloud dav API. Without the checks the API would behave differently compared to the oC10 API.
  • The restore response was missing HTTP headers like ETag

@C0rby C0rby requested a review from labkode as a code owner June 15, 2021 11:31
@C0rby C0rby requested review from butonic and refs June 15, 2021 11:31
@C0rby C0rby self-assigned this Jun 15, 2021
@C0rby
Copy link
Contributor Author

C0rby commented Jun 15, 2021

The CI had some issues but I can't restart the build.

@C0rby
Copy link
Contributor Author

C0rby commented Jun 15, 2021

@phil-davis, I think the tests in core for this are currently wrong IMO.
https://github.com/owncloud/core/blob/510bc012ae25da69730f2de6ed94ad725a6be49a/tests/acceptance/features/apiTrashbin/trashbinRestore.feature#L96-L119

In particular https://github.com/owncloud/core/blob/510bc012ae25da69730f2de6ed94ad725a6be49a/tests/acceptance/features/apiTrashbin/trashbinRestore.feature#L107.

Both backends, oC10 and with this PR oCIS too, delete the conflicting file, which then lands in the trashbin. I.e. effectively the two files change places and in the end there should still be a file with the upload-path in the trashbin.

What do you think?

@C0rby C0rby marked this pull request as draft June 15, 2021 15:11
@C0rby C0rby marked this pull request as ready for review June 16, 2021 14:17
butonic
butonic previously approved these changes Jun 17, 2021
@phil-davis
Copy link
Contributor

What do you think?

When this scenario was being run on oC10 it had 2 different behaviors and I could not sort out a test that would give a consistent result. Read issue owncloud/core#35974 - sometimes the restore from trashbin overwrites the existing file, and the existing file is found in the trashbin. That seems a reasonable behavior (but one could argue that the existing file should end up in the version history).

But sometimes the existing file is not overwritten. The trashbin restore API request returns a "good" HTTP status, but actually the original file is still there, and actually the API request "did nothing".

I will try enabling this again on oC10 and see if the variable results still happen. Then we need to decide what the system is supposed to do in this case.

@C0rby C0rby changed the title check preconditions for ocdav trashbin restore requests fix restore behavior of the trashbin API Jun 21, 2021
@phil-davis
Copy link
Contributor

core PR owncloud/core#38869 has cleaned-up the scenario.
We will get #1801 to bump the core commit id so that the testing is using that adjusted scenario. Then it should be easier to get that scenario passing.

@phil-davis
Copy link
Contributor

@C0rby #1801 has been merged - now you get conflicts for free :)

@C0rby
Copy link
Contributor Author

C0rby commented Jun 21, 2021

Oh nice. I'll resolve that tomorrow. 👍

@C0rby C0rby force-pushed the trashbin-restore branch 3 times, most recently from 60f9342 to 76e63c6 Compare June 22, 2021 13:51
Copy link
Contributor

@phil-davis phil-davis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. Well done getting a number of scenarios out of expected-failures.

Comment on lines +455 to +457
if delRes.Status.Code != rpc.Code_CODE_OK && delRes.Status.Code != rpc.Code_CODE_NOT_FOUND {
HandleErrorStatus(&sublog, w, delRes.Status)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this will handle the case where the restore wants to overwrite an existing resource, but the user does not have delete access to the resource.

And it might be more tricky if the user has change access to the resource, but not delete access. client.Delete will probably refuse, but actually the end-effect that we want is to just overwrite. IMO this is also a hassle in oC10 - the back-end code has a similar flow where it deletes the resource first, then adds the restored resource. That kind of edge-case is something for a future PR...

Copy link
Member

@refs refs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, essentially restoring from the trash bin branches if:

  1. a resource in the restore destination exists and overwrite=T
  2. a resource in the restore destination exists and overwrite=F
  3. the restore destination is available

case 1 will delete the reference on dst and call RestoreRecycleItem
case 2 will fail because the precondition does not pass: destination exists and overwrite is false (precondition = destination location is free)
case 3 will succeed as it is the opposite to case 2

looks good to me!

@labkode
Copy link
Member

labkode commented Jun 23, 2021

Just to add more into the fire, what about this scenario?

I deleted /a/b/c/e.txt
I removed /a

When restoring e.txt as a user I'd expect the hierarchy recreated and maybe asked about the possibility to choose where the restore will happen? original location and hierarchy recreated or another place?

@phil-davis
Copy link
Contributor

phil-davis commented Jun 23, 2021

https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiTrashbin/trashbinRestore.feature currently has scenarios that use the API to restore e.txt to a place specified in the API call (the caller has to say where to restore it, and IMO the target folder has to already exist)

I don't see scenarios for when the restore does not specify the target, and the original folder has been deleted. I should add scenarios for that, so that we at least know how oC10 behaves and can decide what to do! Issue owncloud/core#38882 - more test scenarios will come...

But this PR is definitely a great step forward - lots of existing scenarios pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants