From 06afa5315ff1726e2132c24e5a46d95f015a84fb Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Tue, 13 Dec 2016 16:16:04 -0600 Subject: [PATCH 1/7] Allow admins to search for users by display name or email, per #1749 Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index 28b8d2648d99d..1bec3f3556290 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -259,7 +259,12 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe if($gid !== '') { $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); } else { - $batch = $this->userManager->search($pattern, $limit, $offset); + //TODO: allow partial strings for email matches + $batch = array_merge( + $this->userManager->search($pattern, $limit, $offset), + $this->userManager->searchDisplayName($pattern, $limit, $offset), + $this->userManager->getByEmail($pattern) + ); } foreach ($batch as $user) { From a325162ec5c50626250b43d5093a30d10e9769a6 Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Wed, 14 Dec 2016 00:37:07 -0600 Subject: [PATCH 2/7] Account for null arrays when merging user search results Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index 1bec3f3556290..7744d0c22ae69 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -260,11 +260,16 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); } else { //TODO: allow partial strings for email matches - $batch = array_merge( - $this->userManager->search($pattern, $limit, $offset), - $this->userManager->searchDisplayName($pattern, $limit, $offset), - $this->userManager->getByEmail($pattern) - ); + $batch = array(); + $arrays = array(); + $arrays[0] = $this->userManager->search($pattern, $limit, $offset); + $arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset); + $arrays[2] = $this->userManager->getByEmail($pattern); + foreach ($arrays as $arr) { + if(is_array($arr)) { + $batch = array_merge($batch, $arr); + } + } } foreach ($batch as $user) { From 71d191a1d8ad0a95c0ad4d344421bd6e6767a5ac Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Wed, 14 Dec 2016 10:49:37 -0600 Subject: [PATCH 3/7] Allow more flexible display name matching in user search Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 27 +++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index 7744d0c22ae69..02e66ce041084 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -259,11 +259,34 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe if($gid !== '') { $batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset)); } else { - //TODO: allow partial strings for email matches + + $batch = array(); $arrays = array(); + + //split display name into individual words for flexible matching $arrays[0] = $this->userManager->search($pattern, $limit, $offset); - $arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset); + $subPatterns = explode(" ", $pattern); + + //if the pattern to search for isn't potentially complex, just call searchDisplayName with it + if (count($subPatterns) == 1) + $arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset); + else { + //get array of matches for each substring + $subMatch = array(); + $subMatches = array(); + foreach ($subPatterns as $sub) { + $subMatch = $this->userManager->searchDisplayName($sub, $limit, $offset); + if(is_array($subMatch)) { + array_push($subMatches,$subMatch); + } + } + + //only keep users with display names matched by all substrings + $arrays[1] = call_user_func_array('array_intersect', $subMatches); + } + + // TODO: allow partial strings for email matches $arrays[2] = $this->userManager->getByEmail($pattern); foreach ($arrays as $arr) { if(is_array($arr)) { From 19c81801686d5184463ff9c2a1e26c4c15cbd135 Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Fri, 16 Dec 2016 16:21:58 -0600 Subject: [PATCH 4/7] Add brackets to if block Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index 02e66ce041084..d6659acb81f35 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -269,8 +269,9 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe $subPatterns = explode(" ", $pattern); //if the pattern to search for isn't potentially complex, just call searchDisplayName with it - if (count($subPatterns) == 1) + if (count($subPatterns) == 1) { $arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset); + } else { //get array of matches for each substring $subMatch = array(); From fd91c365e4e48259ad7da0f21a99e6836b5d7bc6 Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Fri, 16 Dec 2016 20:57:40 -0600 Subject: [PATCH 5/7] Fix formatting, use more descriptive names / improve readability Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 64 ++++++++++++------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index d6659acb81f35..891d4e11855dd 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -261,39 +261,37 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe } else { - $batch = array(); - $arrays = array(); - - //split display name into individual words for flexible matching - $arrays[0] = $this->userManager->search($pattern, $limit, $offset); - $subPatterns = explode(" ", $pattern); - - //if the pattern to search for isn't potentially complex, just call searchDisplayName with it - if (count($subPatterns) == 1) { - $arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset); - } - else { - //get array of matches for each substring - $subMatch = array(); - $subMatches = array(); - foreach ($subPatterns as $sub) { - $subMatch = $this->userManager->searchDisplayName($sub, $limit, $offset); - if(is_array($subMatch)) { - array_push($subMatches,$subMatch); - } - } - - //only keep users with display names matched by all substrings - $arrays[1] = call_user_func_array('array_intersect', $subMatches); - } - - // TODO: allow partial strings for email matches - $arrays[2] = $this->userManager->getByEmail($pattern); - foreach ($arrays as $arr) { - if(is_array($arr)) { - $batch = array_merge($batch, $arr); - } - } + $batch = array(); + + $uidSearchResult = $this->userManager->search($pattern, $limit, $offset); + //split display name into individual words for flexible matching + $subPatterns = explode(" ", $pattern); + //if the pattern to search for isn't potentially complex, just call searchDisplayName with it + if (count($subPatterns) == 1) { + $displayNameSearchResult = $this->userManager->searchDisplayName($pattern, $limit, $offset); + } else { + //get array of matches for each substring + $subMatch = array(); + $subMatches = array(); + foreach ($subPatterns as $sub) { + $subMatch = $this->userManager->searchDisplayName($sub, $limit, $offset); + if(is_array($subMatch)) { + array_push($subMatches,$subMatch); + } + } + + //only keep users with display names matched by all substrings + $displayNameSearchResult = call_user_func_array('array_intersect', $subMatches); + } + + // TODO: allow partial strings for email matches + $emailSearchResult = $this->userManager->getByEmail($pattern); + $searchResults = array($uidSearchResult, $displayNameSearchResult, $emailSearchResults); + foreach ($searchResults as $arr) { + if(is_array($arr)) { + $batch = array_merge($batch, $arr); + } + } } foreach ($batch as $user) { From fed79642141cbb01c76d5b714689208b3b918511 Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Fri, 16 Dec 2016 21:05:30 -0600 Subject: [PATCH 6/7] Fix typo Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index 891d4e11855dd..f1e370947505e 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -286,7 +286,7 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe // TODO: allow partial strings for email matches $emailSearchResult = $this->userManager->getByEmail($pattern); - $searchResults = array($uidSearchResult, $displayNameSearchResult, $emailSearchResults); + $searchResults = array($uidSearchResult, $displayNameSearchResult, $emailSearchResult); foreach ($searchResults as $arr) { if(is_array($arr)) { $batch = array_merge($batch, $arr); From 885cefaf70ef7a253c34d14b3833779dd7f64cef Mon Sep 17 00:00:00 2001 From: justin-sleep Date: Fri, 27 Jan 2017 11:51:28 -0600 Subject: [PATCH 7/7] Remove unnecessary array validity check Signed-off-by: justin-sleep --- settings/Controller/UsersController.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php index f1e370947505e..ed57dd24e4b29 100644 --- a/settings/Controller/UsersController.php +++ b/settings/Controller/UsersController.php @@ -286,12 +286,7 @@ public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backe // TODO: allow partial strings for email matches $emailSearchResult = $this->userManager->getByEmail($pattern); - $searchResults = array($uidSearchResult, $displayNameSearchResult, $emailSearchResult); - foreach ($searchResults as $arr) { - if(is_array($arr)) { - $batch = array_merge($batch, $arr); - } - } + $batch = array_merge($uidSearchResult, $displayNameSearchResult, $emailSearchResult); } foreach ($batch as $user) {