Share: cannot find users when sharing mode is groups only
Expected behavior
When trying to share a file or folder in "groups_only" mode, we should be able to find users from the user's own groups or its groups themselves.
Actual behavior
Since 5.0.11, it only allow to search groups or users answer on the same search pattern.
It was working in 5.0.10
Steps to reproduce
- Select groups_only mode in administration
- Create a user "[email protected]" from a group "1234"
- Create a user "[email protected]" from a group "1234"
- Being [email protected], try to share a file with [email protected] searching for "a"
- The user is not found
- Searching for "1" will display the user's group
Fix
It seems that the code in core/ajax/share.php try to search for users in the groups... it found after applying the search pattern.
--- a/core/ajax/share.php 2013-09-19 17:05:59.676756537 +0200
+++ b/core/ajax/share.php 2013-09-27 17:36:48.143608015 +0200
@@ -177,6 +177,7 @@
// }
// }
$groups = OC_Group::getGroups($_GET['search']);
+ $usergroups = array();
if ($sharePolicy == 'groups_only') {
$usergroups = OC_Group::getUserGroups(OC_User::getUser());
$groups = array_intersect($groups, $usergroups);
@@ -188,7 +188,7 @@
while ($count < 15 && count($users) == $limit) {
$limit = 15 - $count;
if ($sharePolicy == 'groups_only') {
- $users = OC_Group::DisplayNamesInGroups($groups, $_GET['search'], $limit, $offset);
+ $users = OC_Group::displayNamesInGroups($usergroups, $_GET['search'], $limit, $offset);
} else {
$users = OC_User::getDisplayNames($_GET['search'], $limit, $offset);
}
I can confirm that this bug is still present in 5.0.12 and this solution fixes the problem.
Thank you nosignleft!
It is already fixed in the stable5 branch and will be released with oc5.0.13. See merged pull request https://github.com/owncloud/core/pull/5211
I have two users that are affected by a bug (?) on a system (oc 7.0.2, nginx, mysql) with about 30 users and three groups. When sharing data or tasks, these two users can't be found by others. Strangely they can see other users of their groups. Group-only-sharing is enabled, sharing to groups is allowed. All relevant users are together in a group so they should be seen by other users in these groups (all the other users can be seen).
That's what I tried so far: I left and rejoined all groups with all depending users (including me) but no change. Then I changed their usernames and passwords and checked their data folders which look good to me. I also deleted and recreated these users from scratch.
any other ideas?
EDIT: If I disable group-only-sharing I can find the two users. The strange thing is, they are definitely in my groups - mysql confirmes that if I look into the "group_user" table.
This is probably the same issue I reported. The cause is simple: the searched list is trimmed before doing the research. So you won't be able to anyone outside of this list, even if someone "excluded" is part of your group.
Yup, that explains it. I saw that 15 entry limit in the code but thought of a pagination feature and didn't look closer... I hope they gonna fix it in the next release.
Do you have a workaround for that issue?
If you don't have thousands of users, you can check my report and temp fix here: #8899
First thing that comes to my mind: Why don't you use Groups.getUsersInGroup($groupId, $limit, $offset)? That function only searches for users in a particular group.
groups = Group.getUserGroups($uid)
foreach ($groups as $group){
$users[] = Group.getUsersInGroup($group);
}
return $users;
If you don't have thousands of groups this might work...? I'm neither a php nor owncloud pro...
For this issue or for the #8899 ?
Anyway, don't forget that the code need to be flexible enough to work with or without the group-only-sharing option and with any group/user backends.