diff --git a/src/postorius/templates/postorius/users/index.html b/src/postorius/templates/postorius/users/index.html index 54979ce..d9c2ec4 100644 --- a/src/postorius/templates/postorius/users/index.html +++ b/src/postorius/templates/postorius/users/index.html @@ -16,6 +16,7 @@ {% trans 'Email' %} {% trans 'Display name' %} + @@ -29,6 +30,9 @@ {{ mm_user.display_name }} + + Delete + diff --git a/src/postorius/templates/postorius/users/new.html b/src/postorius/templates/postorius/users/new.html index c41e2ad..04d8b55 100644 --- a/src/postorius/templates/postorius/users/new.html +++ b/src/postorius/templates/postorius/users/new.html @@ -1,4 +1,4 @@ -{% extends extend_template %} +{% extends postorius_base_template %} {% load url from future %} {% load i18n %} {% load nav_helpers %} diff --git a/src/postorius/templates/postorius/users/user_confirm_delete.html b/src/postorius/templates/postorius/users/user_confirm_delete.html new file mode 100644 index 0000000..e9376af --- /dev/null +++ b/src/postorius/templates/postorius/users/user_confirm_delete.html @@ -0,0 +1,13 @@ +{% extends "postorius/base.html" %} +{% load url from future %} +{% load i18n %} +{% load nav_helpers %} + +{% block main %} +

{% trans 'Confirm Deletion' %}

+

{% trans "Are you sure you want to permanently delete this user ?" %}

+
{% csrf_token %} + + {% trans "Cancel" %} +
+{% endblock main %} diff --git a/src/postorius/urls.py b/src/postorius/urls.py index 7288dd2..6ddeb61 100644 --- a/src/postorius/urls.py +++ b/src/postorius/urls.py @@ -88,5 +88,6 @@ url(r'^users/new/$', 'user_new', name='user_new'), url(r'^users/(?P[^/]+)/$', UserSummaryView.as_view(), name='user_summary'), + url(r'^users/(?P\d+)/delete$', 'user_delete', name='user_delete'), url(r'^api/lists/$', 'api_list_index', name='api_list_index'), ) diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index c61ef9a..97b5b5b 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -202,4 +202,37 @@ {'help_text':help_text, 'helpid':helpid}, context_instance=RequestContext(request)) + + +@user_passes_test(lambda u: u.is_superuser) +def user_delete(request,template='postorius/users/user_confirm_delete.html',**kwargs): + """ Deletes a user after asking for confirmation. + """ + user_id = kwargs["user_id"] + try: + mm_user = MailmanUser.objects.get_or_404(address=user_id) + except MailmanApiError: + return utils.render_api_error(request) + + try: + email_id = mm_user.addresses[0] + except IndexError: + email_id = '' + if request.method == 'POST': + try: + mm_user.delete() + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError as e: + messages.error(request, _('The user could not be deleted:' + ' %s' % e.msg)) + messages.success(request, + _('The user %s has been deleted.' % email_id)) + return redirect("user_index") + + submit_url = reverse('user_delete', + kwargs={'user_id': user_id}) + return render_to_response(template, + {'user': request.user, 'submit_url': submit_url,'email_id':email_id}, + context_instance=RequestContext(request))