--- /dev/null
+<?php
+
+namespace App\Console\Commands;
+
+use App\Events\RoundChanged;
+use App\Models\Protocol;
+use App\Models\Round;
+use Illuminate\Console\Command;
+
+class LockRound extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'round:lock {round}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Lock the round';
+
+ /**
+ * Execute the console command.
+ *
+ * @return int
+ */
+ public function handle()
+ {
+ $round = Round::findOrFail($this->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;
+ }
+}
$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) {
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,
protected $casts = [
'code' => 'array',
+ 'locked' => 'boolean',
];
protected $fillable = [
*/
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);
}
}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('rounds', function(Blueprint $table) {
+ $table->boolean('locked')->default(false);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('rounds', function(Blueprint $table) {
+ $table->dropColumn('locked');
+ });
+ }
+};
tournament={tournament}
/>
</p>
- {isParticipant(user, tournament) ?
+ {!round.locked && isParticipant(user, tournament) ?
<p className="report">
<ReportButton
participant={findParticipant(tournament, user)}
round: PropTypes.shape({
code: PropTypes.arrayOf(PropTypes.string),
created_at: PropTypes.string,
+ locked: PropTypes.bool,
number: PropTypes.number,
seed: PropTypes.string,
}),
if (b_forfeit) {
return 1;
}
- return 0;
+ return compareUsername(a, b);
};
export const compareUsername = (a, b) => {
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),
};
};