Barry Warsaw pushed to branch master at mailman / Mailman
Commits:
3bd2a292 by Barry Warsaw at 2017-05-23T12:39:39-07:00
Add self_links to the system configuration resources.
Closes #335
- - - - -
0eb24746 by Barry Warsaw at 2017-05-23T21:40:13+00:00
Merge branch 'self_links' into 'master'
Add self_links to the system configuration resources
Closes #335
See merge request !271
- - - - -
3 changed files:
- src/mailman/rest/docs/systemconf.rst
- src/mailman/rest/root.py
- src/mailman/rest/tests/test_systemconf.py
Changes:
=====================================
src/mailman/rest/docs/systemconf.rst
=====================================
--- a/src/mailman/rest/docs/systemconf.rst
+++ b/src/mailman/rest/docs/systemconf.rst
@@ -8,6 +8,7 @@ get a list of all defined sections.
>>> dump_json('http://localhost:9001/3.0/system/configuration')
http_etag: ...
sections: ['antispam', 'archiver.mail_archive', 'archiver.master', ...
+ self_link: http://localhost:9001/3.0/system/configuration
You can also get all the values for a particular section, such as the
``[mailman]`` section...
@@ -25,6 +26,7 @@ You can also get all the values for a particular section,
such as the
pending_request_life: 3d
post_hook:
pre_hook:
+ self_link: http://localhost:9001/3.0/system/configuration/mailman
sender_headers: from from_ reply-to sender
site_owner: [email protected]
@@ -36,6 +38,7 @@ You can also get all the values for a particular section,
such as the
org_domain_data_url: https://publicsuffix.org/list/public_suffix_list.dat
resolver_lifetime: 5s
resolver_timeout: 3s
+ self_link: http://localhost:9001/3.0/system/configuration/dmarc
Dotted section names work too, for example, to get the French language
settings section.
@@ -45,3 +48,4 @@ settings section.
description: French
enabled: yes
http_etag: ...
+ self_link: http://localhost:9001/3.0/system/configuration/language.fr
=====================================
src/mailman/rest/root.py
=====================================
--- a/src/mailman/rest/root.py
+++ b/src/mailman/rest/root.py
@@ -89,7 +89,9 @@ class SystemConfiguration:
def on_get(self, request, response):
if self._section is None:
resource = dict(
- sections=sorted(section.name for section in config))
+ sections=sorted(section.name for section in config),
+ self_link=self.api.path_to('system/configuration'),
+ )
okay(response, etag(resource))
return
missing = object()
@@ -100,6 +102,14 @@ class SystemConfiguration:
# Sections don't have .keys(), .values(), or .items() but we can
# iterate over them.
resource = {key: section[key] for key in section}
+ # Add a `self_link` attribute to the resource. This is a little ugly
+ # because technically speaking we're mixing namespaces. We can't have
+ # a variable named `self_link` in any section, but also we can't have
+ # `http_etag` either, so unless we want to shove all these values into
+ # a sub dictionary (which we don't), we have to live with it.
+ self_link = self.api.path_to(
+ 'system/configuration/{}'.format(section.name))
+ resource['self_link'] = self_link
okay(response, etag(resource))
=====================================
src/mailman/rest/tests/test_systemconf.py
=====================================
--- a/src/mailman/rest/tests/test_systemconf.py
+++ b/src/mailman/rest/tests/test_systemconf.py
@@ -48,6 +48,7 @@ class TestSystemConfiguration(unittest.TestCase):
pending_request_life='3d',
post_hook='',
pre_hook='',
+ self_link='http://localhost:9001/3.0/system/configuration/mailman',
sender_headers='from from_ reply-to sender',
site_owner='[email protected]',
))
@@ -65,6 +66,7 @@ class TestSystemConfiguration(unittest.TestCase):
'https://publicsuffix.org/list/public_suffix_list.dat',
resolver_lifetime='5s',
resolver_timeout='3s',
+ self_link='http://localhost:9001/3.0/system/configuration/dmarc',
))
def test_dotted_section(self):
@@ -78,6 +80,8 @@ class TestSystemConfiguration(unittest.TestCase):
description='French',
charset='iso-8859-1',
enabled='yes',
+ self_link=('http://localhost:9001/3.0/system'
+ '/configuration/language.fr'),
))
def test_multiline(self):
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/f690f98ba1ebd8fafadc9a90fe4064ac31cdccc1...0eb24746c61a5fd944adb2b82681e4df6a039de1
---
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/f690f98ba1ebd8fafadc9a90fe4064ac31cdccc1...0eb24746c61a5fd944adb2b82681e4df6a039de1
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org