summaryrefslogtreecommitdiff
path: root/src/mailman/model/roster.py
diff options
context:
space:
mode:
authorBarry Warsaw2015-04-14 12:35:53 -0400
committerBarry Warsaw2015-04-14 12:35:53 -0400
commit85afb7bac938eb2c2f00507482886e1470bdcaa1 (patch)
treec65543aa61bc2dbdeaf4e914fb79160dcdffb864 /src/mailman/model/roster.py
parent7317b94a0b746f0287ecbc5654ec544ce0112adb (diff)
downloadmailman-85afb7bac938eb2c2f00507482886e1470bdcaa1.tar.gz
mailman-85afb7bac938eb2c2f00507482886e1470bdcaa1.tar.zst
mailman-85afb7bac938eb2c2f00507482886e1470bdcaa1.zip
Added IMember.subscriber to definitively return how a member is subscribed to
the mailing list (via preferred address/user or explicit address). IMember.get_member() is defined to return the explicit address when members are subscribed in both ways. IMember.get_memberships() returns a sequence of length 0, 1, or 2 containing all the member records associated with the email address. Fixed the AbstractMemberRoster methods query to properly return subscriptions via the user's preferred address and via an explicit address.
Diffstat (limited to 'src/mailman/model/roster.py')
-rw-r--r--src/mailman/model/roster.py56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/mailman/model/roster.py b/src/mailman/model/roster.py
index 91211c665..d319aa819 100644
--- a/src/mailman/model/roster.py
+++ b/src/mailman/model/roster.py
@@ -97,21 +97,48 @@ class AbstractRoster:
yield member.address
@dbconnection
- def get_member(self, store, address):
- """See `IRoster`."""
- results = store.query(Member).filter(
+ def _get_all_memberships(self, store, email):
+ # Avoid circular imports.
+ from mailman.model.user import User
+ # Here's a query that finds all members subscribed with an explicit
+ # email address.
+ members_a = store.query(Member).filter(
Member.list_id == self._mlist.list_id,
Member.role == self.role,
- Address.email == address,
+ Address.email == email,
Member.address_id == Address.id)
- if results.count() == 0:
+ # Here's a query that finds all members subscribed with their
+ # preferred address.
+ members_u = store.query(Member).filter(
+ Member.list_id == self._mlist.list_id,
+ Member.role == self.role,
+ Address.email==email,
+ Member.user_id == User.id)
+ return members_a.union(members_u).all()
+
+ def get_member(self, email):
+ """See ``IRoster``."""
+ memberships = self._get_all_memberships(email)
+ count = len(memberships)
+ if count == 0:
return None
- elif results.count() == 1:
- return results[0]
- else:
- raise AssertionError(
- 'Too many matching member results: {0}'.format(
- results.count()))
+ elif count == 1:
+ return memberships[0]
+ assert count == 2, 'Unexpected membership count: {}'.format(count)
+ # This is the case where the email address is subscribed both
+ # explicitly and indirectly through the preferred address. By
+ # definition, we return the explicit address membership only.
+ return (memberships[0]
+ if memberships[0]._address is not None
+ else memberships[1])
+
+ def get_memberships(self, email):
+ """See ``IRoster``."""
+ memberships = self._get_all_memberships(email)
+ count = len(memberships)
+ assert 0 <= count <= 2, 'Unexpected membership count: {}'.format(
+ count)
+ return memberships
@@ -298,3 +325,10 @@ class Memberships:
raise AssertionError(
'Too many matching member results: {0}'.format(
results.count()))
+
+ @dbconnection
+ def get_memberships(self, store, address):
+ """See `IRoster`."""
+ # 2015-04-14 BAW: See LP: #1444055 -- this currently exists just to
+ # pass a test.
+ raise NotImplementedError