@@ -188,6 +188,93 @@ public function testGetContactsWithoutAvatarURI(): void {
188188 $ this ->assertEquals ('https://photo ' , $ entries [1 ]->getAvatar ());
189189 }
190190
191+ public static function dataGetContactsWhenUserIsInExcludeGroups (): array {
192+ return [
193+ ['yes ' , '[] ' , [], ['user123 ' , 'user12345 ' ]],
194+ ['yes ' , '["excludedGroup1"] ' , [], ['user123 ' , 'user12345 ' ]],
195+ ['yes ' , '["excludedGroup1"] ' , ['anotherGroup1 ' ], ['user123 ' , 'user12345 ' ]],
196+ ['yes ' , '["excludedGroup1"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
197+ ['yes ' , '["excludedGroup1"] ' , ['excludedGroup1 ' ], []],
198+ ['yes ' , '["excludedGroup1"] ' , ['anotherGroup1 ' , 'excludedGroup1 ' ], []],
199+ ['yes ' , '["excludedGroup1"] ' , ['excludedGroup1 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], []],
200+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , [], ['user123 ' , 'user12345 ' ]],
201+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['anotherGroup1 ' ], ['user123 ' , 'user12345 ' ]],
202+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
203+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup1 ' ], []],
204+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup2 ' ], []],
205+ ['yes ' , '["excludedGroup1", "excludedGroup2", "excludedGroup3"] ' , ['excludedGroup3 ' ], []],
206+ ['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 ' ], []],
210+ ['allow ' , '[] ' , [], []],
211+ ['allow ' , '["allowedGroup1"] ' , [], []],
212+ ['allow ' , '["allowedGroup1"] ' , ['anotherGroup1 ' ], []],
213+ ['allow ' , '["allowedGroup1"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], []],
214+ ['allow ' , '["allowedGroup1"] ' , ['allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
215+ ['allow ' , '["allowedGroup1"] ' , ['anotherGroup1 ' , 'allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
216+ ['allow ' , '["allowedGroup1"] ' , ['allowedGroup1 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
217+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , [], []],
218+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' ], []],
219+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], []],
220+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
221+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup2 ' ], ['user123 ' , 'user12345 ' ]],
222+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup3 ' ], ['user123 ' , 'user12345 ' ]],
223+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup1 ' , 'allowedGroup2 ' , 'allowedGroup3 ' ], ['user123 ' , 'user12345 ' ]],
224+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' , 'allowedGroup1 ' ], ['user123 ' , 'user12345 ' ]],
225+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['anotherGroup1 ' , 'allowedGroup2 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
226+ ['allow ' , '["allowedGroup1", "allowedGroup2", "allowedGroup3"] ' , ['allowedGroup3 ' , 'anotherGroup1 ' , 'anotherGroup2 ' , 'anotherGroup3 ' ], ['user123 ' , 'user12345 ' ]],
227+ ];
228+ }
229+
230+ #[\PHPUnit \Framework \Attributes \DataProvider('dataGetContactsWhenUserIsInExcludeGroups ' )]
231+ public function testGetContactsWhenUserIsInExcludeGroups (string $ excludeGroups , string $ excludeGroupsList , array $ currentUserGroupIds , array $ expectedUids ): void {
232+ $ this ->config
233+ ->method ('getAppValue ' )
234+ ->willReturnMap ([
235+ ['core ' , 'shareapi_allow_share_dialog_user_enumeration ' , 'yes ' , 'yes ' ],
236+ ['core ' , 'shareapi_restrict_user_enumeration_to_group ' , 'no ' , 'no ' ],
237+ ['core ' , 'shareapi_restrict_user_enumeration_to_phone ' , 'no ' , 'no ' ],
238+ ['core ' , 'shareapi_exclude_groups ' , 'no ' , $ excludeGroups ],
239+ ['core ' , 'shareapi_only_share_with_group_members ' , 'no ' , 'no ' ],
240+ ['core ' , 'shareapi_exclude_groups_list ' , '' , $ excludeGroupsList ],
241+ ['core ' , 'shareapi_only_share_with_group_members_exclude_group_list ' , '' , '[] ' ],
242+ ]);
243+
244+ /** @var IUser|MockObject $currentUser */
245+ $ currentUser = $ this ->createMock (IUser::class);
246+ $ currentUser ->expects ($ this ->exactly (2 ))
247+ ->method ('getUID ' )
248+ ->willReturn ('user001 ' );
249+
250+ $ this ->groupManager ->expects ($ this ->once ())
251+ ->method ('getUserGroupIds ' )
252+ ->with ($ this ->equalTo ($ currentUser ))
253+ ->willReturn ($ currentUserGroupIds );
254+
255+ $ this ->contactsManager ->expects ($ this ->once ())
256+ ->method ('search ' )
257+ ->with ($ this ->equalTo ('' ), $ this ->equalTo (['FN ' , 'EMAIL ' ]))
258+ ->willReturn ([
259+ [
260+ 'UID ' => 'user123 ' ,
261+ 'isLocalSystemBook ' => true
262+ ],
263+ [
264+ 'UID ' => 'user12345 ' ,
265+ 'isLocalSystemBook ' => true
266+ ],
267+ ]);
268+
269+
270+ $ entries = $ this ->contactsStore ->getContacts ($ currentUser , '' );
271+
272+ $ this ->assertCount (count ($ expectedUids ), $ entries );
273+ for ($ i = 0 ; $ i < count ($ expectedUids ); $ i ++) {
274+ $ this ->assertEquals ($ expectedUids [$ i ], $ entries [$ i ]->getProperty ('UID ' ));
275+ }
276+ }
277+
191278 public function testGetContactsOnlyShareIfInTheSameGroupWhenUserIsInExcludeGroups (): void {
192279 $ this ->config
193280 ->method ('getAppValue ' )
0 commit comments