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

[sharing] fix addToGroup hook #17381

Merged
merged 2 commits into from
Jul 21, 2015
Merged

[sharing] fix addToGroup hook #17381

merged 2 commits into from
Jul 21, 2015

Conversation

schiessle
Copy link
Contributor

Fix the add to group hook in sharing. This was discovered while working on #17327

We skip this step completely for file shares because for file shares we generate a unique target during the mount operation if needed. Further we make sure that the code gets executed at all. In the old version "$sourcrExists" was always true because we checked it in a post hook. So we always found a share for the user after he was added to the group.

cc @rullzer maybe you have some time to review it? Thanks!

@schiessle schiessle added this to the 8.1.1-next-maintenance milestone Jul 3, 2015
@schiessle
Copy link
Contributor Author

cc @blizzz maybe you can also have a look as we discussed the issue earlier today.

'`file_source`' => $insert->expr()->literal($item['file_source']),
]
);
$insert->execute();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work correctly when you run execute multiple times? Since you keep the original $insert object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should work because we replace the values on the object for each execute()... but I will double-check.

@rullzer
Copy link
Contributor

rullzer commented Jul 4, 2015

Looks good. But I would really like unit tests here.
It is a bit unintuitive that we do this stuff somewhere else for files...

@schiessle
Copy link
Contributor Author

It is a bit unintuitive that we do this stuff somewhere else for files...

For files we need to check anyway on every mount for potential name collisions and resolve it if it happens. Because on a external storage someone could create a file with the same name, the next time you login to you ownCloud the share needs to be moved to a unique name.

Also I think it is better for performance reasons on a per user basis if needed instead of checking it for all users during the share operation. Most likely I would remove this logic completely from a share API 2.0 and let the back-end handle it, like it is already done by sharing.

@schiessle
Copy link
Contributor Author

Hm, tests fail for the same reason it didn't worked for files. We are in a post-hook. This means that the user is already a member of the group. If we now ask for all shares we will already get the new group share, detect a collision and generate a new target "test1.txt". I don't see a way to fix this for the tests. Don't know why this works for address books... will look deeper into it.

Update: it seems to work for contact because contact only compares the target with the local address books of the recipient but not with other shared address books. So it is basically a bug in contacts which makes it work.

@schiessle
Copy link
Contributor Author

@rullzer please have another look, I changed the approach based on #17381 (comment)

We now have a pre-hook to calculate the unique target name and a post-hook to add it to the table

@rullzer
Copy link
Contributor

rullzer commented Jul 6, 2015

Ignore that last one... I'll have another look :)

$item['stime'], $item['file_source'], $fileTarget));
\OC_DB::insertid('*PREFIX*share');
if (($fileTarget === null && $itemTarget != $item['item_target']) ||
($fileTarget !== null && $fileTarget !== $item['file_target'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

coding style: please put || at the beginning of the new line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@blizzz
Copy link
Contributor

blizzz commented Jul 6, 2015

The code itself looks good, and also I really appreciate the tests. Is there anything specific to test manually (steps)?

@schiessle
Copy link
Contributor Author

Following steps can be used to test the correct behavior:

  • create admin, user2, user3 and user4
  • add user2 to group "users"
  • admin shares a file test.txt with the group "users"
  • login as user3
  • user3 also creates a test.txt
  • admin adds user3 to the group "users"

Now check the oc_share table in the database. With this patch you should see a extra row for the group share for user3 with a target "test.txt (2)" or similar because we created a unique name for him.

  • admin adds user4 to the group "users"

Now check the oc_share table in the database. No additional row for the group share for user4 should have been created.

Note: It is important that you check the db directly after adding user3 (user4) to the group. If user3 (user4) log-in we will detect the name collision and create a unique target for him. So after login everything will look the same with or without the patch.

targets before the user was added to the group otherwise we will always detect
a name collision
@scrutinizer-notifier
Copy link

A new inspection was created.

@ghost
Copy link

ghost commented Jul 6, 2015

🚀 Test PASSed.🚀
chuck

@rullzer
Copy link
Contributor

rullzer commented Jul 7, 2015

I assume this has to go into 8.2?

@rullzer
Copy link
Contributor

rullzer commented Jul 7, 2015

Code looks good
I also checked your example case and that works as expected!

Probably hard to add that tests to the testsuite?

Otherwise 👍

@MorrisJobke MorrisJobke modified the milestones: 8.2-current, 8.1.1-current-maintenance Jul 9, 2015
@schiessle
Copy link
Contributor Author

needs a second reviewer... @nickvergessen ? Thanks!

@MorrisJobke
Copy link
Contributor

👍

MorrisJobke added a commit that referenced this pull request Jul 21, 2015
@MorrisJobke MorrisJobke merged commit 2d691c2 into master Jul 21, 2015
@MorrisJobke MorrisJobke deleted the fix_sharing_add_to_group branch July 21, 2015 11:30
@MorrisJobke
Copy link
Contributor

@schiesbn What about the backport to stable8.1? This was only merged against master.

@MorrisJobke
Copy link
Contributor

@schiesbn Ping

@MorrisJobke
Copy link
Contributor

@schiesbn You filed this ticket for 8.1.1 and this is against master, so you need to create a backport.

@MorrisJobke
Copy link
Contributor

@lock lock bot locked as resolved and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants