delete access permissions

This commit is contained in:
Laura Klünder 2017-12-08 22:18:05 +01:00
parent e5f33079b7
commit 9454c82058
3 changed files with 32 additions and 0 deletions

View file

@ -25,20 +25,29 @@
<h4>{% trans 'Access Permissions' %}</h4> <h4>{% trans 'Access Permissions' %}</h4>
{% if user.accesspermissions.all %} {% if user.accesspermissions.all %}
<form method="post">
{% csrf_token %}
<table> <table>
<tr> <tr>
<th>{% trans 'Access Restriction' %}</th> <th>{% trans 'Access Restriction' %}</th>
<th>{% trans 'expires' %}</th> <th>{% trans 'expires' %}</th>
<th>{% trans 'can grant' %}</th> <th>{% trans 'can grant' %}</th>
{% if request.user_permissions.access_all %}
<th></th>
{% endif %}
</tr> </tr>
{% for access_permission in user.accesspermissions.all %} {% for access_permission in user.accesspermissions.all %}
<tr> <tr>
<td>{{ access_permission.access_restriction.title }}</td> <td>{{ access_permission.access_restriction.title }}</td>
<td>{{ access_permission.expire_date }}</td> <td>{{ access_permission.expire_date }}</td>
<td>{% if access_permission.can_grant %}{% trans 'Yes' %}{% else %}{% trans 'No' %}{% endif %}</td> <td>{% if access_permission.can_grant %}{% trans 'Yes' %}{% else %}{% trans 'No' %}{% endif %}</td>
{% if request.user_permissions.access_all %}
<td class="button-cell"><button type="submit" name="delete_access_permission" value="{{ access_permission.pk }}">{% trans 'Delete' %}</button></td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</form>
{% else %} {% else %}
<p><em>{% trans 'none' %}</em></p> <p><em>{% trans 'none' %}</em></p>
{% endif %} {% endif %}

View file

@ -57,6 +57,18 @@ def user_detail(request, user):
) )
user = get_object_or_404(qs, pk=user) user = get_object_or_404(qs, pk=user)
if request.method == 'POST':
delete_access_permission = request.POST.get('delete_access_permission')
if delete_access_permission:
try:
permission = AccessPermission.objects.get(pk=delete_access_permission)
except AccessPermission.DoesNotExist:
messages.error(request, _('Unknown access permission.'))
else:
permission.delete()
messages.success(request, _('Access Permission successfully deleted.'))
return redirect(request.path_info)
ctx = { ctx = {
'user': user, 'user': user,
} }

View file

@ -700,6 +700,17 @@ main.control h4, main.control h2 {
main.control h4 { main.control h4 {
margin-top: 2.5rem; margin-top: 2.5rem;
} }
main.control form tr > * {
white-space: nowrap;
}
.button-cell {
padding-top: 4px;
padding-bottom: 4px;
text-align: right;
}
.button-cell button {
margin: 0;
}
.user-permissions-form label { .user-permissions-form label {
font-weight: 400; font-weight: 400;