Abhilash Raj pushed to branch backport-mr-0315 at mailman / Mailman Core

Commits:
9f883894 by Barry Warsaw at 2017-10-31T18:18:02+00:00
Allow a list's acceptable aliases to be cleared via REST.


(cherry picked from commit 5963175fe5a579a60a15808009f0cb5010f478af)
- - - - -


4 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/rest/docs/listconf.rst
- src/mailman/rest/listconf.py
- src/mailman/rest/tests/test_listconf.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -12,6 +12,12 @@ Here is a history of user visible changes to Mailman.
 =====
 (201X-XX-XXX)
 
+REST
+----
+* Allow a mailing list's acceptable aliases to be cleared by calling
+  ``DELETE`` on the list's ``config/acceptable_aliases`` resource.
+  (Closes #394)
+
 
 3.1.0 -- "Between The Wheels"
 =============================


=====================================
src/mailman/rest/docs/listconf.rst
=====================================
--- a/src/mailman/rest/docs/listconf.rst
+++ b/src/mailman/rest/docs/listconf.rst
@@ -296,7 +296,7 @@ dictionary are ignored.
     server: WSGIServer/...
     status: 204
 
-Aliases are returned as a list on the ``aliases`` key.
+You can get all the mailing list's acceptable aliases through the REST API.
 
     >>> response = call_http(
     ...     'http://localhost:9001/3.0/lists/'
@@ -315,6 +315,23 @@ The mailing list has its aliases set.
     b...@example.net
     f...@example.com
 
+The aliases can be removed by using ``DELETE``.
+
+    >>> response = call_http(
+    ...     'http://localhost:9001/3.0/lists/'
+    ...     'a...@example.com/config/acceptable_aliases',
+    ...     method='DELETE')
+    content-length: 0
+    date: ...
+    server: WSGIServer/...
+    status: 204
+
+Now the mailing list has no aliases.
+
+    >>> aliases = IAcceptableAliasSet(mlist)
+    >>> print(len(list(aliases.aliases)))
+    0
+
 
 Header matches
 --------------


=====================================
src/mailman/rest/listconf.py
=====================================
--- a/src/mailman/rest/listconf.py
+++ b/src/mailman/rest/listconf.py
@@ -329,3 +329,23 @@ class ListConfiguration:
             bad_request(response, str(error))
         else:
             no_content(response)
+
+    def on_delete(self, request, response):
+        if self._attribute is None:
+            bad_request(
+                response, 'Cannot delete the list configuration itself')
+            return
+        if self._attribute not in VALIDATORS:
+            bad_request(
+                response, 'Read-only attribute: {}'.format(self._attribute))
+            return
+        # This kind of sucks because it doesn't scale if the list of attributes
+        # which can be deleted grows.  So if we get too many we'll have to use
+        # a lookup table.  For now, this is good enough.
+        if self._attribute != 'acceptable_aliases':
+            bad_request(
+                response, 'Attribute cannot be DELETEd: {}'.format(
+                    self._attribute))
+            return
+        IAcceptableAliasSet(self._mlist).clear()
+        no_content(response)


=====================================
src/mailman/rest/tests/test_listconf.py
=====================================
--- a/src/mailman/rest/tests/test_listconf.py
+++ b/src/mailman/rest/tests/test_listconf.py
@@ -467,3 +467,31 @@ class TestConfiguration(unittest.TestCase):
                 dict(info=''),
                 'PATCH')
             self.assertEqual(self._mlist.info, '')
+
+    def test_delete_top_level_listconf(self):
+        with self.assertRaises(HTTPError) as cm:
+            call_api('http://localhost:9001/3.0/lists/ant.example.com/config',
+                     method='DELETE')
+        self.assertEqual(cm.exception.code, 400)
+        self.assertEqual(cm.exception.reason,
+                         'Cannot delete the list configuration itself')
+
+    def test_delete_read_only_attribute(self):
+        with self.assertRaises(HTTPError) as cm:
+            call_api(
+                'http://localhost:9001/3.0/lists/ant.example.com/'
+                'config/post_id',
+                method='DELETE')
+        self.assertEqual(cm.exception.code, 400)
+        self.assertEqual(cm.exception.reason,
+                         'Read-only attribute: post_id')
+
+    def test_delete_undeletable_attribute(self):
+        with self.assertRaises(HTTPError) as cm:
+            call_api(
+                'http://localhost:9001/3.0/lists/ant.example.com/'
+                'config/administrivia',
+                method='DELETE')
+        self.assertEqual(cm.exception.code, 400)
+        self.assertEqual(cm.exception.reason,
+                         'Attribute cannot be DELETEd: administrivia')



View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/9f883894ff38f64298c2ca0827e7fa0dd9f7178f

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/commit/9f883894ff38f64298c2ca0827e7fa0dd9f7178f
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to