@@ -62,8 +62,10 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
6262 $ users = [];
6363 $ hasMoreResults = false ;
6464
65- $ currentUserId = $ this ->userSession ->getUser ()->getUID ();
66- $ currentUserGroups = $ this ->groupManager ->getUserGroupIds ($ this ->userSession ->getUser ());
65+ /** @var IUser */
66+ $ currentUser = $ this ->userSession ->getUser ();
67+ $ currentUserId = $ currentUser ->getUID ();
68+ $ currentUserGroups = $ this ->groupManager ->getUserGroupIds ($ currentUser );
6769
6870 // ShareWithGroupOnly filtering
6971 $ currentUserGroups = array_diff ($ currentUserGroups , $ this ->shareWithGroupOnlyExcludeGroupsList );
@@ -75,7 +77,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7577 foreach ($ usersInGroup as $ userId => $ displayName ) {
7678 $ userId = (string )$ userId ;
7779 $ user = $ this ->userManager ->get ($ userId );
78- if (!$ user ->isEnabled ()) {
80+ if (!$ user? ->isEnabled()) {
7981 // Ignore disabled users
8082 continue ;
8183 }
@@ -85,37 +87,43 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
8587 $ hasMoreResults = true ;
8688 }
8789 }
90+ }
8891
89- if (!$ this ->shareWithGroupOnly && $ this ->shareeEnumerationPhone ) {
90- $ usersTmp = $ this ->userManager ->searchKnownUsersByDisplayName ($ currentUserId , $ search , $ limit , $ offset );
91- if (!empty ($ usersTmp )) {
92+ // not limited to group only sharing
93+ if (!$ this ->shareWithGroupOnly ) {
94+ if (!$ this ->shareeEnumerationPhone && !$ this ->shareeEnumerationInGroupOnly ) {
95+ // no restrictions, add everything
96+ $ usersTmp = $ this ->userManager ->searchDisplayName ($ search , $ limit , $ offset );
97+ foreach ($ usersTmp as $ user ) {
98+ if ($ user ->isEnabled ()) { // Don't keep deactivated users
99+ $ users [$ user ->getUID ()] = $ user ;
100+ }
101+ }
102+ } else {
103+ // make sure to add phonebook matches if configured
104+ if ($ this ->shareeEnumerationPhone ) {
105+ $ usersTmp = $ this ->userManager ->searchKnownUsersByDisplayName ($ currentUserId , $ search , $ limit , $ offset );
92106 foreach ($ usersTmp as $ user ) {
93107 if ($ user ->isEnabled ()) { // Don't keep deactivated users
94108 $ users [$ user ->getUID ()] = $ user ;
95109 }
96110 }
97-
98- uasort ($ users , function ($ a , $ b ) {
99- /**
100- * @var \OC\User\User $a
101- * @var \OC\User\User $b
102- */
103- return strcasecmp ($ a ->getDisplayName (), $ b ->getDisplayName ());
104- });
105111 }
106- }
107- } else {
108- // Search in all users
109- if ($ this ->shareeEnumerationPhone ) {
110- $ usersTmp = $ this ->userManager ->searchKnownUsersByDisplayName ($ currentUserId , $ search , $ limit , $ offset );
111- } else {
112- $ usersTmp = $ this ->userManager ->searchDisplayName ($ search , $ limit , $ offset );
113- }
114- foreach ($ usersTmp as $ user ) {
115- if ($ user ->isEnabled ()) { // Don't keep deactivated users
116- $ users [$ user ->getUID ()] = $ user ;
112+
113+ // additionally we need to add full matches
114+ if ($ this ->shareeEnumerationFullMatch ) {
115+ $ usersTmp = $ this ->userManager ->searchDisplayName ($ search , $ limit , $ offset );
116+ foreach ($ usersTmp as $ user ) {
117+ if ($ user ->isEnabled () && mb_strtolower ($ user ->getDisplayName ()) === mb_strtolower ($ search )) {
118+ $ users [$ user ->getUID ()] = $ user ;
119+ }
120+ }
117121 }
118122 }
123+
124+ uasort ($ users , function (IUser $ a , IUser $ b ) {
125+ return strcasecmp ($ a ->getDisplayName (), $ b ->getDisplayName ());
126+ });
119127 }
120128
121129 $ this ->takeOutCurrentUser ($ users );
@@ -147,11 +155,14 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
147155
148156
149157 if (
150- $ this ->shareeEnumerationFullMatch &&
151- $ lowerSearch !== '' && (strtolower ($ uid ) === $ lowerSearch ||
152- strtolower ($ userDisplayName ) === $ lowerSearch ||
153- ($ this ->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim (strtolower (preg_replace ('/ \(.*\)$/ ' , '' , $ userDisplayName ))) === $ lowerSearch ) ||
154- ($ this ->shareeEnumerationFullMatchEmail && strtolower ($ userEmail ?? '' ) === $ lowerSearch ))
158+ $ this ->shareeEnumerationFullMatch
159+ && $ lowerSearch !== ''
160+ && (
161+ strtolower ($ uid ) === $ lowerSearch
162+ || strtolower ($ userDisplayName ) === $ lowerSearch
163+ || ($ this ->shareeEnumerationFullMatchIgnoreSecondDisplayName && trim (strtolower (preg_replace ('/ \(.*\)$/ ' , '' , $ userDisplayName ))) === $ lowerSearch )
164+ || ($ this ->shareeEnumerationFullMatchEmail && strtolower ($ userEmail ?? '' ) === $ lowerSearch )
165+ )
155166 ) {
156167 if (strtolower ($ uid ) === $ lowerSearch ) {
157168 $ foundUserById = true ;
0 commit comments