Delete the correct expired share and handle user/group shares on ExpiredSharesJob#37729
Delete the correct expired share and handle user/group shares on ExpiredSharesJob#37729karakayasemi merged 2 commits intomasterfrom
Conversation
|
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
Codecov Report
@@ Coverage Diff @@
## master #37729 +/- ##
============================================
- Coverage 64.71% 64.71% -0.01%
- Complexity 19386 19387 +1
============================================
Files 1283 1283
Lines 75730 75731 +1
Branches 1333 1333
============================================
Hits 49008 49008
- Misses 26330 26331 +1
Partials 392 392
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| while ($share = $shares->fetch()) { | ||
| \OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']); | ||
| try { | ||
| $share = $this->shareManager->getShareById('ocinternal:' . $share['id']); |
There was a problem hiding this comment.
Any alternative to avoid using "ocinternal:"? It shouldn't be known from the outside.
If it isn't possible, we should include a comment so we could find and adjust this piece of code in case the identifier changes.
There was a problem hiding this comment.
Ideally, we need to inject \OCP\Share\IProviderFactory and get the correct share provider for share_type from it. However, IProviderFactory can not auto-injectable and manually creating it a bit tricky. See
Lines 877 to 880 in 6038c8e
IMHO, for now, using the default share provider is the best option even it has \OC namespace.
|
@karakayasemi Can you add a changelog plse? |
56e993f to
442929f
Compare
|
Changelog has been added. |
0e205ea to
08389d9
Compare
08389d9 to
726357e
Compare
|
Code looks good 👍 |
5642c23 to
8afe84d
Compare
|
share id is coming as integer in a pgsql database, but, it is coming as string in all the other supported databases. Because of that, The failing tests opened a can of worms about share id inconsistency. Share id is supposed to be a string according to its interface description. However, core/lib/private/Share20/Share.php Lines 95 to 97 in 378d38a So, I corrected |
Codecov Report
@@ Coverage Diff @@
## master #37729 +/- ##
============================================
- Coverage 64.71% 64.71% -0.01%
- Complexity 19386 19387 +1
============================================
Files 1283 1283
Lines 75732 75734 +2
Branches 1333 1333
============================================
+ Hits 49009 49010 +1
- Misses 26331 26332 +1
Partials 392 392
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #37729 +/- ##
============================================
- Coverage 64.71% 64.71% -0.01%
- Complexity 19386 19387 +1
============================================
Files 1283 1283
Lines 75732 75734 +2
Branches 1333 1333
============================================
+ Hits 49009 49010 +1
- Misses 26331 26332 +1
Partials 392 392
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #37729 +/- ##
============================================
- Coverage 64.71% 64.71% -0.01%
- Complexity 19386 19387 +1
============================================
Files 1283 1283
Lines 75735 75737 +2
Branches 1333 1333
============================================
+ Hits 49011 49012 +1
- Misses 26332 26333 +1
Partials 392 392
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
Could you double-check the type of the DB column in postgresql? At least in mysql, I see the "id" as int column. I guess this works due to how we're using it, not due to it's properly implemented:
My worry is the interaction being the share object and the DB. If the object has a string but the DB requires an integer, it's either Doctrine or the actual DB the one making an automatic type conversion. |
| */ | ||
| private function createShareObject($data) { | ||
| $share = new Share($this->rootFolder, $this->userManager); | ||
| $share->setId((int)$data['id']) |
There was a problem hiding this comment.
setId expects string. Casting the parameter to integer does not make sense in any case here.
| * Get share by id | ||
| * | ||
| * @param int $id | ||
| * @param string $id |
There was a problem hiding this comment.
I can revert this change and cast incoming share id to an integer when I call this method in ExpireSharesJob to ensure consistency between databases.
|
Share id is integer in Postgres like Mysql also. But, when we query this column, DBAL converts integer id's to string on all the supported databases except Postgres, probably due to possible overflow reasons. I checked one more time. Since |
|
I think this only happens here. I mean, we're using the ids from other tables in other places and it works fine I guess. |
8afe84d to
a8ea321
Compare
|
This id string/integer inconcistency more likely happen in other tables but doctrine/dbal handling these cases without problem. I guess, there is no other test case that configures a stub method with id parameter comes from database. That's why we did not notice before. @jvillafanez, thank you for review. I added a comment that explain why we used type casting. |
…. ExpireSharesJob now also handles user and group shares.
a8ea321 to
c58fe67
Compare
|
Project coverage was not enough. Added a test to increase coverage. |
Description
Delete the correct expired share by using share id on
ExpireSharesJob.ExpireSharesJobnow also handles user and group shares.I created the pr based on @pako81 in https://github.com/owncloud/enterprise/issues/4112#issuecomment-662842454.
Related Issue
Motivation and Context
ExpiredSharesJobscurrently uses\OCP\Share::unsharemethod for deleting expired shares.If multiple links exist for the same node and, non-expired share created before expired share, expiredSharesJob currently deletes non-expired share.
This problem resolved with deleting correct expired shares by using share id.
Also,
ExpireSharesJobnow handles user and group shares. If we prefer, I can separate this part of the change to another pr.How Has This Been Tested?
The class has an integration test. Also, tried manually.
Screenshots (if appropriate):
Types of changes
Checklist: