Administrators can make a user head director from school page
Work on #64
This commit is contained in:
parent
46441268c9
commit
9f71e5e3f5
|
|
@ -2,10 +2,12 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Actions\Schools\SetHeadDirector;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\AuditLogEntry;
|
use App\Models\AuditLogEntry;
|
||||||
use App\Models\School;
|
use App\Models\School;
|
||||||
use App\Models\SchoolEmailDomain;
|
use App\Models\SchoolEmailDomain;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\Invoice\InvoiceDataService;
|
use App\Services\Invoice\InvoiceDataService;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
|
@ -176,4 +178,14 @@ class SchoolController extends Controller
|
||||||
|
|
||||||
return view('dashboard.invoice', compact('school', 'invoiceData'));
|
return view('dashboard.invoice', compact('school', 'invoiceData'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setHeadDirector(School $school, User $user, SetHeadDirector $headSetter)
|
||||||
|
{
|
||||||
|
if ($user->school_id !== $school->id) {
|
||||||
|
return redirect()->back()->with('error', 'That user is not at that school');
|
||||||
|
}
|
||||||
|
$headSetter->setHeadDirector($user);
|
||||||
|
|
||||||
|
return redirect()->back()->with('success', 'Head director set');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,16 @@
|
||||||
<div class="grid md:grid-cols-3 gap-3 mt-3">
|
<div class="grid md:grid-cols-3 gap-3 mt-3">
|
||||||
@foreach($school->directors as $director)
|
@foreach($school->directors as $director)
|
||||||
<x-card.card>
|
<x-card.card>
|
||||||
<x-card.heading>{{ $director->full_name() }}</x-card.heading>
|
<x-card.heading>
|
||||||
|
<a href="{{route('admin.users.edit',$director)}}">{{ $director->full_name() }}</a>
|
||||||
|
@if($director->hasFlag('head_director'))
|
||||||
|
<x-slot:right_side><x-badge_pill>Head Director</x-badge_pill></x-slot:right_side>
|
||||||
|
@else
|
||||||
|
<x-slot:subheading>
|
||||||
|
<a href="{{route('admin.schools.set_head_director',['school'=>$school, 'user'=>$director])}}">[ Make Head Director ]</a>
|
||||||
|
</x-slot:subheading>
|
||||||
|
@endif
|
||||||
|
</x-card.heading>
|
||||||
<div class="ml-6">
|
<div class="ml-6">
|
||||||
<p class="py-2">{{ $director->cell_phone }}</p>
|
<p class="py-2">{{ $director->cell_phone }}</p>
|
||||||
<p class="py-2">
|
<p class="py-2">
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
||||||
Route::post('/', 'store')->name('admin.schools.store');
|
Route::post('/', 'store')->name('admin.schools.store');
|
||||||
Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain');
|
Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain');
|
||||||
Route::delete('/{school}', 'destroy')->name('admin.schools.destroy');
|
Route::delete('/{school}', 'destroy')->name('admin.schools.destroy');
|
||||||
|
Route::get('/{school}/set_head_director/{user}', 'setHeadDirector')->name('admin.schools.set_head_director');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use function Pest\Laravel\actingAs;
|
use function Pest\Laravel\actingAs;
|
||||||
use function Pest\Laravel\assertDatabaseHas;
|
use function Pest\Laravel\assertDatabaseHas;
|
||||||
use function Pest\Laravel\delete;
|
use function Pest\Laravel\delete;
|
||||||
|
use function Pest\Laravel\from;
|
||||||
use function Pest\Laravel\get;
|
use function Pest\Laravel\get;
|
||||||
use function Pest\Laravel\patch;
|
use function Pest\Laravel\patch;
|
||||||
|
|
||||||
|
|
@ -150,7 +151,7 @@ it('allows an administrator to modify a user', function () {
|
||||||
'school_id' => $newSchool->id,
|
'school_id' => $newSchool->id,
|
||||||
];
|
];
|
||||||
// Act
|
// Act
|
||||||
$response = patch(route('admin.users.update', $this->users[0]), $newData);
|
$response = from(route('admin.users.index'))->patch(route('admin.users.update', $this->users[0]), $newData);
|
||||||
/** @noinspection PhpUnhandledExceptionInspection */
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
$response
|
$response
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
|
|
@ -186,7 +187,7 @@ it('allows a users school to be set to no school', function () {
|
||||||
];
|
];
|
||||||
actAsAdmin();
|
actAsAdmin();
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
$response = patch(route('admin.users.update', $user), $newData);
|
$response = from(route('admin.users.index'))->patch(route('admin.users.update', $user), $newData);
|
||||||
/** @noinspection PhpUnhandledExceptionInspection */
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
$response
|
$response
|
||||||
->assertSessionHasNoErrors()
|
->assertSessionHasNoErrors()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue