-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,9 +248,11 @@ public function checkPassword($loginName, $password) { | |
public function search($pattern, $limit = null, $offset = null) { | ||
$accounts = $this->accountMapper->search('user_id', $pattern, $limit, $offset); | ||
$users = []; | ||
foreach ($accounts as $account) { | ||
$user = $this->getUserObject($account); | ||
$users[$user->getUID()] = $user; | ||
if ($this->isSearcheable($pattern)) { | ||
foreach ($accounts as $account) { | ||
$user = $this->getUserObject($account); | ||
$users[$user->getUID()] = $user; | ||
} | ||
} | ||
|
||
return $users; | ||
|
@@ -267,9 +269,11 @@ public function search($pattern, $limit = null, $offset = null) { | |
public function find($pattern, $limit = null, $offset = null) { | ||
$accounts = $this->accountMapper->find($pattern, $limit, $offset); | ||
$users = []; | ||
foreach ($accounts as $account) { | ||
$user = $this->getUserObject($account); | ||
$users[$user->getUID()] = $user; | ||
if ($this->isSearcheable($pattern)) { | ||
foreach ($accounts as $account) { | ||
$user = $this->getUserObject($account); | ||
$users[$user->getUID()] = $user; | ||
} | ||
} | ||
return $users; | ||
} | ||
|
@@ -283,10 +287,27 @@ public function find($pattern, $limit = null, $offset = null) { | |
* @return \OC\User\User[] | ||
*/ | ||
public function searchDisplayName($pattern, $limit = null, $offset = null) { | ||
$accounts = $this->accountMapper->search('display_name', $pattern, $limit, $offset); | ||
return array_map(function(Account $account) { | ||
return $this->getUserObject($account); | ||
}, $accounts); | ||
if ($this->isSearcheable($pattern)) { | ||
$accounts = $this->accountMapper->search('display_name', $pattern, $limit, $offset); | ||
return array_map(function(Account $account) { | ||
return $this->getUserObject($account); | ||
}, $accounts); | ||
|
||
} | ||
return []; | ||
} | ||
|
||
/** | ||
* @param string $pattern | ||
* @return bool | ||
*/ | ||
public function isSearcheable($pattern) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
PVince81
Contributor
|
||
$trimmed = trim($pattern); | ||
return $trimmed === '' || strlen($trimmed) >= $this->getSearchMinLength(); | ||
} | ||
|
||
public function getSearchMinLength() { | ||
return $this->config->getSystemValue('user.search_min_length', 4); | ||
} | ||
|
||
/** | ||
|
Good thing that these are reusable functions, however it feels that these do not really belong in the UserManager. Are there other good candidates to move these to ?