@@ -63,8 +63,10 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
6363 $ users = [];
6464 $ hasMoreResults = false ;
6565
66- $ currentUserId = $ this ->userSession ->getUser ()->getUID ();
67- $ currentUserGroups = $ this ->groupManager ->getUserGroupIds ($ this ->userSession ->getUser ());
66+ /** @var IUser */
67+ $ currentUser = $ this ->userSession ->getUser ();
68+ $ currentUserId = $ currentUser ->getUID ();
69+ $ currentUserGroups = $ this ->groupManager ->getUserGroupIds ($ currentUser );
6870
6971 // ShareWithGroupOnly filtering
7072 $ currentUserGroups = array_diff ($ currentUserGroups , $ this ->shareWithGroupOnlyExcludeGroupsList );
@@ -76,7 +78,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7678 foreach ($ usersInGroup as $ userId => $ displayName ) {
7779 $ userId = (string )$ userId ;
7880 $ user = $ this ->userManager ->get ($ userId );
79- if (!$ user ->isEnabled ()) {
81+ if (!$ user? ->isEnabled()) {
8082 // Ignore disabled users
8183 continue ;
8284 }
@@ -86,37 +88,43 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
8688 $ hasMoreResults = true ;
8789 }
8890 }
91+ }
8992
90- if (!$ this ->shareWithGroupOnly && $ this ->shareeEnumerationPhone ) {
91- $ usersTmp = $ this ->userManager ->searchKnownUsersByDisplayName ($ currentUserId , $ search , $ limit , $ offset );
92- if (!empty ($ usersTmp )) {
93+ // not limited to group only sharing
94+ if (!$ this ->shareWithGroupOnly ) {
95+ if (!$ this ->shareeEnumerationPhone && !$ this ->shareeEnumerationInGroupOnly ) {
96+ // no restrictions, add everything
97+ $ usersTmp = $ this ->userManager ->searchDisplayName ($ search , $ limit , $ offset );
98+ foreach ($ usersTmp as $ user ) {
99+ if ($ user ->isEnabled ()) { // Don't keep deactivated users
100+ $ users [$ user ->getUID ()] = $ user ;
101+ }
102+ }
103+ } else {
104+ // make sure to add phonebook matches if configured
105+ if ($ this ->shareeEnumerationPhone ) {
106+ $ usersTmp = $ this ->userManager ->searchKnownUsersByDisplayName ($ currentUserId , $ search , $ limit , $ offset );
93107 foreach ($ usersTmp as $ user ) {
94108 if ($ user ->isEnabled ()) { // Don't keep deactivated users
95109 $ users [$ user ->getUID ()] = $ user ;
96110 }
97111 }
98-
99- uasort ($ users , function ($ a , $ b ) {
100- /**
101- * @var \OC\User\User $a
102- * @var \OC\User\User $b
103- */
104- return strcasecmp ($ a ->getDisplayName (), $ b ->getDisplayName ());
105- });
106112 }
107- }
108- } else {
109- // Search in all users
110- if ($ this ->shareeEnumerationPhone ) {
111- $ usersTmp = $ this ->userManager ->searchKnownUsersByDisplayName ($ currentUserId , $ search , $ limit , $ offset );
112- } else {
113- $ usersTmp = $ this ->userManager ->searchDisplayName ($ search , $ limit , $ offset );
114- }
115- foreach ($ usersTmp as $ user ) {
116- if ($ user ->isEnabled ()) { // Don't keep deactivated users
117- $ users [$ user ->getUID ()] = $ user ;
113+
114+ // additionally we need to add full matches
115+ if ($ this ->shareeEnumerationFullMatch ) {
116+ $ usersTmp = $ this ->userManager ->searchDisplayName ($ search , $ limit , $ offset );
117+ foreach ($ usersTmp as $ user ) {
118+ if ($ user ->isEnabled () && mb_strtolower ($ user ->getDisplayName ()) === mb_strtolower ($ search )) {
119+ $ users [$ user ->getUID ()] = $ user ;
120+ }
121+ }
118122 }
119123 }
124+
125+ uasort ($ users , function (IUser $ a , IUser $ b ) {
126+ return strcasecmp ($ a ->getDisplayName (), $ b ->getDisplayName ());
127+ });
120128 }
121129
122130 $ this ->takeOutCurrentUser ($ users );
@@ -149,10 +157,13 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
149157
150158 if (
151159 $ this ->shareeEnumerationFullMatch
152- && $ lowerSearch !== '' && (strtolower ($ uid ) === $ lowerSearch
153- || strtolower ($ userDisplayName ) === $ lowerSearch
154- || ($ this ->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim (strtolower (preg_replace ('/ \(.*\)$/ ' , '' , $ userDisplayName ))) === $ lowerSearch )
155- || ($ this ->shareeEnumerationFullMatchEmail && strtolower ($ userEmail ?? '' ) === $ lowerSearch ))
160+ && $ lowerSearch !== ''
161+ && (
162+ strtolower ($ uid ) === $ lowerSearch
163+ || strtolower ($ userDisplayName ) === $ lowerSearch
164+ || ($ this ->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim (strtolower (preg_replace ('/ \(.*\)$/ ' , '' , $ userDisplayName ))) === $ lowerSearch )
165+ || ($ this ->shareeEnumerationFullMatchEmail && strtolower ($ userEmail ?? '' ) === $ lowerSearch )
166+ )
156167 ) {
157168 if (strtolower ($ uid ) === $ lowerSearch ) {
158169 $ foundUserById = true ;
0 commit comments