Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Admin/UsersController.php
Show All 23 Lines | public function index() | ||||
$result = collect([]); | $result = collect([]); | ||||
if ($owner) { | if ($owner) { | ||||
if ($owner = User::find($owner)) { | if ($owner = User::find($owner)) { | ||||
$result = $owner->users(false)->orderBy('email')->get(); | $result = $owner->users(false)->orderBy('email')->get(); | ||||
} | } | ||||
} elseif (strpos($search, '@')) { | } elseif (strpos($search, '@')) { | ||||
// Search by email | // Search by email | ||||
$user = User::where('email', $search)->first(); | $result = User::withTrashed()->where('email', $search) | ||||
if ($user) { | ->orderBy('email')->get(); | ||||
$result->push($user); | |||||
} else { | if ($result->isEmpty()) { | ||||
// Search by an alias | // Search by an alias | ||||
$user_ids = UserAlias::where('alias', $search)->get()->pluck('user_id'); | $user_ids = UserAlias::where('alias', $search)->get()->pluck('user_id'); | ||||
if ($user_ids->isEmpty()) { | |||||
// Search by an external email | // Search by an external email | ||||
$user_ids = UserSetting::where('key', 'external_email') | $ext_user_ids = UserSetting::where('key', 'external_email') | ||||
->where('value', $search)->get()->pluck('user_id'); | ->where('value', $search)->get()->pluck('user_id'); | ||||
} | |||||
$user_ids = $user_ids->merge($ext_user_ids)->unique(); | |||||
if (!$user_ids->isEmpty()) { | if (!$user_ids->isEmpty()) { | ||||
$result = User::whereIn('id', $user_ids)->orderBy('email')->get(); | $result = User::withTrashed()->whereIn('id', $user_ids) | ||||
->orderBy('email')->get(); | |||||
} | } | ||||
} | } | ||||
} elseif (is_numeric($search)) { | } elseif (is_numeric($search)) { | ||||
// Search by user ID | // Search by user ID | ||||
if ($user = User::find($search)) { | if ($user = User::withTrashed()->find($search)) { | ||||
$result->push($user); | $result->push($user); | ||||
} | } | ||||
} elseif (!empty($search)) { | } elseif (!empty($search)) { | ||||
// Search by domain | // Search by domain | ||||
if ($domain = Domain::where('namespace', $search)->first()) { | if ($domain = Domain::withTrashed()->where('namespace', $search)->first()) { | ||||
if ($wallet = $domain->wallet()) { | if ($wallet = $domain->wallet()) { | ||||
$result->push($wallet->owner); | $result->push($wallet->owner()->withTrashed()->first()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Process the result | // Process the result | ||||
$result = $result->map(function ($user) { | $result = $result->map(function ($user) { | ||||
$data = $user->toArray(); | $data = $user->toArray(); | ||||
$data = array_merge($data, self::userStatuses($user)); | $data = array_merge($data, self::userStatuses($user)); | ||||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |