From 87188dbd4f4b26858cc03966d638d77389378c19 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 6 Aug 2024 19:37:08 +0200 Subject: [PATCH] feat: Don't display edit buttons when no permission --- .../details/detail_adoption_notice.html | 10 ++++++---- src/fellchensammlung/views.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html b/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html index 40ab138..36b2bd5 100644 --- a/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html +++ b/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html @@ -5,10 +5,12 @@ {% block content %}

{{ adoption_notice.name }}

- {% translate 'Foto hinzufügen' %} - {% translate 'Bearbeiten' %} + {% if has_edit_permission %} + {% translate 'Foto hinzufügen' %} + {% translate 'Bearbeiten' %} + {% endif %}
diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 92f5f1c..f59a20e 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -67,6 +67,7 @@ def change_language(request): def adoption_notice_detail(request, adoption_notice_id): adoption_notice = AdoptionNotice.objects.get(id=adoption_notice_id) + has_edit_permission = user_is_owner_or_trust_level(request.user, adoption_notice) if request.method == 'POST': if request.user.is_authenticated: comment_form = CommentForm(request.POST) @@ -95,7 +96,7 @@ def adoption_notice_detail(request, adoption_notice_id): raise PermissionDenied else: comment_form = CommentForm(instance=adoption_notice) - context = {"adoption_notice": adoption_notice, "comment_form": comment_form, "user": request.user} + context = {"adoption_notice": adoption_notice, "comment_form": comment_form, "user": request.user, "has_edit_permission": has_edit_permission} return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context)