feat: allow super admin to update candidate tenant on profile page
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -13,6 +13,7 @@ import InputError from '@/Components/InputError.vue';
|
||||
const props = defineProps({
|
||||
candidate: Object,
|
||||
jobPositions: Array,
|
||||
tenants: Array,
|
||||
ai_config: Object
|
||||
});
|
||||
|
||||
@@ -29,6 +30,16 @@ const updatePosition = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const tenantForm = useForm({
|
||||
tenant_id: props.candidate.tenant_id || ''
|
||||
});
|
||||
|
||||
const updateTenant = () => {
|
||||
tenantForm.patch(route('admin.candidates.update-tenant', props.candidate.id), {
|
||||
preserveScroll: true,
|
||||
});
|
||||
};
|
||||
|
||||
const selectedDocument = ref(null);
|
||||
|
||||
const docForm = useForm({
|
||||
@@ -207,6 +218,22 @@ const runAI = async () => {
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Structure de rattachement (Super Admin only) -->
|
||||
<div v-if="page.props.auth.user.role === 'super_admin'" class="mb-6">
|
||||
<label class="text-[10px] font-black uppercase tracking-widest text-slate-400 mb-2 block text-left">Structure de Rattachement</label>
|
||||
<select
|
||||
v-model="tenantForm.tenant_id"
|
||||
@change="updateTenant"
|
||||
class="w-full bg-slate-50 dark:bg-slate-900 border-none rounded-xl py-2 px-3 text-xs font-bold text-emerald-600 focus:ring-2 focus:ring-emerald-500/20 transition-all cursor-pointer"
|
||||
>
|
||||
<option value="">Aucune structure</option>
|
||||
<option v-for="tenant in tenants" :key="tenant.id" :value="tenant.id">
|
||||
{{ tenant.name }}
|
||||
</option>
|
||||
</select>
|
||||
<p class="text-[9px] text-slate-400 mt-1 italic text-left">Note: modifie aussi le rattachement de l'utilisateur.</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3 text-left">
|
||||
<div class="flex items-center gap-3 p-3 bg-slate-50 dark:bg-slate-900 rounded-xl">
|
||||
|
||||
@@ -76,6 +76,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::patch('/candidates/{candidate}/notes', [\App\Http\Controllers\CandidateController::class, 'updateNotes'])->name('candidates.update-notes');
|
||||
Route::patch('/candidates/{candidate}/scores', [\App\Http\Controllers\CandidateController::class, 'updateScores'])->name('candidates.update-scores');
|
||||
Route::patch('/candidates/{candidate}/position', [\App\Http\Controllers\CandidateController::class, 'updatePosition'])->name('candidates.update-position');
|
||||
Route::patch('/candidates/{candidate}/tenant', [\App\Http\Controllers\CandidateController::class, 'updateTenant'])->name('candidates.update-tenant');
|
||||
Route::post('/candidates/{candidate}/analyze', [\App\Http\Controllers\AIAnalysisController::class, 'analyze'])->name('candidates.analyze');
|
||||
Route::post('/candidates/{candidate}/reset-password', [\App\Http\Controllers\CandidateController::class, 'resetPassword'])->name('candidates.reset-password');
|
||||
Route::get('/documents/{document}', [\App\Http\Controllers\DocumentController::class, 'show'])->name('documents.show');
|
||||
|
||||
Reference in New Issue
Block a user