mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-17 17:54:22 +00:00
better selection of who can make people refill
This commit is contained in:
@@ -747,6 +747,7 @@ class Command(BaseCommand):
|
|||||||
"add_subscription",
|
"add_subscription",
|
||||||
"add_membership",
|
"add_membership",
|
||||||
"view_hidden_user",
|
"view_hidden_user",
|
||||||
|
"add_refilling",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
+11
-6
@@ -669,13 +669,18 @@ class Counter(models.Model):
|
|||||||
"""Update the barman activity to prevent timeout."""
|
"""Update the barman activity to prevent timeout."""
|
||||||
self.permanencies.filter(end=None).update(activity=timezone.now())
|
self.permanencies.filter(end=None).update(activity=timezone.now())
|
||||||
|
|
||||||
|
@cached_property
|
||||||
def can_refill(self) -> bool:
|
def can_refill(self) -> bool:
|
||||||
"""Show if the counter authorize the refilling with physic money."""
|
"""Show if the counter authorize the refilling with physic money.
|
||||||
if self.type != "BAR":
|
|
||||||
return False
|
Refills are authorized if a user having the required permission
|
||||||
# at least one of the barmen is in the AE board
|
is currently logged in.
|
||||||
ae = Club.objects.get(id=settings.SITH_MAIN_CLUB_ID)
|
"""
|
||||||
return any(ae.get_membership_for(barman) for barman in self.barmen_list)
|
return self.type == "BAR" and (
|
||||||
|
User.objects.with_perm("counter.add_refilling")
|
||||||
|
.filter(id__in=[u.id for u in self.barmen_list])
|
||||||
|
.exists()
|
||||||
|
)
|
||||||
|
|
||||||
def get_top_barmen(self) -> QuerySet:
|
def get_top_barmen(self) -> QuerySet:
|
||||||
"""Return a QuerySet querying the office hours stats of all the barmen of all time
|
"""Return a QuerySet querying the office hours stats of all the barmen of all time
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class CounterClick(
|
|||||||
res["student_card_fragment"] = StudentCardFormFragment.as_fragment()(
|
res["student_card_fragment"] = StudentCardFormFragment.as_fragment()(
|
||||||
self.request, customer=self.customer
|
self.request, customer=self.customer
|
||||||
)
|
)
|
||||||
if self.object.can_refill():
|
if self.object.can_refill:
|
||||||
res["refilling_fragment"] = RefillingCreateView.as_fragment()(
|
res["refilling_fragment"] = RefillingCreateView.as_fragment()(
|
||||||
self.request, customer=self.customer, counter=self.object
|
self.request, customer=self.customer, counter=self.object
|
||||||
)
|
)
|
||||||
@@ -250,7 +250,7 @@ class RefillingCreateView(FragmentMixin, CreateView):
|
|||||||
if not (
|
if not (
|
||||||
request.barmen
|
request.barmen
|
||||||
and request.barmen.issubset(self.counter.barmen_list)
|
and request.barmen.issubset(self.counter.barmen_list)
|
||||||
and self.counter.can_refill()
|
and self.counter.can_refill
|
||||||
):
|
):
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user