diff --git a/app/Http/Controllers/SchoolController.php b/app/Http/Controllers/SchoolController.php index f9ef6f1..5acfddf 100644 --- a/app/Http/Controllers/SchoolController.php +++ b/app/Http/Controllers/SchoolController.php @@ -9,6 +9,7 @@ use App\Models\AuditLogEntry; use App\Models\School; use App\Models\SchoolEmailDomain; use App\Models\User; +use Illuminate\Database\UniqueConstraintViolationException; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -211,4 +212,46 @@ class SchoolController extends Controller return redirect()->back()->with('success', 'New head director set'); } + + public function addDomain(School $school) + { + if (auth()->user()->school_id !== $school->id) { + return redirect()->back()->with('error', 'No adding domains for another school'); + } + if (! auth()->user()->hasFlag('head_director')) { + return redirect()->back()->with('error', 'Only the head director can add domains'); + } + $verifiedData = request()->validate([ + 'domain' => ['required'], + ]); + try { + SchoolEmailDomain::create([ + 'school_id' => $school->id, + 'domain' => $verifiedData['domain'], + ]); + } catch (UniqueConstraintViolationException $e) { + return redirect()->back()->with('error', 'That domain is already associated with your school'); + } + $logMessage = 'Added domain '.$verifiedData['domain'].' to school '.$school->name; + $logAffected = ['schools' => [$school->id]]; + auditionLog($logMessage, $logAffected); + + return redirect()->back()->with('success', 'Domain added'); + } + + public function deleteDomain(SchoolEmailDomain $domain) + { + if (auth()->user()->school_id !== $domain->school_id) { + return redirect()->back()->with('error', 'No deleting domains for another school'); + } + if (! auth()->user()->hasFlag('head_director')) { + return redirect()->back()->with('error', 'Only the head director can delete domains'); + } + $logMessage = 'Deleted domain '.$domain->domain.' from school '.$domain->school->name; + $logAffected = ['schools' => [$domain->school_id]]; + auditionLog($logMessage, $logAffected); + $domain->delete(); + + return redirect()->back()->with('success', 'Domain deleted'); + } } diff --git a/resources/views/schools/show.blade.php b/resources/views/schools/show.blade.php index 18713b6..742f8d4 100644 --- a/resources/views/schools/show.blade.php +++ b/resources/views/schools/show.blade.php @@ -36,14 +36,31 @@ @endif - - - - + @if(auth()->user()->hasFlag('head_director')) + +

Users with emails in these domains (the part after the @) that don't already have a school + will be able to join your school.

+ +
+ @endif diff --git a/routes/user.php b/routes/user.php index c95d462..e9a0c71 100644 --- a/routes/user.php +++ b/routes/user.php @@ -54,6 +54,8 @@ Route::middleware(['auth', 'verified'])->controller(SchoolController::class)->gr 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'); + Route::post('/schools/{school}/add_domain', 'addDomain')->name('schools.add_domain'); + Route::get('/schools/delete_domain/{domain}', 'deleteDomain')->name('schools.delete_domain'); }); // Doubler Related Routes