diff --git a/app/Http/Controllers/Admin/EntryController.php b/app/Http/Controllers/Admin/EntryController.php index 529788c..d88d49d 100644 --- a/app/Http/Controllers/Admin/EntryController.php +++ b/app/Http/Controllers/Admin/EntryController.php @@ -12,6 +12,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use function compact; +use function to_route; class EntryController extends Controller { @@ -62,12 +63,14 @@ class EntryController extends Controller $entries = $entries->paginate(10); - return view('admin.entries.index', ['entries' => $entries, + return view('admin.entries.index', [ + 'entries' => $entries, 'auditions' => $auditions, 'schools' => $schools, 'minGrade' => $minGrade, 'maxGrade' => $maxGrade, - 'filters' => $filters]); + 'filters' => $filters, + ]); } public function create() @@ -106,9 +109,16 @@ class EntryController extends Controller public function edit(Entry $entry) { - if (! Auth::user()->is_admin) { - abort(403); + if ($entry->audition->hasFlag('seats_published')) { + return to_route('admin.entries.index')->with('error', + 'Entries in auditions with seats published cannot be modified'); } + + if ($entry->audition->hasFlag('advancement_published')) { + return to_route('admin.entries.index')->with('error', + 'Entries in auditions with advancement results published cannot be modified'); + } + $students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get(); $auditions = Audition::orderBy('score_order')->get(); $scores = $entry->scoreSheets()->get(); @@ -119,8 +129,14 @@ class EntryController extends Controller public function update(Request $request, Entry $entry) { - if (! Auth::user()->is_admin) { - abort(403); + if ($entry->audition->hasFlag('seats_published')) { + return to_route('admin.entries.index')->with('error', + 'Entries in auditions with seats published cannot be modified'); + } + + if ($entry->audition->hasFlag('advancement_published')) { + return to_route('admin.entries.index')->with('error', + 'Entries in auditions with advancement results published cannot be modified'); } $validData = request()->validate([ 'student_id' => ['required', 'exists:students,id'], @@ -142,8 +158,14 @@ class EntryController extends Controller public function destroy(Request $request, Entry $entry) { - if (! Auth::user()->is_admin) { - abort(403); + if ($entry->audition->hasFlag('seats_published')) { + return to_route('admin.entries.index')->with('error', + 'Entries in auditions with seats published cannot be deleted'); + } + + if ($entry->audition->hasFlag('advancement_published')) { + return to_route('admin.entries.index')->with('error', + 'Entries in auditions with advancement results published cannot be deleted'); } if (Seat::where('entry_id', $entry->id)->exists()) { return redirect()->route('admin.entries.index')->with('error', 'Cannot delete an entry that is seated'); diff --git a/resources/views/admin/entries/edit.blade.php b/resources/views/admin/entries/edit.blade.php index 225b26a..9e66245 100644 --- a/resources/views/admin/entries/edit.blade.php +++ b/resources/views/admin/entries/edit.blade.php @@ -5,15 +5,9 @@ Edit Entry #{{ $entry->id }} - @if(! Seat::where('entry_id', $entry->id)->exists()) -
- @csrf - @method('DELETE') - - - @else - Seated: {{ $entry->seat->ensemble->name }} #{{ $entry->seat->seat }} - @endif + + Confirm you would like to delete entry #{{$entry->id}} by {{$entry->student->full_name()}} on {{$entry->audition->name}}. +
diff --git a/tests/Feature/Pages/Admin/EntriesEditTest.php b/tests/Feature/Pages/Admin/EntriesEditTest.php new file mode 100644 index 0000000..f813945 --- /dev/null +++ b/tests/Feature/Pages/Admin/EntriesEditTest.php @@ -0,0 +1,115 @@ +entry = Entry::factory()->create(); +}); + +it('does not respond to an ordinary user', function () { + actAsNormal(); + get(route('admin.entries.edit', $this->entry)) + ->assertRedirect(route('dashboard')); +}); +it('does not respond to a guest', function () { + // Act & Assert + get(route('admin.entries.edit', $this->entry)) + ->assertRedirect(route('home')); +}); +it('does not respond if the audition is published', function () { + // Arrange + actAsAdmin(); + $this->entry->audition->addFlag('seats_published'); + get(route('admin.entries.edit', $this->entry)) + ->assertRedirect(route('admin.entries.index')) + ->assertSessionHas('error', 'Entries in auditions with seats published cannot be modified'); +}); +it('does not respond if advancement for the audition is published', function () { + // Arrange + actAsAdmin(); + $this->entry->audition->addFlag('advancement_published'); + get(route('admin.entries.edit', $this->entry)) + ->assertRedirect(route('admin.entries.index')) + ->assertSessionHas('error', 'Entries in auditions with advancement results published cannot be modified'); +}); +it('has a delete link', function () { + // Arrange + actAsAdmin(); + // Act & Assert + get(route('admin.entries.edit', $this->entry)) + ->assertSee('', false); +}); +it('has a dropdown for all auditions', function () { + // Arrange + $auditions = Audition::factory()->count(5)->create(); + actAsAdmin(); + $response = get(route('admin.entries.edit', $this->entry)); + foreach ($auditions as $audition) { + $response->assertSeeInOrder([ + 'option', + 'value=', + $audition->id, + 'option', + ], false); + $response->assertSeeInOrder([ + 'option', + 'value=', + $this->entry->audition->id, + 'selected', + 'option', + ], false); + } +}); +it('shows checkboxes for entry types only if advancement is enabled', function () { + actAsAdmin(); + get(route('admin.entries.edit', $this->entry)) + ->assertSee('Enter for '.auditionSetting('auditionAbbreviation')) + ->assertSee('Enter for '.auditionSetting('advanceTo')); + Settings::set('advanceTo', ''); + get(route('admin.entries.edit', $this->entry)) + ->assertDontSee('Enter for '.auditionSetting('auditionAbbreviation')) + ->assertDontSee('Enter for '.auditionSetting('advanceTo')); +}); +it('properly checks boxes based on entries settings', function () { + actAsAdmin(); + get(route('admin.entries.edit', $this->entry)) + ->assertSeeInOrder([ + 'input', + 'name=', + 'for_seating', + 'checked', + auditionSetting('auditionAbbreviation'), + ]) + ->assertSeeInOrder([ + 'input', + 'name=', + 'for_advancement', + 'checked', + auditionSetting('advanceTo'), + ]); + $entry2 = Entry::factory()->advanceOnly()->create(); + get(route('admin.entries.edit', $entry2)) + ->assertSeeInOrder([ + 'input', + 'name=', + 'for_seating', + 'checked', + auditionSetting('auditionAbbreviation'), + ]) + ->assertSeeInOrder([ + 'input', + 'name=', + 'for_advancement', + 'checked', + auditionSetting('advanceTo'), + ]); + +}); +// Submission tests diff --git a/tests/Pest.php b/tests/Pest.php index f711b53..6cd9f4c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -60,7 +60,7 @@ function actAsNormal() actingAs(User::factory()->create()); } -uses(TestCase::class)->beforeEach(function () { +uses()->beforeEach(function () { Settings::set('auditionName', 'Somewhere Band Directors Association'); Settings::set('auditionAbbreviation', 'SBDA'); Settings::set('registrationCode', 'secret'); @@ -75,5 +75,5 @@ uses(TestCase::class)->beforeEach(function () { Settings::set('payment_city', 'Washington'); Settings::set('payment_state', 'DC'); Settings::set('payment_zip', '20500'); -}); +})->in('Feature');