Auditionadmin 64 #71
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,14 +36,31 @@
|
|||
</div>
|
||||
@endif
|
||||
</x-card.info.row>
|
||||
|
||||
@if(auth()->user()->hasFlag('head_director'))
|
||||
<x-card.info.row row_name="Associated Email Domains">
|
||||
<p class="text-sm text-gray-400 border-b">Users with emails in these domains (the part after the @) that don't already have a school
|
||||
will be able to join your school.</p>
|
||||
<ul>
|
||||
@foreach($school->emailDomains as $domain)
|
||||
<li>{{ $domain->domain }}</li>
|
||||
<li class="flex my-2">
|
||||
<a href="{{route('schools.delete_domain',$domain)}}">
|
||||
<x-icons.circled-x color="red" />
|
||||
</a>
|
||||
{{ $domain->domain }}
|
||||
</li>
|
||||
@endforeach
|
||||
<li class="border-t">
|
||||
<p class="text-base">Add Domain</p>
|
||||
<x-form.form method="post" action="{{route('schools.add_domain',$school)}}" class="-ml-8">
|
||||
<div class="grid grid-cols-3">
|
||||
<x-form.field name="domain" label_text="Domain (do not include @)" colspan="2" />
|
||||
<x-form.button class="mt-6 ml-2">Add</x-form.button>
|
||||
</div>
|
||||
</x-form.form>
|
||||
</li>
|
||||
</ul>
|
||||
</x-card.info.row>
|
||||
@endif
|
||||
</x-card.info.body>
|
||||
</x-card.card>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue