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

Listen to federated share accept event #131

Merged
merged 2 commits into from
Aug 6, 2019

Conversation

sharidas
Copy link
Contributor

Listen to the federated share accept event
and add the accepted share to the background
job.

Signed-off-by: Sujith H sharidasan@owncloud.com

@sharidas
Copy link
Contributor Author

Description

Listen to the accept event triggered for the federated share. Prior to this change the events were not listened hence no background jobs for the same were triggered. Hence the share data was not updated in the search. With this change the event is listened and the share user is added to the background job to update the content.

By the time the event is listened the view of the user is not udpated with the accepted share. It happens when the share is accepted and the dav request is triggered. Once the dav request is tirggered we get sufficient time to execute the background job.

Issue

Test done

  • Create a user user1 in the server1
  • From server2 send a federated share say file1.txt to user1 of server1.
  • When user1 of server1 accepts the federeated share the background job is added. Its been verified by looking into the jobs table.
  • Run the occ system:cron. Verified the contents of file1.txt of user1 (of server1) are displayed in the search.

@codecov
Copy link

codecov bot commented Jul 31, 2019

Codecov Report

Merging #131 into release-1.0.0 will increase coverage by 0.26%.
The diff coverage is 22%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##             release-1.0.0     #131      +/-   ##
===================================================
+ Coverage            19.32%   19.59%   +0.26%     
+ Complexity             273      271       -2     
===================================================
  Files                   24       24              
  Lines                 1190     1230      +40     
===================================================
+ Hits                   230      241      +11     
- Misses                 960      989      +29
Impacted Files Coverage Δ Complexity Δ
lib/Hooks/Files.php 7.35% <0%> (-2%) 19 <16> (-2)
lib/Application.php 88.39% <100%> (+1.26%) 22 <0> (ø) ⬇️

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 ddfe8c2...41f726b. Read the comment docs.

@sharidas sharidas requested a review from VicDeo July 31, 2019 06:46
@davitol
Copy link

davitol commented Jul 31, 2019

Tested and works 👍

* @param AcceptShare $acceptShare
*/
public static function federatedShareUpdate(AcceptShare $acceptShare) {
$share = $acceptShare->getShare();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we use the status mapper here?
Please use the same logic like in the contentChanged method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While looking into the issue, my first thought was to proceed using logic like contentChanged method. But then I found an issue with accessing nodes like for example \OC::$server->getUserFolder($share['user'])->get($share['name']). And I found that the node was not there. And then I found that a PROPFIND request is made for the user, after the share is accepted and then the nodes are available. Hence I thought we can add the background job for the user, instead of using the logic of contentChanged. Let me know if this makes sense? @micbar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

So we depend on the webUI making the propfind before the cronjob runs? This is ugly.
@VicDeo Any Ideas?

Copy link
Member

@VicDeo VicDeo Jul 31, 2019

Choose a reason for hiding this comment

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

By design federated shares are neither scanned nor updated before user browses inside due to performance reasons.
That's why we added owncloud/core#34933 to sync them manually by cron.

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 have updated the PR with trashbin and version restore.

@sharidas sharidas force-pushed the listen-fedshare-acceptevent branch 3 times, most recently from f7152d5 to 8f61a4f Compare July 31, 2019 14:15
@jvillafanez
Copy link
Member

For the trashbin and version hooks, I'd create different functions. There is also common functionality that can be reused in the contentChange function.

From what I see, the contentChange can be seen as "getNode" + "processNode". This "processNode" is the common part that can be moved to a private function and be reused, while the "getNode" is specific for each event.
Basically, I'd create a different hook for each event in order to get the related node, and then call this "processNode" function, which will be the same.

What we get with these changes is a more streamlined flow. I expect less conditions to check, which leads to less unittests to do in order to cover all scenarios.

So we depend on the webUI making the propfind before the cronjob runs? This is ugly.

This is something we can't guarantee, so we musn't rely on that.

@sharidas sharidas force-pushed the listen-fedshare-acceptevent branch 2 times, most recently from 2108cab to eed7b79 Compare August 1, 2019 12:37
@sharidas
Copy link
Contributor Author

sharidas commented Aug 1, 2019

Updated the PR.
The initial observation with PROPFIND helping list the node, was not correct. The \OC_Util::setupFS() was doing the trick. So I have updated the code to have a tearDown and setupFS call for the user which receives the share.

lib/Hooks/Files.php Outdated Show resolved Hide resolved
lib/Hooks/Files.php Outdated Show resolved Hide resolved
* update to have the federated share added.
*/
\OC_Util::tearDownFS();
\OC_Util::setupFS($share['user']);
Copy link
Member

Choose a reason for hiding this comment

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

Doble-check FS operations after this hook is run are executed using the previous user, not the one shared. We might need to restore the previous user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its run against the recipient of the fed share, and its not done against the sender of the share.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to include a comment.

Normally, you'd use \OC_Util::setupFS() to setup the FS for the user in the session, and \OC_Util::setupFS($user) if you need to explicitly setup the FS for a different user. At this point in the code, we might assume that we have the FS for the session user available, so it's fine to tearDown the FS.

Now, if we use \OC_Util::setupFS($share['user']), I assume that $share['user'] might not be the user in the session but a different user. If this is the case, I think we should restore the previous user.
We have to assume this callback won't be last to access to the FS. If after this callback is executed there are more calls to the FS, these calls will be run against the $share['user']'s FS, which as said, it could be a different user.

return;
}

