diff --git a/app/Http/Controllers/EntryController.php b/app/Http/Controllers/EntryController.php
index 2932b4f..744c690 100644
--- a/app/Http/Controllers/EntryController.php
+++ b/app/Http/Controllers/EntryController.php
@@ -41,6 +41,7 @@ class EntryController extends Controller
public function destroy(Request $request, Entry $entry)
{
+ if ($request->user()->cannot('delete', $entry)) abort(403);
$entry->delete();
return redirect('/entries')->with('success','The ' . $entry->audition->name . 'entry for ' . $entry->student->full_name(). 'has been deleted.');
diff --git a/app/Http/Controllers/JudgingController.php b/app/Http/Controllers/JudgingController.php
index a531089..8857ab2 100644
--- a/app/Http/Controllers/JudgingController.php
+++ b/app/Http/Controllers/JudgingController.php
@@ -33,7 +33,8 @@ class JudgingController extends Controller
public function entryScoreSheet(Entry $entry)
{
// TODO verify user is assigned to judge this audition
- return view('judging.entry_score_sheet',compact('entry'));
+ $oldSheet = ScoreSheet::where('user_id',Auth::id())->where('entry_id',$entry->id)->value('subscores') ?? null;
+ return view('judging.entry_score_sheet',compact('entry','oldSheet'));
}
public function saveScoreSheet(Request $request, Entry $entry)
@@ -64,5 +65,31 @@ class JudgingController extends Controller
}
+ public function updateScoreSheet(Request $request, Entry $entry)
+ {
+ $scoreSheet = ScoreSheet::where('user_id',Auth::id())->where('entry_id',$entry->id)->first();
+ if (!$scoreSheet) return redirect()->back()->with('error','Attempt to edit non existent entry');
+ Gate::authorize('update',$scoreSheet);
+
+ $scoringGuide = $entry->audition->scoringGuide()->with('subscores')->first();
+ $scoreValidation = $scoringGuide->validateScores($request->input('score'));
+ if ($scoreValidation != 'success') {
+ return redirect(url()->previous())->with('error', $scoreValidation)->with('oldScores',$request->all());
+ }
+ $scoreSheetArray = [];
+ foreach($scoringGuide->subscores as $subscore) {
+ $scoreSheetArray[$subscore->id] = [
+ 'score' => $request->input('score')[$subscore->id],
+ 'subscore_id' => $subscore->id,
+ 'subscore_name' => $subscore->name
+ ];
+ }
+
+ $scoreSheet->update([
+ 'subscores' => $scoreSheetArray
+ ]);
+ return redirect('/judging/audition/' . $entry->audition_id)->with('success','Updated scores for ' . $entry->audition->name . ' ' . $entry->draw_number);
+ }
+
}
diff --git a/app/Policies/EntryPolicy.php b/app/Policies/EntryPolicy.php
index abd0e6e..e080f66 100644
--- a/app/Policies/EntryPolicy.php
+++ b/app/Policies/EntryPolicy.php
@@ -50,6 +50,11 @@ class EntryPolicy
public function delete(User $user, Entry $entry): bool
{
if($user->is_admin) return true;
+ // Return false if $entry->audition->entry_deadline is in the past, continue if not
+ if ($entry->audition->entry_deadline < now()) {
+ return false;
+ }
+
return $user->school_id == $entry->student()->school_id;
}
diff --git a/app/Policies/ScoreSheetPolicy.php b/app/Policies/ScoreSheetPolicy.php
index 3b3f900..c83ebdd 100644
--- a/app/Policies/ScoreSheetPolicy.php
+++ b/app/Policies/ScoreSheetPolicy.php
@@ -39,7 +39,7 @@ class ScoreSheetPolicy
*/
public function update(User $user, ScoreSheet $scoreSheet): bool
{
- //
+ return $user->id == $scoreSheet->user_id;
}
/**
diff --git a/phpunit.xml b/phpunit.xml
index 506b9a3..c1c967f 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -22,8 +22,8 @@