Commit 30611aa0 authored by Aurélien Bompard's avatar Aurélien Bompard Committed by Barry Warsaw

Make sure that Pendables always have a type

parent ed9efb35
......@@ -176,6 +176,7 @@ class ProbeVERP(_BaseVERPParser):
@implementer(IPendable)
class _ProbePendable(dict):
"""The pendable dictionary for probe messages."""
PEND_TYPE = 'probe'
def send_probe(member, msg):
......
......@@ -168,6 +168,7 @@ however the message metadata indicates that the message has been approved.
_parsemsg : False
approved : True
moderator_approved: True
type : data
version : 3
......
......@@ -43,7 +43,7 @@ log = logging.getLogger('mailman.error')
@implementer(IPendable)
class PendableRegistration(dict):
PEND_KEY = 'registration'
PEND_TYPE = 'registration'
......
......@@ -68,7 +68,7 @@ class WhichSubscriber(Enum):
@implementer(IPendable)
class Pendable(dict):
pass
PEND_TYPE = 'subscription'
......
......@@ -207,9 +207,9 @@ Message-ID: <first>
# corresponds to a record in the pending database.
token = send_probe(self._member, self._msg)
pendable = getUtility(IPendings).confirm(token)
self.assertEqual(len(pendable.items()), 2)
self.assertEqual(len(pendable.items()), 3)
self.assertEqual(set(pendable.keys()),
set(['member_id', 'message_id']))
set(['member_id', 'message_id', 'type']))
# member_ids are pended as unicodes.
self.assertEqual(uuid.UUID(hex=pendable['member_id']),
self._member.member_id)
......
......@@ -55,7 +55,7 @@ log = logging.getLogger('mailman.vette')
@implementer(IPendable)
class HeldMessagePendable(dict):
PEND_KEY = 'held message'
PEND_TYPE = 'held message'
......@@ -149,8 +149,7 @@ class HoldChain(TerminalChainBase):
request_id = hold_message(mlist, msg, msgdata, None)
# Calculate a confirmation token to send to the author of the
# message.
pendable = HeldMessagePendable(type=HeldMessagePendable.PEND_KEY,
id=request_id)
pendable = HeldMessagePendable(id=request_id)
token = getUtility(IPendings).add(pendable)
# Get the language to send the response in. If the sender is a
# member, then send it in the member's language, otherwise send it in
......
......@@ -37,6 +37,8 @@ from zope.interface import Interface, Attribute
class IPendable(Interface):
"""A pendable object."""
PEND_TYPE = Attribute("""The type of this pendable.""")
def keys():
"""The keys of the pending event data, all of which are strings."""
......
......@@ -26,10 +26,9 @@ token that can be used in urls and such.
>>> from mailman.interfaces.pending import IPendable
>>> @implementer(IPendable)
... class SimplePendable(dict):
... pass
... PEND_TYPE = 'subscription'
>>> subscription = SimplePendable(
... type='subscription',
... address='[email protected]',
... display_name='Anne Person',
... language='en',
......
......@@ -124,6 +124,7 @@ an additional key which holds the name of the request type.
_request_type: held_message
bar : no
foo : yes
type : data
Iterating over requests
......@@ -146,6 +147,7 @@ over by type.
_request_type: held_message
bar: no
foo: yes
type: data
Deleting requests
......
......@@ -79,7 +79,7 @@ class Pended(Model):
@implementer(IPendable)
class UnpendedPendable(dict):
pass
PEND_TYPE = 'unpended'
......@@ -114,6 +114,9 @@ class Pendings:
pending = Pended(
token=token,
expiration_date=now() + lifetime)
pendable_type = pendable.pop('type', pendable.PEND_TYPE)
pending.key_values.append(
PendedKeyValue(key='type', value=pendable_type))
for key, value in pendable.items():
# Both keys and values must be strings.
if isinstance(key, bytes):
......@@ -141,7 +144,10 @@ class Pendings:
# Iter on PendedKeyValue entries that are associated with the pending
# object's ID. Watch out for type conversions.
for keyvalue in pending.key_values:
value = json.loads(keyvalue.value)
if keyvalue.key == 'type':
value = keyvalue.value
else:
value = json.loads(keyvalue.value)
if isinstance(value, dict) and '__encoding__' in value:
value = value['value'].encode(value['__encoding__'])
pendable[keyvalue.key] = value
......@@ -169,7 +175,7 @@ class Pendings:
pkv_alias_type = aliased(PendedKeyValue)
query = query.join(pkv_alias_type).filter(and_(
pkv_alias_type.key == 'type',
pkv_alias_type.value == json.dumps(type)
pkv_alias_type.value == type
))
for pending in query:
yield pending.token, self.confirm(pending.token, expunge=False)
......
......@@ -41,6 +41,8 @@ from zope.interface import implementer
class DataPendable(dict):
"""See `IPendable`."""
PEND_TYPE = 'data'
def update(self, mapping):
# Keys and values must be strings (unicodes, but bytes values are
# accepted for now). Any other types for keys are a programming
......
......@@ -35,7 +35,7 @@ from zope.interface import implementer
@implementer(IPendable)
class SimplePendable(dict):
pass
PEND_TYPE = 'simple'
......
......@@ -51,6 +51,7 @@ The subscription request can be viewed in the REST API.
list_id: ant.example.com
token: ...
token_owner: moderator
type: subscription
when: 2005-08-01T07:49:23
http_etag: "..."
start: 0
......@@ -71,6 +72,7 @@ You can view an individual membership change request by providing the token
list_id: ant.example.com
token: ...
token_owner: moderator
type: subscription
when: 2005-08-01T07:49:23
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment