feat: allow super admin to update candidate tenant on profile page

This commit is contained in:
jeremy bayse
2026-03-30 17:03:20 +02:00
parent 7ece2036c1
commit 4810ca9d9c
3 changed files with 62 additions and 3 deletions

View File

@@ -84,10 +84,11 @@ class CandidateController extends Controller
'attempts.quiz',
'attempts.answers.question',
'attempts.answers.option',
'jobPosition'
'jobPosition',
'tenant'
]);
return \Inertia\Inertia::render('Admin/Candidates/Show', [
$data = [
'candidate' => $candidate,
'jobPositions' => \App\Models\JobPosition::all(),
'ai_config' => [
@@ -99,7 +100,13 @@ class CandidateController extends Controller
'gemini' => !empty(env('GEMINI_API_KEY')),
], function($v) { return $v; })
]
]);
];
if (auth()->user()->isSuperAdmin()) {
$data['tenants'] = \App\Models\Tenant::orderBy('name')->get();
}
return \Inertia\Inertia::render('Admin/Candidates/Show', $data);
}
public function destroy(Candidate $candidate)
@@ -174,6 +181,30 @@ class CandidateController extends Controller
return back()->with('success', 'Fiche de poste associée au candidat.');
}
public function updateTenant(Request $request, Candidate $candidate)
{
if (!auth()->user()->isSuperAdmin()) {
abort(403);
}
$request->validate([
'tenant_id' => 'nullable|exists:tenants,id',
]);
$candidate->update([
'tenant_id' => $request->tenant_id,
]);
// Also update the associated user's tenant_id if it exists
if ($candidate->user) {
$candidate->user->update([
'tenant_id' => $request->tenant_id,
]);
}
return back()->with('success', 'Structure de rattachement mise à jour avec succès.');
}
public function resetPassword(Candidate $candidate)
{
$password = Str::random(10);