*/ public function candidates(?User $viewer, ?int $excludeId = null): array { return User::query() ->when($excludeId, fn (Builder $query, int $id) => $query->whereKeyNot($id)) ->when($viewer, fn (Builder $query, User $for) => $query->where(fn (Builder $reachable) => $reachable ->where('type', UserType::Staff) ->orWhereIn('id', $this->scope->clients($for)->select('users.id')))) ->where('active', true) ->with('role') ->orderBy('name') ->get() ->map(function (User $user): array { $role = $user->role; return [ 'id' => $user->id, 'name' => $user->name, 'role' => $user->isClient() ? __('Client') : ($role instanceof Role ? $role->name : __('Staff')), ]; }) ->values() ->all(); } /** * When the account being deleted owns any files/folders, require the * admin to choose what happens to them. Returns an empty array when * there is nothing to decide, so accounts with no content delete * exactly as before. * * @return array{content_action?: string, reassign_to_id?: int} */ public function validate(Request $request, User $target): array { $summary = $this->content->summarize($target); if ($summary['files'] === 0 && $summary['folders'] === 0) { return []; } return $request->validate([ 'content_action' => ['required', Rule::in(['cascade_delete', 'reassign'])], 'reassign_to_id' => [ 'required_if:content_action,reassign', 'integer', Rule::exists('users', 'id')->where('active', true), Rule::notIn([$target->id]), ], ]); } /** * @param array{content_action?: string, reassign_to_id?: int} $validated */ public function apply(array $validated, User $target, string $name): void { $action = $validated['content_action'] ?? null; if ($action === 'cascade_delete') { $result = $this->content->cascadeDelete($target); $this->activity->log(Action::AccountContentCascadeDeleted, context: ['name' => $name, ...$result]); return; } if ($action === 'reassign' && isset($validated['reassign_to_id'])) { $to = User::findOrFail($validated['reassign_to_id']); $result = $this->content->reassignTo($target, $to); $this->activity->log(Action::AccountContentReassigned, context: ['name' => $name, 'target' => $to->name, ...$result]); } } }