From: Daniel Karbach
Date: Sat, 19 Mar 2022 11:43:31 +0000 (+0100)
Subject: lock rounds
X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=09c1644b5f64d7423905ae1be8f79da0b482289a;p=alttp.git
lock rounds
---
diff --git a/app/Console/Commands/LockRound.php b/app/Console/Commands/LockRound.php
new file mode 100644
index 0000000..f0f81c1
--- /dev/null
+++ b/app/Console/Commands/LockRound.php
@@ -0,0 +1,52 @@
+argument('round'));
+
+ if ($round->locked) {
+ $this->line('already locked');
+ return 0;
+ }
+
+ $round->locked = true;
+ $round->save();
+
+ Protocol::roundLocked(
+ $round->tournament,
+ $round,
+ );
+
+ RoundChanged::dispatch($round);
+
+ return 0;
+ }
+}
diff --git a/app/Http/Controllers/ResultController.php b/app/Http/Controllers/ResultController.php
index b23c907..d72a100 100644
--- a/app/Http/Controllers/ResultController.php
+++ b/app/Http/Controllers/ResultController.php
@@ -23,6 +23,9 @@ class ResultController extends Controller
$participant = Participant::findOrFail($validatedData['participant_id']);
$round = Round::findOrFail($validatedData['round_id']);
+ if (!$round || $round->locked) {
+ abort(403);
+ }
$user = $request->user();
if ($user->id != $participant->user->id) {
diff --git a/app/Models/Protocol.php b/app/Models/Protocol.php
index ddbc441..fee8b88 100644
--- a/app/Models/Protocol.php
+++ b/app/Models/Protocol.php
@@ -36,6 +36,19 @@ class Protocol extends Model
ProtocolAdded::dispatch($protocol);
}
+ public static function roundLocked(Tournament $tournament, Round $round, User $user = null) {
+ $protocol = static::create([
+ 'tournament_id' => $tournament->id,
+ 'user_id' => $user ? $user->id : null,
+ 'type' => 'round.lock',
+ 'details' => [
+ 'tournament' => static::tournamentMemo($tournament),
+ 'round' => static::roundMemo($round),
+ ],
+ ]);
+ ProtocolAdded::dispatch($protocol);
+ }
+
public static function roundSeedSet(Tournament $tournament, Round $round, User $user) {
$protocol = static::create([
'tournament_id' => $tournament->id,
diff --git a/app/Models/Round.php b/app/Models/Round.php
index 927307c..71a4273 100644
--- a/app/Models/Round.php
+++ b/app/Models/Round.php
@@ -19,6 +19,7 @@ class Round extends Model
protected $casts = [
'code' => 'array',
+ 'locked' => 'boolean',
];
protected $fillable = [
diff --git a/app/Policies/RoundPolicy.php b/app/Policies/RoundPolicy.php
index 1e29803..7ea3cac 100644
--- a/app/Policies/RoundPolicy.php
+++ b/app/Policies/RoundPolicy.php
@@ -101,6 +101,6 @@ class RoundPolicy
*/
public function setSeed(User $user, Round $round)
{
- return $user->role === 'admin' || $user->isParticipant($round->tournament);
+ return $user->role === 'admin' || ($user->isParticipant($round->tournament) && !$round->locked);
}
}
diff --git a/database/migrations/2022_03_19_102304_lock_rounds.php b/database/migrations/2022_03_19_102304_lock_rounds.php
new file mode 100644
index 0000000..30059d4
--- /dev/null
+++ b/database/migrations/2022_03_19_102304_lock_rounds.php
@@ -0,0 +1,32 @@
+boolean('locked')->default(false);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('rounds', function(Blueprint $table) {
+ $table->dropColumn('locked');
+ });
+ }
+};
diff --git a/resources/js/components/rounds/Item.js b/resources/js/components/rounds/Item.js
index 10549dd..d8fe9d8 100644
--- a/resources/js/components/rounds/Item.js
+++ b/resources/js/components/rounds/Item.js
@@ -34,7 +34,7 @@ const Item = ({
tournament={tournament}
/>
- {isParticipant(user, tournament) ?
+ {!round.locked && isParticipant(user, tournament) ?
(a, b) => {
if (b_forfeit) {
return 1;
}
- return 0;
+ return compareUsername(a, b);
};
export const compareUsername = (a, b) => {
diff --git a/resources/js/helpers/Tournament.js b/resources/js/helpers/Tournament.js
index 2c145a8..ff1a063 100644
--- a/resources/js/helpers/Tournament.js
+++ b/resources/js/helpers/Tournament.js
@@ -64,7 +64,7 @@ export const patchRound = (tournament, round) => {
if (!tournament) return tournament;
return {
...tournament,
- rounds: tournament.rounds.map(r => r.id === round.id ? round : r),
+ rounds: tournament.rounds.map(r => r.id === round.id ? { ...r, ...round } : r),
};
};