]> git.localhorst.tv Git - alttp.git/commitdiff
allow users to view their own unpublished result
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 20 Jun 2025 21:52:31 +0000 (23:52 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 20 Jun 2025 21:52:31 +0000 (23:52 +0200)
app/Http/Controllers/TournamentController.php
app/Models/Round.php
resources/js/components/results/DetailDialog.js
resources/js/components/results/Item.js
resources/js/helpers/permissions.js

index 72947ca0a30bbf45f668dd16a3d51a48c08213a5..eb4d0484210d28324fe1c2ce14cd9d3f6ae2cd55 100644 (file)
@@ -38,7 +38,7 @@ class TournamentController extends Controller
                        try {
                                $this->authorize('seeResults', $round);
                        } catch (AuthorizationException) {
-                               $round->hideResults();
+                               $round->hideResults($request->user());
                        }
                }
                $json = $tournament->toArray();
@@ -97,7 +97,7 @@ class TournamentController extends Controller
                        try {
                                $this->authorize('seeResults', $round);
                        } catch (AuthorizationException) {
-                               $round->hideResults();
+                               $round->hideResults($request->user());
                        }
                }
                return $rounds->toArray();
index fb78af161c7211c0c3ce9a237918387379bdfc77..68dee71f418a19a1c843648d83f858dbc759eb55 100644 (file)
@@ -101,9 +101,11 @@ class Round extends Model
        }
 
 
-       public function hideResults() {
+       public function hideResults(User $user = null) {
                foreach ($this->results as $result) {
-                       $result->makeHidden(['forfeit', 'placement', 'score', 'time']);
+                       if (!$user || $result->user_id != $user->id) {
+                               $result->makeHidden(['forfeit', 'placement', 'score', 'time']);
+                       }
                }
        }
 
index 5739bbfa90faea55dc9bf7cc69711ea633635928..60e6b747383defc082ab6092b5d66eacc6f08b57 100644 (file)
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
 
 import Box from '../users/Box';
 import { getTime } from '../../helpers/Result';
-import { maySeeResults } from '../../helpers/permissions';
+import { maySeeResult } from '../../helpers/permissions';
 import { findResult } from '../../helpers/User';
 import { useUser } from '../../hooks/user';
 
@@ -27,8 +27,8 @@ const DetailDialog = ({
                [round, user],
        );
        const maySee = React.useMemo(
-               () => maySeeResults(authUser, tournament, round),
-               [authUser, round, tournament],
+               () => maySeeResult(authUser, tournament, round, result),
+               [authUser, result, round, tournament],
        );
 
        return <Modal className="result-dialog" onHide={onHide} show={show}>
index 2e29d752afd2bd6938e82a5123c3b607bdea7308..a95bffef48305edf9ec5c479ba10fc23192a53dc 100644 (file)
@@ -7,7 +7,7 @@ import DetailDialog from './DetailDialog';
 import Icon from '../common/Icon';
 import Box from '../users/Box';
 import { getIcon, getTime } from '../../helpers/Result';
-import { maySeeResults } from '../../helpers/permissions';
+import { maySeeResult } from '../../helpers/permissions';
 import { findResult } from '../../helpers/User';
 import { useUser } from '../../hooks/user';
 
@@ -64,8 +64,8 @@ const Item = ({
                [round, user],
        );
        const maySee = React.useMemo(
-               () => maySeeResults(authUser, tournament, round),
-               [authUser, round, tournament],
+               () => maySeeResult(authUser, tournament, round, result),
+               [authUser, result, round, tournament],
        );
 
        return <div className="result">
index 9515417c05858cae07a5f6aaaf439e5bfd521ba1..f1be8765ce11134832f6edf8d343efcb010a9b74 100644 (file)
@@ -174,6 +174,13 @@ export const maySeeResults = (user, tournament, round) => {
        return false;
 };
 
+export const maySeeResult = (user, tournament, round, result) => {
+       if (user && result && user.id === result.user_id) {
+               return true;
+       }
+       return maySeeResults(user, tournament, round);
+};
+
 // Twitch
 
 export const mayManageTwitchBot = user => isAnyChannelAdmin(user);