X Tutup
Skip to content

Delete the correct expired share and handle user/group shares on ExpiredSharesJob#37729

Merged
karakayasemi merged 2 commits intomasterfrom
expire-share-job
Jul 30, 2020
Merged

Delete the correct expired share and handle user/group shares on ExpiredSharesJob#37729
karakayasemi merged 2 commits intomasterfrom
expire-share-job

Conversation

@karakayasemi
Copy link
Contributor

@karakayasemi karakayasemi commented Jul 26, 2020

Description

Delete the correct expired share by using share id on ExpireSharesJob. ExpireSharesJob now 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

ExpiredSharesJobs currently uses \OCP\Share::unshare method 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, ExpireSharesJob now 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@karakayasemi karakayasemi added this to the development milestone Jul 26, 2020
@karakayasemi karakayasemi self-assigned this Jul 26, 2020
@update-docs
Copy link

update-docs bot commented Jul 26, 2020

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.

@karakayasemi karakayasemi marked this pull request as ready for review July 26, 2020 13:54
@codecov
Copy link

codecov bot commented Jul 26, 2020

Codecov Report

Merging #37729 into master will decrease coverage by 0.00%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             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              
Flag Coverage Δ Complexity Δ
#javascript 54.03% <ø> (ø) 0.00 <ø> (ø)
#phpunit 65.89% <87.50%> (-0.01%) 19387.00 <1.00> (+1.00) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
lib/private/Share20/Manager.php 96.19% <ø> (ø) 273.00 <0.00> (ø)
apps/files_sharing/lib/ExpireSharesJob.php 95.45% <87.50%> (-4.55%) 4.00 <1.00> (+1.00) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f447f0...5f9cdc9. Read the comment docs.

@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
@owncloud owncloud deleted a comment from codecov bot Jul 26, 2020
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']);
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

core/lib/private/Server.php

Lines 877 to 880 in 6038c8e

$config = $c->getConfig();
$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
/** @var \OCP\Share\IProviderFactory $factory */
$factory = new $factoryClass($this);

IMHO, for now, using the default share provider is the best option even it has \OC namespace.

@micbar
Copy link
Contributor

micbar commented Jul 27, 2020

@karakayasemi Can you add a changelog plse?

@karakayasemi karakayasemi force-pushed the expire-share-job branch 3 times, most recently from 56e993f to 442929f Compare July 27, 2020 18:02
@karakayasemi
Copy link
Contributor Author

karakayasemi commented Jul 27, 2020

Changelog has been added. @jvillafanez ready to review again. Some tests are failed in Postgres. I will look at it.

@karakayasemi karakayasemi force-pushed the expire-share-job branch 3 times, most recently from 0e205ea to 08389d9 Compare July 27, 2020 18:54
@owncloud owncloud deleted a comment from codecov bot Jul 27, 2020
@jvillafanez
Copy link
Member

Code looks good 👍

@karakayasemi
Copy link
Contributor Author

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, returnValueMap did not work in Postgres and Postgres tests failed.

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, IShareProvider expects share id as integer, in fact, its implementations also cast share id to integer when they setting id to any IShare instance. In contrast, setId method of Share implementation casts incoming integer argument to string.

if (\is_int($id)) {
$id = (string)$id;
}

So, I corrected IShareProvider's getShareById method description and removed the unnecessary casting operation from IShareProvider implementations.

@codecov
Copy link

codecov bot commented Jul 28, 2020

Codecov Report

Merging #37729 into master will decrease coverage by 0.00%.
The diff coverage is 90.90%.

Impacted file tree graph

@@             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              
Flag Coverage Δ Complexity Δ
#javascript 54.03% <ø> (ø) 0.00 <ø> (ø)
#phpunit 65.89% <90.90%> (-0.01%) 19387.00 <1.00> (+1.00) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
lib/private/Share20/Manager.php 96.19% <ø> (ø) 273.00 <0.00> (ø)
apps/files_sharing/lib/ExpireSharesJob.php 95.65% <88.88%> (-4.35%) 4.00 <1.00> (+1.00) ⬇️
...ederatedfilesharing/lib/FederatedShareProvider.php 63.36% <100.00%> (ø) 94.00 <0.00> (ø)
lib/private/Share20/DefaultShareProvider.php 97.74% <100.00%> (ø) 120.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c19d083...8afe84d. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Jul 28, 2020

Codecov Report

Merging #37729 into master will decrease coverage by 0.00%.
The diff coverage is 90.90%.

Impacted file tree graph

@@             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              
Flag Coverage Δ Complexity Δ
#javascript 54.03% <ø> (ø) 0.00 <ø> (ø)
#phpunit 65.89% <90.90%> (-0.01%) 19387.00 <1.00> (+1.00) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
lib/private/Share20/Manager.php 96.19% <ø> (ø) 273.00 <0.00> (ø)
apps/files_sharing/lib/ExpireSharesJob.php 95.65% <88.88%> (-4.35%) 4.00 <1.00> (+1.00) ⬇️
...ederatedfilesharing/lib/FederatedShareProvider.php 63.36% <100.00%> (ø) 94.00 <0.00> (ø)
lib/private/Share20/DefaultShareProvider.php 97.74% <100.00%> (ø) 120.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c19d083...8afe84d. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 28, 2020

Codecov Report

Merging #37729 into master will decrease coverage by 0.00%.
The diff coverage is 90.90%.

Impacted file tree graph

@@             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              
Flag Coverage Δ Complexity Δ
#javascript 54.03% <ø> (ø) 0.00 <ø> (ø)
#phpunit 65.89% <90.90%> (-0.01%) 19387.00 <1.00> (+1.00) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
lib/private/Share20/Manager.php 96.19% <ø> (ø) 273.00 <0.00> (ø)
apps/files_sharing/lib/ExpireSharesJob.php 95.65% <88.88%> (-4.35%) 4.00 <1.00> (+1.00) ⬇️
...ederatedfilesharing/lib/FederatedShareProvider.php 63.36% <100.00%> (ø) 94.00 <0.00> (ø)
lib/private/Share20/DefaultShareProvider.php 97.74% <100.00%> (ø) 120.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24b305a...c58fe67. Read the comment docs.

@jvillafanez
Copy link
Member

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:

  • Doctrine is likely fetching an integer, which is stored as string in the object because of the type checking done in the setId method of the share.
  • We aren't actively setting any id to any share. We're only set the id when we create the object from the DB.
  • There are checks in place to prevent changing the id after being set.

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'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@karakayasemi
Copy link
Contributor Author

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 IShare getId method always returns string, Phpunit's returnValueMap method configuration did not work for Postgres.

@jvillafanez
Copy link
Member

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.
I'm fine with the fix, but include a comment explaining the situation, specially mentioning mysql and postgresql, so we can remember this problem in the future and prevent breaking the same thing again. In addition, it would make easier to know what we need to check if we touch something around this.

@karakayasemi
Copy link
Contributor Author

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.

@karakayasemi
Copy link
Contributor Author

Project coverage was not enough. Added a test to increase coverage.

@karakayasemi karakayasemi merged commit 38ab9fb into master Jul 30, 2020
@delete-merged-branch delete-merged-branch bot deleted the expire-share-job branch July 30, 2020 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup