diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-03-20 21:30:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-03-20 21:30:22 +0900 |
| commit | fc191e09c8b1acd8cfefc43a6e678a6d38e4ce12 (patch) | |
| tree | 933f5d8ac7e87fa6c2b7ca0fe1f2028cf47b2954 /backend/game/service.go | |
| parent | cd7a1532535cd5fa314ec4f0c9b51c571f38ec12 (diff) | |
| download | phperkaigi-2026-albatross-fc191e09c8b1acd8cfefc43a6e678a6d38e4ce12.tar.gz phperkaigi-2026-albatross-fc191e09c8b1acd8cfefc43a6e678a6d38e4ce12.tar.zst phperkaigi-2026-albatross-fc191e09c8b1acd8cfefc43a6e678a6d38e4ce12.zip | |
fix(game): allow participants to view watch states after game finishes
Previously GetWatchLatestStates returned ErrForbidden for participants
regardless of game state. Now checks whether the game has finished and
permits access once complete. Also fixes config test env var cleanup.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'backend/game/service.go')
| -rw-r--r-- | backend/game/service.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/backend/game/service.go b/backend/game/service.go index a054388..dc23061 100644 --- a/backend/game/service.go +++ b/backend/game/service.go @@ -293,6 +293,15 @@ func (s *Service) GetLatestState(ctx context.Context, gameID int, userID int32) } func (s *Service) GetWatchLatestStates(ctx context.Context, gameID int, userID *int32, isAdmin bool) (map[int]LatestState, error) { + gameRow, err := s.q.GetGameByID(ctx, int32(gameID)) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return nil, ErrNotFound + } + return nil, err + } + finished := IsGameFinished(gameRow.StartedAt, gameRow.DurationSeconds) + rows, err := s.q.GetLatestStatesOfMainPlayers(ctx, int32(gameID)) if err != nil { return nil, err @@ -320,7 +329,7 @@ func (s *Service) GetWatchLatestStates(ctx context.Context, gameID int, userID * submittedAt = &ts } - if userID != nil && row.UserID == *userID && !isAdmin { + if userID != nil && row.UserID == *userID && !isAdmin && !finished { return nil, ErrForbidden } |
