diff --git a/api/permissions.py b/api/permissions.py index f371910b..38377c98 100644 --- a/api/permissions.py +++ b/api/permissions.py @@ -46,7 +46,7 @@ from django.http import HttpRequest from ninja_extra import ControllerBase from ninja_extra.permissions import BasePermission -from counter.models import Counter +from counter.utils import is_logged_in_counter class IsInGroup(BasePermission): @@ -186,12 +186,7 @@ class IsLoggedInCounter(BasePermission): """Check that a user is logged in a counter.""" def has_permission(self, request: HttpRequest, controller: ControllerBase) -> bool: - if "/counter/" not in request.META.get("HTTP_REFERER", ""): - return False - token = request.session.get("counter_token") - if not token: - return False - return Counter.objects.filter(token=token).exists() + return is_logged_in_counter(request) CanAccessLookup = IsLoggedInCounter | HasPerm("core.access_lookup") diff --git a/club/migrations/0017_linktype_clublink.py b/club/migrations/0017_linktype_clublink.py index 097e77f3..3e6d53ca 100644 --- a/club/migrations/0017_linktype_clublink.py +++ b/club/migrations/0017_linktype_clublink.py @@ -25,8 +25,7 @@ class Migration(migrations.Migration): "url_base", models.URLField( help_text=( - "The base url that links with this type " - "must respect (e.g. `https://www.instagram.com`)" + "The base url that links with this type must respect" ), unique=True, verbose_name="url base", diff --git a/club/models.py b/club/models.py index 6e98848e..a226cbcd 100644 --- a/club/models.py +++ b/club/models.py @@ -793,10 +793,7 @@ class LinkType(models.Model): url_base = models.URLField( "url base", unique=True, - help_text=_( - "The base url that links with this type must respect (e.g. `%(url)s`)" - ) - % {"url": "https://www.instagram.com"}, + help_text=_("The base url that links with this type must respect"), ) icon = models.CharField( _("icon"), diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 38da5e95..d4da37fc 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -43,6 +43,7 @@ from core.models import BanGroup, Group, Page, PageRev, SithFile, User from core.utils import resize_image from counter.models import ( Counter, + CounterSellers, Price, Product, ProductType, @@ -364,10 +365,10 @@ class Command(BaseCommand): Counter.objects.create(name="Carte AE", club=clubs.refound, type="OFFICE") # Add barman to counter - Counter.sellers.through.objects.bulk_create( + CounterSellers.objects.bulk_create( [ - Counter.sellers.through(counter_id=1, user=skia), # MDE - Counter.sellers.through(counter_id=2, user=krophil), # Foyer + CounterSellers(counter_id=1, user=skia, is_regular=True), # MDE + CounterSellers(counter_id=2, user=krophil, is_regular=True), # Foyer ] ) diff --git a/core/templates/core/base/header.jinja b/core/templates/core/base/header.jinja index de0169b9..5735f099 100644 --- a/core/templates/core/base/header.jinja +++ b/core/templates/core/base/header.jinja @@ -22,14 +22,9 @@

{% trans %}Total: {% endtrans %}{{ last_total }} €

{% endif %} - {% if barmen %} + {% if can_click %}

{% trans %}Enter client code:{% endtrans %}

-
+ {% csrf_token %} - - {{ form.as_p() }} + {{ form }}

{% else %} @@ -45,17 +44,36 @@ {% endif %} {% if counter.type == 'BAR' %} -
-

{% trans %}Barman: {% endtrans %}

+

{% trans %}Barmen:{% endtrans %}

+ + {% if barmen_here %} +
+
+

{% trans %}On this device{% endtrans %}

+ {% for b in barmen_here %} +

{{ barman_logout_link(b) }}

+ {% endfor %} +
+
+

{% trans %}Elsewhere{% endtrans %}

+ {% if barmen_here|length == barmen|length %} + {# all logged barmen are logged in this session #} +

{% trans %}No barman logged elsewhere{% endtrans %}

+ {% else %} + {% for b in barmen %} + {%- if b not in barmen_here -%} +

{{ barman_logout_link(b) }}

+ {%- endif -%} + {% endfor %} + {% endif %} +
+
+ {% else %} {% for b in barmen %}

{{ barman_logout_link(b) }}

{% endfor %} -
- {% csrf_token %} - {{ login_form.as_p() }} -

-
-
+ {% endif %} + {{ login_fragment }} {% endif %} {% endblock %} @@ -63,10 +81,10 @@ {{ super() }}