Add custom template filter 'has_group' and update question_link_header for improved user permission checks

This commit is contained in:
Ross
2026-03-25 22:12:33 +00:00
parent 2d48a6bad6
commit 5a050fb36d
3 changed files with 14 additions and 1 deletions
@@ -6,12 +6,13 @@
<a href="{% url 'rapids:question_delete' pk=question.pk %}" title="Delete the Rapid">Delete</a>
<a href="{% url 'rapids:question_answer_update' pk=question.pk %}" title="Update the question answers">Edit Answers</a>
<a href="#" onclick="return window.create_popup_window('{% url 'feedback_create' question_type='rapid' pk=question.pk %}')"> Add Note</a>
{% load rapids_extras %}
{% if request.user.is_superuser %}
<a href="{% url 'admin:rapids_rapid_change' question.id %}" title="Edit the Rapid using the admin interface">Admin Edit</a>
<a href="{% url 'rapids:question_user_answers' question.id %}" title="View user answers associated with this question">User answers</a>
{% endif %}
{% comment %} Migrate to shorts (authors / rapid_checkers / superusers) {% endcomment %}
{% if request.user.is_superuser or request.user in question.author.all or request.user.groups.filter(name='rapid_checker').exists %}
{% if request.user.is_superuser or request.user in question.author.all or request.user|has_group:"rapid_checker" %}
<a href="{% url 'rapids:question_migrate_to_shorts' pk=question.pk %}" onclick="return confirm('Migrate this Rapid to a Short question?')">Migrate to Shorts</a>
{% endif %}
{% if exam %}
View File
+12
View File
@@ -0,0 +1,12 @@
from django import template
register = template.Library()
@register.filter(name='has_group')
def has_group(user, group_name):
if user is None:
return False
try:
return user.groups.filter(name=group_name).exists()
except Exception:
return False