]> git.localhorst.tv Git - alttp.git/commitdiff
broadcast results with locked rounds
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 29 Jun 2025 12:00:04 +0000 (14:00 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 29 Jun 2025 12:00:04 +0000 (14:00 +0200)
app/Console/Commands/UnlockRound.php [new file with mode: 0644]
app/Events/RoundChanged.php
app/Http/Controllers/ResultController.php
app/Http/Controllers/TournamentController.php
app/Models/Result.php
app/Models/Round.php
resources/js/components/results/Item.jsx
resources/js/helpers/Round.js
resources/js/pages/Tournament.jsx

diff --git a/app/Console/Commands/UnlockRound.php b/app/Console/Commands/UnlockRound.php
new file mode 100644 (file)
index 0000000..3f58fea
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Events\RoundChanged;
+use App\Models\Protocol;
+use App\Models\Round;
+use Illuminate\Console\Command;
+
+class UnlockRound extends Command
+{
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'round:unlock {round}';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Unlock the round';
+
+       /**
+        * Execute the console command.
+        *
+        * @return int
+        */
+       public function handle()
+       {
+               $round = Round::findOrFail($this->argument('round'));
+
+               if (!$round->locked) {
+                       $this->line('already unlocked');
+                       return 0;
+               }
+
+               $round->locked = false;
+               $round->save();
+
+               Protocol::roundUnlocked(
+                       $round->tournament,
+                       $round,
+               );
+
+               RoundChanged::dispatch($round);
+
+               return 0;
+       }
+}
index 926e2e26b5656c2f6911f7732729f1a527fe127c..74ba0b15b4852d26c40fa3f51bc2540f5063ea4b 100644 (file)
@@ -24,6 +24,9 @@ class RoundChanged implements ShouldBroadcast
        {
                $this->round = $round;
                $this->round->setRelations([]);
+               if ($this->round->locked) {
+                       $round->load(['results', 'results.user']);
+               }
        }
 
        /**
index ba57c4b0759f45c33b0bb72fe776ec02cc65a5c7..16327c6fe23dad37add1614820974767a22fdbb7 100644 (file)
@@ -9,6 +9,7 @@ use App\Models\Result;
 use App\Models\Round;
 use App\Models\User;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Gate;
 
 class ResultController extends Controller
 {
@@ -68,6 +69,10 @@ class ResultController extends Controller
 
                $result->load('user');
 
+               if (!Gate::allows('seeResults', $round)) {
+                       $result->hideResult($request->user());
+               }
+
                return $result->toJson();
        }
 
index eb4d0484210d28324fe1c2ce14cd9d3f6ae2cd55..12289a27690aa58bcc6e7bf16ed2a5cfa1bd42a2 100644 (file)
@@ -9,6 +9,7 @@ use App\Models\Protocol;
 use App\Models\Tournament;
 use Illuminate\Auth\Access\AuthorizationException;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Gate;
 
 class TournamentController extends Controller
 {
@@ -35,9 +36,7 @@ class TournamentController extends Controller
                $this->authorize('view', $tournament);
                $rounds = $tournament->rounds()->with(['results', 'results.user'])->limit(25)->get();
                foreach ($rounds as $round) {
-                       try {
-                               $this->authorize('seeResults', $round);
-                       } catch (AuthorizationException) {
+                       if (!Gate::allows('seeResults', $round)) {
                                $round->hideResults($request->user());
                        }
                }
@@ -94,9 +93,7 @@ class TournamentController extends Controller
                        ->with(['results', 'results.user'])
                        ->limit(25)->get();
                foreach ($rounds as $round) {
-                       try {
-                               $this->authorize('seeResults', $round);
-                       } catch (AuthorizationException) {
+                       if (!Gate::allows('seeResults', $round)) {
                                $round->hideResults($request->user());
                        }
                }
index 229ac4b9c8e418c5d52cf9de99c33e07122eaf26..ab9f49ffdc838f4039a858144992a1d9cb2dfb3c 100644 (file)
@@ -68,6 +68,15 @@ class Result extends Model
        }
 
 
+       public function hideResult(User $user = null) {
+               if (!$user || $this->user_id != $user->id) {
+                       $this->makeHidden(['forfeit', 'placement', 'score', 'time']);
+               } else {
+                       $this->makeHidden(['placement', 'score']);
+               }
+       }
+
+
        public function round() {
                return $this->belongsTo(Round::class);
        }
index 68dee71f418a19a1c843648d83f858dbc759eb55..c9435c285867e20e0974fbcc81bb6023806bca95 100644 (file)
@@ -103,9 +103,7 @@ class Round extends Model
 
        public function hideResults(User $user = null) {
                foreach ($this->results as $result) {
-                       if (!$user || $result->user_id != $user->id) {
-                               $result->makeHidden(['forfeit', 'placement', 'score', 'time']);
-                       }
+                       $result->hideResult($user);
                }
        }
 
index a95bffef48305edf9ec5c479ba10fc23192a53dc..da0c99e88f9c21289837fb5fda359ce7967c32e8 100644 (file)
@@ -79,7 +79,7 @@ const Item = ({
                                <span className="time">
                                        {getTime(result, maySee)}
                                </span>
-                               {getIcon(result, maySee)}
+                               {getIcon(result, maySeeResult(authUser, tournament, round))}
                        </Button>
                        {maySee && result && result.vod ?
                                <Button
index 2096759cf12a7f81b96055761b3a84d1312ce303..68579b84815cd15fad98c2c9463af3a8c8553346 100644 (file)
@@ -28,7 +28,7 @@ export const patchResult = (round, result) => {
        }
        return {
                ...round,
-               results: round.results.map(r => r.id === result.id ? result : r),
+               results: round.results.map(r => r.id === result.id ? { ...r, ...result } : r),
        };
 };
 
index a374fe907ff9e93c2142b9420943e53d4466a8c1..661eaa7c687975d1d87baff6799875259dd58799 100644 (file)
@@ -128,7 +128,6 @@ export const Component = () => {
        const moreRounds = React.useCallback(async () => {
                const last_round = getLastRound(tournament);
                if (!last_round) return;
-               console.log(last_round);
                const last_known = last_round.number;
                const rsp = await axios.get(
                        `/api/tournaments/${id}/more-rounds`,
@@ -153,7 +152,7 @@ export const Component = () => {
                        }));
                        setShowContentDialog(false);
                } catch (e) {
-                       toastr.error(t('content.saveError'));
+                       toastr.error(t('content.saveError', e));
                }
        }, [tournament && tournament.description_id]);