diff --git a/src/party/templates/party/snippets/effect_card.html b/src/party/templates/party/snippets/effect_card.html index e1f82af..3a5e222 100644 --- a/src/party/templates/party/snippets/effect_card.html +++ b/src/party/templates/party/snippets/effect_card.html @@ -2,7 +2,20 @@
-
{{ effect.name }}
+
+ {% if party.game_master == request.user %} + + {% endif %} + {{ effect.name }} +
{{ effect.created_by.get_full_name|default:effect.created_by.username }} {{ effect.target }} diff --git a/src/party/templates/party/snippets/effects.html b/src/party/templates/party/snippets/effects.html index 0b9de97..5bdf15f 100644 --- a/src/party/templates/party/snippets/effects.html +++ b/src/party/templates/party/snippets/effects.html @@ -17,7 +17,7 @@ hx-swap="outerHTML" type="button" id="increase-rounds" - class="btn btn-outline-secondary"> tours + class="btn btn-outline-secondary"> tours
{% endif %} diff --git a/src/party/tests/test_interactions.py b/src/party/tests/test_interactions.py index 3cbe128..e68d2ea 100644 --- a/src/party/tests/test_interactions.py +++ b/src/party/tests/test_interactions.py @@ -4,6 +4,7 @@ import pytest from django.urls import reverse from model_bakery import baker from pytest_django.live_server_helper import LiveServer +from selenium.common import NoSuchElementException from selenium.webdriver.common.by import By from selenium.webdriver.firefox.webdriver import WebDriver from selenium.webdriver.support.select import Select @@ -233,18 +234,25 @@ def test_gm_can_change_remaining_rounds( ) -@pytest.mark.django_db -def test_gm_can_update_existing_effect( - selenium: WebDriver, live_server: LiveServer, initial_data: None -): - """The GM of a group can update existing effect, except group and creator.""" - - @pytest.mark.django_db def test_gm_can_delete_any_existing_effect( selenium: WebDriver, live_server: LiveServer, initial_data: None ): """The GM of a group can delete any existing effect, running or terminated.""" + user, password = "gm", "password" + gm = User.objects.create_user(user, password=password) + party = baker.make(Party, game_master=gm) + effects = baker.make(BattleEffect, _quantity=2, party=party) + + assert BattleEffect.objects.count() == 2 + + go_to_party(selenium, live_server, party, user, password) + selenium.find_element( + By.CSS_SELECTOR, f'.effect[data-id="{effects[0].pk}"] .delete' + ).click() + + assert BattleEffect.objects.count() == 1 + BattleEffect.objects.get(pk=effects[1].pk) @pytest.mark.django_db @@ -252,13 +260,28 @@ def test_player_cant_change_existing_running_effect( selenium: WebDriver, live_server: LiveServer, initial_data: None ): """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 -@pytest.mark.django_db -def test_player_can_delete_terminated_effect( - selenium: WebDriver, live_server: LiveServer, initial_data: None -): - """Members of the group can delete terminated effects.""" + 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(selenium, name, description, target, remaining_rounds): diff --git a/src/party/urls.py b/src/party/urls.py index 568698d..bcd34c8 100644 --- a/src/party/urls.py +++ b/src/party/urls.py @@ -11,6 +11,11 @@ urlpatterns = [ path("/delete/", views.party_delete, name="delete"), path("/reset_stats/", views.party_reset_stats, name="reset_stats"), path("/add_effect/", views.party_add_effect, name="add_effect"), + path( + "/delete_effect//", + views.party_delete_effect, + name="delete_effect", + ), path( "/increase_rounds/", views.party_increase_rounds, name="increase_rounds" ), diff --git a/src/party/views.py b/src/party/views.py index 1d298d2..7f4d816 100644 --- a/src/party/views.py +++ b/src/party/views.py @@ -5,7 +5,7 @@ from django.views.decorators.http import require_GET, require_http_methods from character.models import Character, HarmfulState from party.forms import BattleEffectForm, PartyForm -from party.models import Party +from party.models import BattleEffect, Party @require_GET @@ -109,6 +109,14 @@ def party_decrease_rounds(request, pk): return render(request, "party/snippets/effects.html", {"party": party}) +@require_GET +@login_required +def party_delete_effect(request, pk, effect_pk): + party = get_object_or_404(Party.objects.managed_by(request.user), pk=pk) + BattleEffect.objects.filter(pk=effect_pk).delete() + return render(request, "party/snippets/effects.html", {"party": party}) + + @require_http_methods(["GET", "POST"]) @login_required def party_change(request, pk):