From: Daniel Karbach Date: Sun, 29 Jun 2025 12:00:04 +0000 (+0200) Subject: broadcast results with locked rounds X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=b876038263871e1217e6369016966caf2e736c03;p=alttp.git broadcast results with locked rounds --- diff --git a/app/Console/Commands/UnlockRound.php b/app/Console/Commands/UnlockRound.php new file mode 100644 index 0000000..3f58fea --- /dev/null +++ b/app/Console/Commands/UnlockRound.php @@ -0,0 +1,52 @@ +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; + } +} diff --git a/app/Events/RoundChanged.php b/app/Events/RoundChanged.php index 926e2e2..74ba0b1 100644 --- a/app/Events/RoundChanged.php +++ b/app/Events/RoundChanged.php @@ -24,6 +24,9 @@ class RoundChanged implements ShouldBroadcast { $this->round = $round; $this->round->setRelations([]); + if ($this->round->locked) { + $round->load(['results', 'results.user']); + } } /** diff --git a/app/Http/Controllers/ResultController.php b/app/Http/Controllers/ResultController.php index ba57c4b..16327c6 100644 --- a/app/Http/Controllers/ResultController.php +++ b/app/Http/Controllers/ResultController.php @@ -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(); } diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index eb4d048..12289a2 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -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()); } } diff --git a/app/Models/Result.php b/app/Models/Result.php index 229ac4b..ab9f49f 100644 --- a/app/Models/Result.php +++ b/app/Models/Result.php @@ -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); } diff --git a/app/Models/Round.php b/app/Models/Round.php index 68dee71..c9435c2 100644 --- a/app/Models/Round.php +++ b/app/Models/Round.php @@ -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); } } diff --git a/resources/js/components/results/Item.jsx b/resources/js/components/results/Item.jsx index a95bffe..da0c99e 100644 --- a/resources/js/components/results/Item.jsx +++ b/resources/js/components/results/Item.jsx @@ -79,7 +79,7 @@ const Item = ({ {getTime(result, maySee)} - {getIcon(result, maySee)} + {getIcon(result, maySeeResult(authUser, tournament, round))} {maySee && result && result.vod ?