mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
Allow to find local users by their email address
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
72ccab0ab6
commit
ae693129db
1 changed files with 30 additions and 7 deletions
|
|
@ -593,24 +593,47 @@ class ShareesAPIController extends OCSController {
|
|||
* @return array
|
||||
*/
|
||||
protected function getEmail($search) {
|
||||
$result = ['results' => [], 'exact' => []];
|
||||
$result = ['results' => [], 'exact' => [], 'exactIdMatch' => false];
|
||||
|
||||
// Search in contacts
|
||||
//@todo Pagination missing
|
||||
$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
|
||||
$result['exactIdMatch'] = false;
|
||||
$lowerSearch = strtolower($search);
|
||||
foreach ($addressBookContacts as $contact) {
|
||||
if (isset($contact['isLocalSystemBook'])) {
|
||||
continue;
|
||||
}
|
||||
if (isset($contact['EMAIL'])) {
|
||||
$emailAddresses = $contact['EMAIL'];
|
||||
if (!is_array($emailAddresses)) {
|
||||
$emailAddresses = [$emailAddresses];
|
||||
}
|
||||
foreach ($emailAddresses as $emailAddress) {
|
||||
if (strtolower($contact['FN']) === strtolower($search) || strtolower($emailAddress) === strtolower($search)) {
|
||||
if (strtolower($emailAddress) === strtolower($search)) {
|
||||
$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
|
||||
if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
|
||||
if (isset($contact['isLocalSystemBook'])) {
|
||||
if ($exactEmailMatch) {
|
||||
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
|
||||
$this->result['exact']['users'][] = [
|
||||
'label' => $contact['FN'] . " ($emailAddress)",
|
||||
'value' => [
|
||||
'shareType' => Share::SHARE_TYPE_USER,
|
||||
'shareWith' => $cloud->getUser(),
|
||||
],
|
||||
];
|
||||
return ['results' => [], 'exact' => [], 'exactIdMatch' => true];
|
||||
}
|
||||
if ($this->shareeEnumeration) {
|
||||
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
|
||||
$this->result['users'][] = [
|
||||
'label' => $contact['FN'] . " ($emailAddress)",
|
||||
'value' => [
|
||||
'shareType' => Share::SHARE_TYPE_USER,
|
||||
'shareWith' => $cloud->getUser(),
|
||||
],
|
||||
];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($exactEmailMatch) {
|
||||
$result['exactIdMatch'] = true;
|
||||
}
|
||||
$result['exact'][] = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue