Skip to content

Commit fbe2023

Browse files
committed
fix: Unify handling of exclude groups in contacts menu and sharing
If the current user belongs to both one or more groups excluded from sharing and one or more groups not excluded from sharing the user is allowed to share. However, in the contacts menu, as soon as the current user belonged to a group excluded from sharing the user could not search for local contacts. This has been unified now with the sharing behaviour, so local contacts can still be searched if the user also belongs to a group not excluded from sharing (or to no group at all, which was also allowed before). Signed-off-by: Daniel Calviño Sánchez <[email protected]>
1 parent d59d8db commit fbe2023

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

build/integration/features/contacts-menu.feature

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Feature: contacts-menu
103103
And searching for contacts matching with "test"
104104
Then the list of searched contacts has "0" contacts
105105

106-
Scenario: users can not be searched by display name when searcher belongs to both a group excluded from sharing and another group
106+
Scenario: users can be searched by display name when searcher belongs to both a group excluded from sharing and another group
107107
Given user "user0" exists
108108
And group "ExcludedGroup" exists
109109
And user "user0" belongs to group "ExcludedGroup"
@@ -118,9 +118,10 @@ Feature: contacts-menu
118118
| value | Test name |
119119
When Logging in using web as "user0"
120120
And searching for contacts matching with "test"
121-
Then the list of searched contacts has "0" contacts
121+
Then the list of searched contacts has "1" contacts
122+
And searched contact "0" is named "Test name"
122123

123-
Scenario: users can not be searched by email when searcher belongs to both a group excluded from sharing and another group
124+
Scenario: users can be searched by email when searcher belongs to both a group excluded from sharing and another group
124125
Given user "user0" exists
125126
And group "ExcludedGroup" exists
126127
And user "user0" belongs to group "ExcludedGroup"
@@ -135,7 +136,8 @@ Feature: contacts-menu
135136
| value | test@example.com |
136137
When Logging in using web as "user0"
137138
And searching for contacts matching with "test"
138-
Then the list of searched contacts has "0" contacts
139+
Then the list of searched contacts has "1" contacts
140+
And searched contact "0" is named "user1"
139141

140142
Scenario: users can not be searched by display name when searcher does not belong to a group allowed to share
141143
Given user "user0" exists

lib/private/Contacts/ContactsMenu/ContactsStore.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?i
149149
* 1. if the `shareapi_allow_share_dialog_user_enumeration` config option is
150150
* enabled it will filter all local users
151151
* 2. if the `shareapi_exclude_groups` config option is enabled and the
152-
* current user is in an excluded group it will filter all local users.
152+
* current user is only in excluded groups it will filter all local users.
153153
* 3. if the `shareapi_only_share_with_group_members` config option is
154154
* enabled it will filter all users which doesn't have a common group
155155
* with the current user.
@@ -184,8 +184,8 @@ private function filterContacts(
184184
$excludeGroupsList = $decodedExcludeGroups ?? [];
185185

186186
if ($excludeGroups != 'allow') {
187-
if (count(array_intersect($excludeGroupsList, $selfGroups)) !== 0) {
188-
// a group of the current user is excluded -> filter all local users
187+
if (count($selfGroups) > 0 && count(array_diff($selfGroups, $excludeGroupsList)) === 0) {
188+
// all the groups of the current user are excluded -> filter all local users
189189
$skipLocal = true;
190190
}
191191
} else {

tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,18 @@ public static function dataGetContactsWhenUserIsInExcludeGroups(): array {
195195
['yes', '["excludedGroup1"]', ['anotherGroup1'], ['user123', 'user12345']],
196196
['yes', '["excludedGroup1"]', ['anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
197197
['yes', '["excludedGroup1"]', ['excludedGroup1'], []],
198-
['yes', '["excludedGroup1"]', ['anotherGroup1', 'excludedGroup1'], []],
199-
['yes', '["excludedGroup1"]', ['excludedGroup1', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], []],
198+
['yes', '["excludedGroup1"]', ['anotherGroup1', 'excludedGroup1'], ['user123', 'user12345']],
199+
['yes', '["excludedGroup1"]', ['excludedGroup1', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
200200
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', [], ['user123', 'user12345']],
201201
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1'], ['user123', 'user12345']],
202202
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
203203
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup1'], []],
204204
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup2'], []],
205205
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup3'], []],
206206
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup1', 'excludedGroup2', 'excludedGroup3'], []],
207-
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'excludedGroup1'], []],
208-
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'excludedGroup2', 'anotherGroup2', 'anotherGroup3'], []],
209-
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup3', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], []],
207+
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'excludedGroup1'], ['user123', 'user12345']],
208+
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['anotherGroup1', 'excludedGroup2', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
209+
['yes', '["excludedGroup1", "excludedGroup2", "excludedGroup3"]', ['excludedGroup3', 'anotherGroup1', 'anotherGroup2', 'anotherGroup3'], ['user123', 'user12345']],
210210
['allow', '[]', [], []],
211211
['allow', '["allowedGroup1"]', [], []],
212212
['allow', '["allowedGroup1"]', ['anotherGroup1'], []],

0 commit comments

Comments
 (0)