mirror of
https://github.com/ae-utbm/sith.git
synced 2026-12-04 06:42:47 +00:00
feat: forbid self-refill on counters
This commit is contained in:
1 parent
ebb43658e1
commit
702524d77d
5 files changed
+70
-5
No files matched your search
+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
|
||||
|
||||
|
||||
Reference in new issue
Block a user