From 7720afcdc383632f7672d355456909f78be1e948 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 29 Jul 2024 23:30:52 +0900 Subject: fix: problem not available in watching page --- backend/api/handlers.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'backend/api/handlers.go') diff --git a/backend/api/handlers.go b/backend/api/handlers.go index c4810a0..273f68a 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -145,8 +145,8 @@ func (h *ApiHandler) GetGames(ctx context.Context, request GetGamesRequestObject } func (h *ApiHandler) GetGamesGameId(ctx context.Context, request GetGamesGameIdRequestObject) (GetGamesGameIdResponseObject, error) { - // TODO: user permission - // user := ctx.Value("user").(*auth.JWTClaims) + user := ctx.Value("user").(*auth.JWTClaims) + // TODO: check user permission gameId := request.GameId row, err := h.q.GetGameById(ctx, int32(gameId)) if err != nil { @@ -158,14 +158,16 @@ func (h *ApiHandler) GetGamesGameId(ctx context.Context, request GetGamesGameIdR startedAt = &startedAtTimestamp } var problem *Problem - if row.ProblemID != nil && GameState(row.State) != Closed && GameState(row.State) != WaitingEntries { + if row.ProblemID != nil { if row.Title == nil || row.Description == nil { panic("inconsistent data") } - problem = &Problem{ - ProblemId: int(*row.ProblemID), - Title: *row.Title, - Description: *row.Description, + if user.IsAdmin || (GameState(row.State) != Closed && GameState(row.State) != WaitingEntries) { + problem = &Problem{ + ProblemId: int(*row.ProblemID), + Title: *row.Title, + Description: *row.Description, + } } } game := Game{ -- cgit v1.2.3-70-g09d2