]> git.localhorst.tv Git - alttp.git/commitdiff
prevent group swapping to finished rounds
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Nov 2025 10:43:38 +0000 (11:43 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Nov 2025 10:43:38 +0000 (11:43 +0100)
app/Policies/RoundPolicy.php
resources/js/helpers/permissions.js

index bd1f0e96bc86da05bb2190a21500808e514b8344..ba8c3ad42d001675bcdabe267c357348eff8e456 100644 (file)
@@ -184,7 +184,17 @@ class RoundPolicy
        public function swapGroup(User $user, Round $round)
        {
                $result = $user->findResult($round);
-               return $result && !$round->locked;
+               if (!$result || $round->locked || $round->tournament->locked) {
+                       return false;
+               }
+               $remaining = $round->tournament->rounds()
+                       ->where('number', '=', $round->number)
+                       ->where('group', '!=', $round->group)
+                       ->whereDoesntHave('results', function ($query) use ($user) {
+                               $query->where('user_id', '=', $user->id);
+                       })
+                       ->count();
+               return $remaining > 0;
        }
 
 }
index 3b9356ca2f4021fd65e2c97dd2143dc592ef1629..542d5a6c07ae14dc4b9488527e4949e7a1e93c71 100644 (file)
@@ -214,7 +214,13 @@ export const maySeeResult = (user, tournament, round, result) => {
 };
 
 export const maySwapGroup = (user, tournament, round, result) => {
-       return user && result && tournament?.group_size > 1 && !tournament.locked && round && !round.locked;
+       if (!user || !result || tournament?.group_size <= 1 || tournament.locked || !tournament?.rounds || !round || round.locked) {
+               return false;
+       }
+       const remaining_rounds = tournament.rounds.filter(
+               (r) => r.number === round.number && r.group !== round.group && !User.findResult(user, r),
+       );
+       return remaining_rounds.length > 0;
 };
 
 export const mayModifyResults = (user, tournament, round) => {