diff --git a/app/Http/Controllers/SchoolController.php b/app/Http/Controllers/SchoolController.php index 1f78afc..f9ef6f1 100644 --- a/app/Http/Controllers/SchoolController.php +++ b/app/Http/Controllers/SchoolController.php @@ -191,4 +191,24 @@ class SchoolController extends Controller return redirect()->back()->with('success', 'Director added'); } + + public function setHeadDirector(School $school, User $user, SetHeadDirector $headSetter) + { + if (auth()->user()->school_id !== $school->id) { + return redirect()->back()->with('error', 'No setting the head director for another school'); + } + if (! auth()->user()->hasFlag('head_director')) { + return redirect()->back()->with('error', 'Only the head director can name a new head director'); + } + if ($school->id !== $user->school_id) { + return redirect()->back()->with('error', 'The proposed head director must be at your school'); + } + try { + $headSetter->setHeadDirector($user); + } catch (AuditionAdminException $e) { + return redirect()->back()->with('error', $e->getMessage()); + } + + return redirect()->back()->with('success', 'New head director set'); + } } diff --git a/resources/views/schools/show.blade.php b/resources/views/schools/show.blade.php index d074753..18713b6 100644 --- a/resources/views/schools/show.blade.php +++ b/resources/views/schools/show.blade.php @@ -67,6 +67,34 @@ Change Head Director + {{-- Warming Message --}} +
+
+
+ +
+
+

WARNING!!!

+
+

After making another director head, you will no longer have access to head director functions

+

This action cannot be undone

+
+
+
+
+

Which director should be the head director at {{$school->name}}? (click to set)

+ + @foreach($school->directors as $director) + @continue($director->id === auth()->user()->id) + + + {{ $director->full_name() }} < {{$director->email }} > + + + @endforeach +
@endif diff --git a/routes/user.php b/routes/user.php index 1c30eb5..c95d462 100644 --- a/routes/user.php +++ b/routes/user.php @@ -53,6 +53,7 @@ Route::middleware(['auth', 'verified'])->controller(SchoolController::class)->gr Route::get('/schools/{school}', 'show')->name('schools.show'); Route::patch('/schools/{school}', 'update')->name('schools.update'); Route::post('schools/{school}/add_director', 'addDirector')->name('schools.add_director'); + Route::get('/schools/{school}/set_head_director/{user}', 'setHeadDirector')->name('schools.set_head_director'); }); // Doubler Related Routes