feat: Don't display edit buttons when no permission

This commit is contained in:
moanos [he/him] 2024-08-06 19:37:08 +02:00
parent 8c51597c29
commit 87188dbd4f
2 changed files with 8 additions and 5 deletions

View File

@ -5,10 +5,12 @@
{% block content %}
<div class="detail-adoption-notice-header">
<h1 class="detail-adoption-notice-header">{{ adoption_notice.name }}</h1>
<a class="btn2"
href="{% url 'adoption-notice-add-photo' adoption_notice_id=adoption_notice.pk %}">{% translate 'Foto hinzufügen' %}</a>
<a class="btn2 detail-adoption-notice-header"
href="{% url 'adoption-notice-edit' adoption_notice_id=adoption_notice.pk %}">{% translate 'Bearbeiten' %}</a>
{% if has_edit_permission %}
<a class="btn2"
href="{% url 'adoption-notice-add-photo' adoption_notice_id=adoption_notice.pk %}">{% translate 'Foto hinzufügen' %}</a>
<a class="btn2 detail-adoption-notice-header"
href="{% url 'adoption-notice-edit' adoption_notice_id=adoption_notice.pk %}">{% translate 'Bearbeiten' %}</a>
{% endif %}
</div>
<div class="table-adoption-notice-info">
<table>

View File

@ -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)