Abhilash Raj has proposed merging lp:~raj-abhilash1/postorius/remove-owner into 
lp:postorius.

Requested reviews:
  Mailman Coders (mailman-coders)

For more details, see:
https://code.launchpad.net/~raj-abhilash1/postorius/remove-owner/+merge/215770

Added functionality to remove owner or moderator of a list.
-- 
https://code.launchpad.net/~raj-abhilash1/postorius/remove-owner/+merge/215770
Your team Mailman Coders is requested to review the proposed merge of 
lp:~raj-abhilash1/postorius/remove-owner into lp:postorius.
=== added file 'src/postorius/templates/postorius/lists/confirm_remove_role.html'
--- src/postorius/templates/postorius/lists/confirm_remove_role.html	1970-01-01 00:00:00 +0000
+++ src/postorius/templates/postorius/lists/confirm_remove_role.html	2014-04-14 22:16:41 +0000
@@ -0,0 +1,14 @@
+{% extends "postorius/base.html" %}
+{% load url from future %}
+{% load i18n %}
+{% load nav_helpers %}
+
+{% block main %}
+    <h1>{% trans 'Confirm Remove Role' %}</h1>
+    <p>{% trans "Are you sure you want to remove?" %}</p>
+    <form method="post" action="{% url 'remove_role' fqdn_listname role address %}">
+      {% csrf_token %}
+        <button class="btn btn-danger" type="submit">{% trans "Remove " %}{{ address }}</button>
+        <a class="btn" href="{% url 'user_index' %}">{% trans "Cancel" %}</a>
+    </form>
+{% endblock main %}

=== modified file 'src/postorius/templates/postorius/lists/members.html'
--- src/postorius/templates/postorius/lists/members.html	2013-05-31 02:21:03 +0000
+++ src/postorius/templates/postorius/lists/members.html	2014-04-14 22:16:41 +0000
@@ -26,6 +26,7 @@
                 <tr>
                     <td>{{ member }}</td>
                     <td>
+                      <a href="{% url 'remove_role' list.fqdn_listname 'owner' member %}" class="btn btn-mini btn-danger">Delete</a>
                     </td>
                 </tr>
             {% endfor %}
@@ -52,6 +53,7 @@
                 <tr>
                     <td>{{ member }}</td>
                     <td>
+                      <a href="{% url 'remove_role' list.fqdn_listname 'moderator' member %}" class="btn btn-mini btn-danger">Delete</a>
                     </td>
                 </tr>
             {% endfor %}

=== modified file 'src/postorius/urls.py'
--- src/postorius/urls.py	2014-03-15 21:36:39 +0000
+++ src/postorius/urls.py	2014-04-14 22:16:41 +0000
@@ -66,6 +66,8 @@
                                 url(r'^held_messages$',
                                     'list_held_messages',
                                     name='list_held_messages'),
+                                url(r'^(?P<role>[^/]+)/(?P<address>[^/]+)',
+                                    'remove_role', name='remove_role'),
                                 url(r'^settings/(?P<visible_section>[^/]+)?'
                                     '(?:/(?P<visible_option>.*))?$',
                                     'list_settings',

=== modified file 'src/postorius/views/list.py'
--- src/postorius/views/list.py	2014-03-15 21:36:39 +0000
+++ src/postorius/views/list.py	2014-04-14 22:16:41 +0000
@@ -556,7 +556,39 @@
                               context_instance=RequestContext(request))
 
 
-@login_required
-def membership_settings(request):
-    """Display a list of all memberships.
+@user_passes_test(lambda u: u.is_superuser)
+def remove_role(request, fqdn_listname=None, role=None, address=None,
+                template='postorius/lists/confirm_remove_role.html'):
+    """Removes a list moderator or owner.
     """
+    try:
+        the_list = List.objects.get_or_404(fqdn_listname=fqdn_listname)
+    except MailmanApiError:
+        return utils.render_api_error(request)
+
+    if role == 'owner':
+        if address not in the_list.owners:
+            messages.error(request, _('The user {} is not a owner'.format(address)))
+            return redirect("list_members", the_list.fqdn_listname)
+    elif role == 'moderator':
+        if address not in the_list.moderators:
+            messages.error(request, _('The user {} is not a moderator'.format(address)))
+            return redirect("list_members", the_list.fqdn_listname)
+
+    if request.method == 'POST':
+        try:
+            the_list.remove_role(role, address)
+        except MailmanApiError:
+            return utils.render_api_error(request)
+        except HTTPError as e:
+            messages.error(request, _('The {0} could not be removed:'
+                                      ' {1}'.format(role, e.msg)))
+            return redirect("list_members", the_list.fqdn_listname)
+        messages.success(request,
+                         _('The user {0} has been removed as {1}.'.format(address, role)))
+        return redirect("list_members", the_list.fqdn_listname)
+
+    return render_to_response(template,
+                              {'role': role, 'address': address, 
+                               'fqdn_listname': the_list.fqdn_listname},
+                              context_instance=RequestContext(request))

_______________________________________________
Mailman-coders mailing list
[email protected]
https://mail.python.org/mailman/listinfo/mailman-coders

Reply via email to