aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2017-07-07 20:06:56 +0200
committerJ08nY2017-07-07 20:06:56 +0200
commit888da7e2ca9d475d1e27b58e425ed8c8d1a0cd42 (patch)
treec38bfa7eb36932de45cc19799fcfeb52b8fd674b
parent3c15bcc9b8a838439de4301f8c9f1a73b522ac4b (diff)
downloadmailman-pgp-888da7e2ca9d475d1e27b58e425ed8c8d1a0cd42.tar.gz
mailman-pgp-888da7e2ca9d475d1e27b58e425ed8c8d1a0cd42.tar.zst
mailman-pgp-888da7e2ca9d475d1e27b58e425ed8c8d1a0cd42.zip
-rw-r--r--src/mailman_pgp/rest/lists.py22
-rw-r--r--src/mailman_pgp/rest/root.py4
-rw-r--r--src/mailman_pgp/rest/tests/test_lists.py2
3 files changed, 16 insertions, 12 deletions
diff --git a/src/mailman_pgp/rest/lists.py b/src/mailman_pgp/rest/lists.py
index 72fa7a4..9141bce 100644
--- a/src/mailman_pgp/rest/lists.py
+++ b/src/mailman_pgp/rest/lists.py
@@ -16,10 +16,11 @@
# this program. If not, see <http://www.gnu.org/licenses/>.
""""""
-
+from mailman.interfaces.listmanager import IListManager
from mailman.rest.helpers import (
child, CollectionMixin, etag, not_found, okay)
from public import public
+from zope.component import getUtility
from mailman_pgp.config import config
from mailman_pgp.model.list import PGPMailingList
@@ -38,8 +39,8 @@ class _EncryptedBase(CollectionMixin):
sign_outgoing=emlist.sign_outgoing,
nonencrypted_msg_action=emlist.nonencrypted_msg_action,
self_link=self.api.path_to(
- '/plugins/{}/lists/{}'.format(config.name,
- emlist.list_id)))
+ '/plugins/{}/lists/{}'.format(config.name,
+ emlist.list_id)))
def _get_collection(self, request):
"""See `CollectionMixin`."""
@@ -56,9 +57,13 @@ class AllEncryptedLists(_EncryptedBase):
@public
class AnEncryptedList(_EncryptedBase):
- def __init__(self, list_id):
- self._mlist = PGPMailingList.query().filter_by(
- list_id=list_id).first()
+ def __init__(self, list_identifier):
+ manager = getUtility(IListManager)
+ if '@' in list_identifier:
+ mlist = manager.get(list_identifier)
+ else:
+ mlist = manager.get_by_list_id(list_identifier)
+ self._mlist = PGPMailingList.for_list(mlist)
def on_get(self, request, response):
"""/lists/<list_id>"""
@@ -86,7 +91,6 @@ class AListPubkey:
if pubkey is None:
return not_found(response)
- resource = dict(public_key=str(self._mlist.pubkey),
- key_fingerprint=str(
- self._mlist.pubkey.fingerprint))
+ resource = dict(public_key=str(pubkey),
+ key_fingerprint=str(pubkey.fingerprint))
return okay(response, etag(resource))
diff --git a/src/mailman_pgp/rest/root.py b/src/mailman_pgp/rest/root.py
index 627f3da..374a88d 100644
--- a/src/mailman_pgp/rest/root.py
+++ b/src/mailman_pgp/rest/root.py
@@ -38,8 +38,8 @@ class RESTRoot:
if len(segments) == 0:
return AllEncryptedLists(), []
else:
- list_id = segments.pop(0)
- return AnEncryptedList(list_id), segments
+ list_identifier = segments.pop(0)
+ return AnEncryptedList(list_identifier), segments
@child()
def addresses(self, context, segments):
diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py
index e940517..8044a8f 100644
--- a/src/mailman_pgp/rest/tests/test_lists.py
+++ b/src/mailman_pgp/rest/tests/test_lists.py
@@ -64,7 +64,7 @@ class TestLists(TestCase):
json, response = call_api(
'http://localhost:9001/3.1/plugins/pgp/lists/'
- 'test.example.com/key')
+ 'another.example.com/key')
json.pop('http_etag')
self.assertEqual(len(json.keys()), 2)