Barry Warsaw pushed to branch master at mailman / Mailman Core

Commits:
5963175f by Barry Warsaw at 2017-09-03T16:01:07-07:00
Allow a list's acceptable aliases to be cleared via REST.

- - - - -
dd8071a2 by Barry Warsaw at 2017-09-04T14:17:13+00:00
Merge branch 'issue394' into 'master'

Allow a list's acceptable aliases to be cleared via REST

See merge request !315
- - - - -


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
@@ -65,6 +65,12 @@ Other
 * Drop support for Python 3.4.  (Closes #373)
 * Bump minimum requirements for aiosmtpd (>= 1.1) and flufl.lock (>= 3.1).
 
+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/compare/fda6c2aa5d91d10d19d6da2eff0c73f60c36037a...dd8071a24562477e006952f22e61aa70658b25a7

---
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/fda6c2aa5d91d10d19d6da2eff0c73f60c36037a...dd8071a24562477e006952f22e61aa70658b25a7
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