better selection of who can make people refill

This commit is contained in:
imperosol
2026-09-16 23:32:57 +02:00
parent 22bf38beaf
commit ee6b4d4b1e
3 changed files with 14 additions and 8 deletions
+1
View File
@@ -747,6 +747,7 @@ class Command(BaseCommand):
"add_subscription",
"add_membership",
"view_hidden_user",
"add_refilling",
]
)
)
+11 -6
View File
@@ -669,13 +669,18 @@ class Counter(models.Model):
"""Update the barman activity to prevent timeout."""
self.permanencies.filter(end=None).update(activity=timezone.now())
@cached_property
def can_refill(self) -> bool:
"""Show if the counter authorize the refilling with physic money."""
if self.type != "BAR":
return False
# at least one of the barmen is in the AE board
ae = Club.objects.get(id=settings.SITH_MAIN_CLUB_ID)
return any(ae.get_membership_for(barman) for barman in self.barmen_list)
"""Show if the counter authorize the refilling with physic money.
Refills are authorized if a user having the required permission
is currently logged in.
"""
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:
"""Return a QuerySet querying the office hours stats of all the barmen of all time
+2 -2
View File
@@ -204,7 +204,7 @@ class CounterClick(
res["student_card_fragment"] = StudentCardFormFragment.as_fragment()(
self.request, customer=self.customer
)
if self.object.can_refill():
if self.object.can_refill:
res["refilling_fragment"] = RefillingCreateView.as_fragment()(
self.request, customer=self.customer, counter=self.object
)
@@ -250,7 +250,7 @@ class RefillingCreateView(FragmentMixin, CreateView):
if not (
request.barmen
and request.barmen.issubset(self.counter.barmen_list)
and self.counter.can_refill()
and self.counter.can_refill
):
raise PermissionDenied