public static function processNode($node, $userIdReceiver = null) {
Copy link
Member

Choose a reason for hiding this comment

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

Why the $userIdReceiver can be null? or, why the $userIdReceiver is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the method. Now it accepts userId. There is a check which I have made for @ in the code.

@sharidas sharidas force-pushed the listen-fedshare-acceptevent branch 2 times, most recently from 35180f4 to 5051a76 Compare August 1, 2019 16:40
@micbar micbar force-pushed the listen-fedshare-acceptevent branch from 5051a76 to 5eb28e4 Compare August 1, 2019 19:27
Listen to the federated share accept event,
trashbin restore event and file version restore event
and process the event to add it to the background
job.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas force-pushed the listen-fedshare-acceptevent branch from 5eb28e4 to 16a88cc Compare August 2, 2019 07:01
* update to have the federated share added.
*/
\OC_Util::tearDownFS();
\OC_Util::setupFS($share['user']);
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to include a comment.

Normally, you'd use \OC_Util::setupFS() to setup the FS for the user in the session, and \OC_Util::setupFS($user) if you need to explicitly setup the FS for a different user. At this point in the code, we might assume that we have the FS for the session user available, so it's fine to tearDown the FS.

Now, if we use \OC_Util::setupFS($share['user']), I assume that $share['user'] might not be the user in the session but a different user. If this is the case, I think we should restore the previous user.
We have to assume this callback won't be last to access to the FS. If after this callback is executed there are more calls to the FS, these calls will be run against the $share['user']'s FS, which as said, it could be a different user.

lib/Hooks/Files.php Outdated Show resolved Hide resolved
@sharidas sharidas force-pushed the listen-fedshare-acceptevent branch from 16a88cc to 41f726b Compare August 2, 2019 08:15
@sharidas
Copy link
Contributor Author

sharidas commented Aug 2, 2019

Regarding #131 (comment) I have updated the setupFS to execute on the currently logged in user. Because the recipient of the remote share is the currently logged in user.

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

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

code looks good

@sharidas
Copy link
Contributor Author

sharidas commented Aug 2, 2019

Not sure why codecov is responding.

@sharidas sharidas merged commit d6ef1d2 into release-1.0.0 Aug 6, 2019
@delete-merged-branch delete-merged-branch bot deleted the listen-fedshare-acceptevent branch August 6, 2019 09:20
@micbar micbar mentioned this pull request Aug 26, 2019
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.

6 participants