feat: allow players to update party effects (#206)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Gabriel Augendre 2024-03-05 19:05:41 +01:00 committed by GitHub
parent 92ac0caa33
commit 7f38d60365
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 66 deletions

View file

@ -3,17 +3,15 @@
<div class="card {% if rounds == 0 %}text-bg-secondary{% endif %} effect" data-id="{{ effect.pk }}"> <div class="card {% if rounds == 0 %}text-bg-secondary{% endif %} effect" data-id="{{ effect.pk }}">
<div class="card-body"> <div class="card-body">
<h5 class="card-title"> <h5 class="card-title">
{% if party.game_master == request.user %} <button
<button hx-get="{% url "party:delete_effect" pk=party.pk effect_pk=effect.pk %}"
hx-get="{% url "party:delete_effect" pk=party.pk effect_pk=effect.pk %}" hx-target="#effects"
hx-target="#effects" hx-swap="outerHTML"
hx-swap="outerHTML" class="btn btn-sm btn-danger delete"
class="btn btn-sm btn-danger delete" type="button"
type="button" >
> <i class="fa-solid fa-trash"></i>
<i class="fa-solid fa-trash"></i> </button>
</button>
{% endif %}
{{ effect.name }} {{ effect.name }}
</h5> </h5>
<h6 class="card-subtitle mb-2 {% if rounds != 0 %}text-muted{% endif %}"> <h6 class="card-subtitle mb-2 {% if rounds != 0 %}text-muted{% endif %}">

View file

@ -9,26 +9,24 @@
id="add-effect" id="add-effect"
class="btn btn-primary"><i class="fa-solid fa-plus"></i> Ajouter un effet class="btn btn-primary"><i class="fa-solid fa-plus"></i> Ajouter un effet
</button> </button>
{% if party.game_master == request.user %} <div class="btn-group">
<div class="btn-group"> <button
<button hx-get="{% url "party:increase_rounds" pk=party.pk %}"
hx-get="{% url "party:increase_rounds" pk=party.pk %}" hx-target="#effects"
hx-target="#effects" hx-swap="outerHTML"
hx-swap="outerHTML" type="button"
type="button" id="increase-rounds"
id="increase-rounds" class="btn btn-outline-secondary"><i class="fa-solid fa-plus"></i> tours
class="btn btn-outline-secondary"><i class="fa-solid fa-plus"></i> tours </button>
</button> <button
<button hx-get="{% url "party:decrease_rounds" pk=party.pk %}"
hx-get="{% url "party:decrease_rounds" pk=party.pk %}" hx-target="#effects"
hx-target="#effects" hx-swap="outerHTML"
hx-swap="outerHTML" type="button"
type="button" id="decrease-rounds"
id="decrease-rounds" class="btn btn-outline-secondary"><i class="fa-solid fa-minus"></i> tours
class="btn btn-outline-secondary"><i class="fa-solid fa-minus"></i> tours </button>
</button> </div>
</div>
{% endif %}
</div> </div>
<div id="effects-cards" class="row mt-1 row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4"> <div id="effects-cards" class="row mt-1 row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
{% for effect in party.effects.all %} {% for effect in party.effects.all %}

View file

@ -4,7 +4,6 @@ import pytest
from django.urls import reverse from django.urls import reverse
from model_bakery import baker from model_bakery import baker
from pytest_django.live_server_helper import LiveServer from pytest_django.live_server_helper import LiveServer
from selenium.common import NoSuchElementException
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.webdriver import WebDriver from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.select import Select from selenium.webdriver.support.select import Select
@ -285,37 +284,6 @@ def test_gm_can_delete_any_existing_effect(
BattleEffect.objects.get(pk=effects[1].pk) BattleEffect.objects.get(pk=effects[1].pk)
@pytest.mark.django_db()
def test_player_cant_change_existing_running_effect(
selenium: WebDriver,
live_server: LiveServer,
):
"""Members of the group can only view existing running effects, no update."""
user, password = "player", "password"
player = User.objects.create_user(user, password=password)
character = baker.make(Character, player=player)
party = baker.make(Party)
party.characters.set([character])
effects = baker.make(BattleEffect, _quantity=2, party=party)
go_to_party(selenium, live_server, party, user, password)
effect = effects[0]
effect_element = selenium.find_element(
By.CSS_SELECTOR,
f'.effect[data-id="{effect.pk}"]',
)
assert effect.name in effect_element.text
assert effect.target in effect_element.text
assert effect.description in effect_element.text
with pytest.raises(NoSuchElementException):
selenium.find_element(By.CSS_SELECTOR, ".effect .delete")
with pytest.raises(NoSuchElementException):
selenium.find_element(By.ID, "increase-rounds")
with pytest.raises(NoSuchElementException):
selenium.find_element(By.ID, "decrease-rounds")
def fill_effect( def fill_effect(
selenium: WebDriver, selenium: WebDriver,
name: str, name: str,

View file

@ -96,7 +96,7 @@ def party_add_effect(request, pk):
@require_GET @require_GET
@login_required @login_required
def party_increase_rounds(request, pk): def party_increase_rounds(request, pk):
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk) party = get_object_or_404(Party.objects.played_or_mastered_by(request.user), pk=pk)
party.effects.increase_rounds() party.effects.increase_rounds()
return render(request, "party/snippets/effects.html", {"party": party}) return render(request, "party/snippets/effects.html", {"party": party})
@ -104,7 +104,7 @@ def party_increase_rounds(request, pk):
@require_GET @require_GET
@login_required @login_required
def party_decrease_rounds(request, pk): def party_decrease_rounds(request, pk):
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk) party = get_object_or_404(Party.objects.played_or_mastered_by(request.user), pk=pk)
party.effects.decrease_rounds() party.effects.decrease_rounds()
return render(request, "party/snippets/effects.html", {"party": party}) return render(request, "party/snippets/effects.html", {"party": party})
@ -112,7 +112,7 @@ def party_decrease_rounds(request, pk):
@require_GET @require_GET
@login_required @login_required
def party_delete_effect(request, pk, effect_pk): def party_delete_effect(request, pk, effect_pk):
party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk) party = get_object_or_404(Party.objects.played_or_mastered_by(request.user), pk=pk)
BattleEffect.objects.filter(pk=effect_pk).delete() BattleEffect.objects.filter(pk=effect_pk).delete()
return render(request, "party/snippets/effects.html", {"party": party}) return render(request, "party/snippets/effects.html", {"party": party})