diff --git a/app/Http/Controllers/JudgingController.php b/app/Http/Controllers/JudgingController.php index 7c764d6..41c7dab 100644 --- a/app/Http/Controllers/JudgingController.php +++ b/app/Http/Controllers/JudgingController.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Gate; use Tests\Feature\Models\ScoreSheet; + use function compact; use function redirect; use function url; @@ -31,8 +32,9 @@ class JudgingController extends Controller $subscores = $audition->scoringGuide->subscores()->orderBy('display_order')->get(); $votes = JudgeAdvancementVote::where('user_id', Auth::id())->get(); + $published = $audition->hasFlag('advancement_published') || $audition->hasFlag('seats_published'); - return view('judging.audition_entry_list', compact('audition', 'entries', 'subscores', 'votes')); + return view('judging.audition_entry_list', compact('audition', 'entries', 'subscores', 'votes', 'published')); } public function entryScoreSheet(Request $request, Entry $entry) @@ -40,6 +42,9 @@ class JudgingController extends Controller if ($request->user()->cannot('judge', $entry->audition)) { return redirect()->route('judging.index')->with('error', 'You are not assigned to judge this entry'); } + if ($entry->audition->hasFlag('seats_published') || $entry->audition->hasFlag('advancement_published')) { + return redirect()->route('judging.auditionEntryList', $entry->audition)->with('error', 'Scores for entries in published auditions cannot be modified'); + } $oldSheet = ScoreSheet::where('user_id', Auth::id())->where('entry_id', $entry->id)->value('subscores') ?? null; $oldVote = JudgeAdvancementVote::where('user_id', Auth::id())->where('entry_id', $entry->id)->first(); $oldVote = $oldVote ? $oldVote->vote : 'novote'; diff --git a/resources/views/judging/audition_entry_list.blade.php b/resources/views/judging/audition_entry_list.blade.php index a510a12..6d99fb5 100644 --- a/resources/views/judging/audition_entry_list.blade.php +++ b/resources/views/judging/audition_entry_list.blade.php @@ -2,7 +2,12 @@ Judging Dashboard - {{ $audition->name }} + + {{ $audition->name }} + @if($published) + Results are published. Scores cannot be changed. + @endif + @@ -20,9 +25,13 @@ @foreach($entries as $entry) - + @if(! $published) + + @endif {{ $audition->name }} {{ $entry->draw_number }} - + @if(! $published) + + @endif @foreach($subscores as $subscore) diff --git a/tests/Feature/Pages/JudgingAudtionEntryListTest.php b/tests/Feature/Pages/JudgingAudtionEntryListTest.php index 00dd7ff..a6fc741 100644 --- a/tests/Feature/Pages/JudgingAudtionEntryListTest.php +++ b/tests/Feature/Pages/JudgingAudtionEntryListTest.php @@ -12,6 +12,8 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Artisan; use Tests\Feature\Models\ScoreSheet; +use function Pest\Laravel\actingAs; + uses(RefreshDatabase::class); beforeEach(function () { @@ -110,10 +112,19 @@ test('it shows scores previously entered', function () { }); it('indicates when an audition has published seats or advancement', function () { // Arrange - $seatsPublishedAudition = Audition::factory()->create(); - $advancePublishedAudition = Audition::factory()->create(); - $seatsPublishedAudition->addFlag('seats_published'); - $advancePublishedAudition->addFlag('advancement_published'); - // Act & Assert - + $this->audition->addFlag('seats_published'); + actingAs($this->user); + // Act + $response = $this->get(route('judging.auditionEntryList', $this->audition)); + // Assert + $response->assertOk() + ->assertSee('Results are published. Scores cannot be changed.'); + $this->audition->removeFlag('seats_published'); + $response = $this->get(route('judging.auditionEntryList', $this->audition)); + $response->assertOk() + ->assertDontSee('Results are published. Scores cannot be changed.'); + $this->audition->addFlag('advancement_published'); + $response = $this->get(route('judging.auditionEntryList', $this->audition)); + $response->assertOk() + ->assertSee('Results are published. Scores cannot be changed.'); }); diff --git a/tests/Feature/Pages/JudgingEntryScoreSheetTest.php b/tests/Feature/Pages/JudgingEntryScoreSheetTest.php index 990c674..bc73c59 100644 --- a/tests/Feature/Pages/JudgingEntryScoreSheetTest.php +++ b/tests/Feature/Pages/JudgingEntryScoreSheetTest.php @@ -118,3 +118,25 @@ it('allows an assigned judge to enter scores', function () { 'td', $arrayToTest[4], '/td', ]); }); +it('redirects if seats are published', function () { + // Arrange + $this->entries->first()->audition->addFlag('seats_published'); + $this->actingAs($this->user); + // Act + $response = $this->get(route('judging.entryScoreSheet', $this->entries->first())); + // Assert + $response->assertRedirect(route('judging.auditionEntryList', $this->entries[0]->audition)) + ->assertSessionHas('error', 'Scores for entries in published auditions cannot be modified'); + +}); +it('redirects if advancement is published', function () { + // Arrange + $this->entries->first()->audition->addFlag('advancement_published'); + $this->actingAs($this->user); + // Act + $response = $this->get(route('judging.entryScoreSheet', $this->entries->first())); + // Assert + $response->assertRedirect(route('judging.auditionEntryList', $this->entries[0]->audition)) + ->assertSessionHas('error', 'Scores for entries in published auditions cannot be modified'); + +});