mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
702524d77d |
No files matched your search
@@ -190,6 +190,17 @@
|
||||
>
|
||||
{{ refilling_fragment }}
|
||||
</div>
|
||||
{% elif customer in request.barmen %}
|
||||
<div class="accordion-content">
|
||||
<p class="alert alert-yellow">
|
||||
{% trans trimmed %}
|
||||
You are able to refill AE accounts.
|
||||
However, it is forbidden to self-refill on a counter.
|
||||
To refill your account, please ask to another barman,
|
||||
or do it in the eboutic.
|
||||
{% endtrans %}
|
||||
</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="accordion-content">
|
||||
<p class="alert alert-yellow">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<form
|
||||
id="counter-refill-fragment"
|
||||
hx-trigger="submit"
|
||||
hx-post="{{ action }}"
|
||||
hx-swap="outerHTML"
|
||||
|
||||
@@ -18,7 +18,7 @@ from decimal import Decimal
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from bs4 import BeautifulSoup, SoupStrainer
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.hashers import make_password
|
||||
@@ -144,6 +144,24 @@ class TestRefilling(TestFullClickBase):
|
||||
),
|
||||
)
|
||||
|
||||
def refill_form_displayed(self, customer: User | Customer | None = None) -> bool:
|
||||
"""Assert the click interface is displayed,
|
||||
then return if it contains the refill form.
|
||||
"""
|
||||
if not customer:
|
||||
customer = self.customer
|
||||
click_res = self.client.get(
|
||||
reverse(
|
||||
"counter:click",
|
||||
kwargs={"counter_id": self.counter.id, "user_id": customer.pk},
|
||||
)
|
||||
)
|
||||
assert click_res.status_code == 200
|
||||
soup = BeautifulSoup(
|
||||
click_res.content, "lxml", parse_only=SoupStrainer(id="click-form")
|
||||
)
|
||||
return soup.find(id="counter-refill-fragment") is not None
|
||||
|
||||
def test_refilling_office_fail(self):
|
||||
self.client.force_login(self.club_admin)
|
||||
assert self.refill_user(self.customer, self.club_counter, 10).status_code == 403
|
||||
@@ -197,9 +215,22 @@ class TestRefilling(TestFullClickBase):
|
||||
|
||||
def test_refilling_counter_no_board_member(self):
|
||||
self.login_in_bar(barmen=self.barmen)
|
||||
assert not self.refill_form_displayed()
|
||||
assert self.refill_user(self.customer, self.counter, 10).status_code == 403
|
||||
assert self.updated_amount(self.customer) == 0
|
||||
|
||||
def test_self_refill_fails(self):
|
||||
"""Test that a barman cannot refill itself."""
|
||||
original_amount = self.barmen.customer.amount
|
||||
self.barmen.user_permissions.add(
|
||||
Permission.objects.get(codename="add_refilling")
|
||||
)
|
||||
self.login_in_bar(barmen=self.barmen)
|
||||
|
||||
assert not self.refill_form_displayed(customer=self.barmen)
|
||||
assert self.refill_user(self.barmen, self.counter, 10).status_code == 403
|
||||
assert self.updated_amount(self.customer) == original_amount
|
||||
|
||||
def test_refilling_user_can_not_buy(self):
|
||||
self.login_in_bar(barmen=self.barmen)
|
||||
|
||||
@@ -228,6 +259,7 @@ class TestRefilling(TestFullClickBase):
|
||||
def test_refilling_counter_success(self):
|
||||
self.login_in_bar()
|
||||
|
||||
assert self.refill_form_displayed()
|
||||
assert self.refill_user(self.customer, self.counter, 30).status_code == 302
|
||||
assert self.updated_amount(self.customer) == 30
|
||||
assert self.refill_user(self.customer, self.counter, 10.1).status_code == 302
|
||||
|
||||
+12
-3
@@ -147,7 +147,9 @@ class CounterClick(
|
||||
}
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.customer = get_object_or_404(Customer, user_id=self.kwargs["user_id"])
|
||||
self.customer = get_object_or_404(
|
||||
Customer.objects.select_related("user"), user_id=self.kwargs["user_id"]
|
||||
)
|
||||
obj: Counter = self.get_object()
|
||||
|
||||
if not self.customer.can_buy or self.customer.user.is_banned_counter:
|
||||
@@ -278,7 +280,11 @@ class CounterClick(
|
||||
res["student_card_fragment"] = StudentCardFormFragment.as_fragment()(
|
||||
self.request, customer=self.customer
|
||||
)
|
||||
if self.object.can_refill:
|
||||
if self.object.can_refill and self.customer.user not in self.request.barmen:
|
||||
# The counter must a bar with a barman allowed to refill.
|
||||
# However, a barman, even with the required permission,
|
||||
# cannot refill itself, which means the refilling process always
|
||||
# implies two persons (in order to prevent fraud and genuine errors).
|
||||
res["refilling_fragment"] = RefillingCreateView.as_fragment()(
|
||||
self.request, customer=self.customer, counter=self.object
|
||||
)
|
||||
@@ -312,7 +318,9 @@ class RefillingCreateView(FragmentMixin, CreateView):
|
||||
template_name = "counter/fragments/create_refill.jinja"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.customer: Customer = get_object_or_404(Customer, pk=kwargs["customer_id"])
|
||||
self.customer: Customer = get_object_or_404(
|
||||
Customer.objects.select_related("user"), pk=kwargs["customer_id"]
|
||||
)
|
||||
if not self.customer.can_buy:
|
||||
raise Http404
|
||||
|
||||
@@ -321,6 +329,7 @@ class RefillingCreateView(FragmentMixin, CreateView):
|
||||
if (
|
||||
not is_logged_in_counter(request, counter=self.counter)
|
||||
or not self.counter.can_refill
|
||||
or self.customer.user in self.request.barmen
|
||||
):
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-27 11:02+0100\n"
|
||||
"POT-Creation-Date: 2026-12-03 08:59+0100\n"
|
||||
"PO-Revision-Date: 2016-07-18\n"
|
||||
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||
@@ -3841,6 +3841,18 @@ msgstr "Terminer"
|
||||
msgid "Refilling"
|
||||
msgstr "Rechargement"
|
||||
|
||||
#: counter/templates/counter/counter_click.jinja
|
||||
msgid ""
|
||||
"You are able to refill AE accounts. However, it is forbidden to self-refill "
|
||||
"on a counter. To refill your account, please ask to another barman, or do it "
|
||||
"in the eboutic."
|
||||
msgstr ""
|
||||
"Vous avez le droit de recharger des comptes AE."
|
||||
"Cependant, le rechargement de son propre compte sur un comptoir"
|
||||
"est administrativement prohibé."
|
||||
"Pour recharger votre compte, veuillez demander à un autre"
|
||||
"barman ou passer par l'eboutic."
|
||||
|
||||
#: counter/templates/counter/counter_click.jinja
|
||||
msgid ""
|
||||
"As a barman, you are not able to refill any account on your own. An admin "
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ prod = [
|
||||
]
|
||||
dev = [
|
||||
"django-debug-toolbar>=8.0.0,<9",
|
||||
"ipython>=9.19.1,<10.0.0",
|
||||
"ipython>=9.18.1,<10.0.0",
|
||||
"pre-commit>=4.7.0,<5.0.0",
|
||||
"ruff>=0.17.6,<1.0.0",
|
||||
"djhtml>=3.0.11,<4.0.0",
|
||||
|
||||
Reference in new issue
Block a user