Varun Sharma has proposed merging lp:~varun/postorius/user_delete into
lp:postorius.
Requested reviews:
Florian Fuchs (flo-fuchs)
For more details, see:
https://code.launchpad.net/~varun/postorius/user_delete/+merge/173185
added deleting of user functionality by adding user_delete method in user.py
and creating a confirmation page user_confirm_delete.html. This patch will
enable the superusers to delete other users.
--
https://code.launchpad.net/~varun/postorius/user_delete/+merge/173185
Your team Mailman Coders is subscribed to branch lp:postorius.
=== modified file 'src/postorius/templates/postorius/users/index.html'
--- src/postorius/templates/postorius/users/index.html 2013-03-29 22:04:06 +0000
+++ src/postorius/templates/postorius/users/index.html 2013-07-05 11:08:26 +0000
@@ -16,6 +16,7 @@
<tr>
<th>{% trans 'Email' %}</th>
<th>{% trans 'Display name' %}</th>
+ <th></th> <!-- header for delete user button -->
<!-- th>{% trans 'Web User' %}</th -->
<!--th>{% trans 'Mailman User' %}</th -->
</tr>
@@ -29,6 +30,9 @@
<td>
{{ mm_user.display_name }}
</td>
+ <td>
+ <a href="{{mm_user.user_id}}/delete" class="btn btn-mini btn-danger">Delete</a>
+ </td>
<!--td><i class="icon-ok"></i></td -->
<!--td><i class="icon-remove"></i></td -->
</tr>
=== modified file 'src/postorius/templates/postorius/users/new.html'
--- src/postorius/templates/postorius/users/new.html 2012-11-18 19:51:08 +0000
+++ src/postorius/templates/postorius/users/new.html 2013-07-05 11:08:26 +0000
@@ -1,4 +1,4 @@
-{% extends extend_template %}
+{% extends postorius_base_template %}
{% load url from future %}
{% load i18n %}
{% load nav_helpers %}
=== added file 'src/postorius/templates/postorius/users/user_confirm_delete.html'
--- src/postorius/templates/postorius/users/user_confirm_delete.html 1970-01-01 00:00:00 +0000
+++ src/postorius/templates/postorius/users/user_confirm_delete.html 2013-07-05 11:08:26 +0000
@@ -0,0 +1,13 @@
+{% extends "postorius/base.html" %}
+{% load url from future %}
+{% load i18n %}
+{% load nav_helpers %}
+
+{% block main %}
+ <h1>{% trans 'Confirm Deletion' %}</h1>
+ <p>{% trans "Are you sure you want to permanently delete this user ?" %}</p>
+ <form action="{{submit_url}}" method="post"> {% csrf_token %}
+ <button class="btn btn-danger" type="submit">{% trans "Delete" %} {{ email_id }}</button>
+ <a class="btn" href="{% url 'user_index' %}">{% trans "Cancel" %}</a>
+ </form>
+{% endblock main %}
=== modified file 'src/postorius/urls.py'
--- src/postorius/urls.py 2013-06-30 22:39:39 +0000
+++ src/postorius/urls.py 2013-07-05 11:08:26 +0000
@@ -88,5 +88,6 @@
url(r'^users/new/$', 'user_new', name='user_new'),
url(r'^users/(?P<user_id>[^/]+)/$',
UserSummaryView.as_view(), name='user_summary'),
+ url(r'^users/(?P<user_id>\d+)/delete$', 'user_delete', name='user_delete'),
url(r'^api/lists/$', 'api_list_index', name='api_list_index'),
)
=== modified file 'src/postorius/views/user.py'
--- src/postorius/views/user.py 2013-06-30 22:44:36 +0000
+++ src/postorius/views/user.py 2013-07-05 11:08:26 +0000
@@ -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))
_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders