Skip to content

Commit 5e2df55

Browse files
committed
fix: only allow users to replay their own matches
[pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci
1 parent 190c413 commit 5e2df55

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

othello/apps/games/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ def replay(request: HttpRequest) -> HttpResponse:
201201
@login_required
202202
def match_replay(request: HttpRequest, match_id: int) -> HttpResponse:
203203
match = get_object_or_404(Match, id=match_id)
204+
if request.user not in [match.player1.user, match.player2.user]:
205+
messages.error(
206+
request,
207+
"You can only view replays of matches you participated in.",
208+
extra_tags="danger",
209+
)
210+
return redirect("games:queue")
204211
games = list(match.games.order_by("created_at"))
205212
selected_game_id = request.GET.get("game_id")
206213
if selected_game_id:

othello/templates/games/queue.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ <h1>Running Matches</h1>
4545
{{ match.player2.get_game_name }}
4646
</td>
4747
<td>{% if match.is_ranked %}Yes{% else %}No{% endif %}</td>
48-
<td>{{ match.status }}{% if match.status == 'completed' %} <a href="{% url 'games:match_replay' match.id %}">(Replay)</a>{% endif %}</td>
48+
<td>
49+
{{ match.status }}
50+
{% if match.status == 'completed' %}
51+
{% if user == match.player1.user or user == match.player2.user %}
52+
<a href="{% url 'games:match_replay' match.id %}">(Replay)</a>
53+
{% endif %}
54+
{% endif %}
55+
</td>
4956
<td>{{ match.created_at }}</td>
5057
</tr>
5158
{% endfor %}

0 commit comments

Comments
 (0)