Commit 8613712a authored by Abhilash Raj's avatar Abhilash Raj

Add compatibility for MailmanClient 3.2.0b2

parent a5b07989
......@@ -53,7 +53,7 @@ setup(
install_requires=[
'Django>=1.11',
'django-mailman3>=1.2.0a1',
'mailmanclient>=3.2.0b1'
'mailmanclient>=3.2.0b2'
],
tests_require=[
"mock",
......
......@@ -39,7 +39,9 @@ def user_is_in_list_roster(user, mailing_list, roster):
return False
addresses = set(EmailAddress.objects.filter(
user=user, verified=True).values_list("email", flat=True))
if addresses & set(getattr(mailing_list, roster)):
roster_addresses = set([member.email for member in
set(getattr(mailing_list, roster))])
if addresses & roster_addresses:
return True # At least one address is in the roster
return False
......
......@@ -57,7 +57,7 @@ class DomainCreationTest(ViewTestCase):
a_new_domain = self.mm_client.get_domain('example.com')
self.assertEqual(a_new_domain.mail_host, 'example.com')
self.assertEqual(a_new_domain.owners[0]['user_id'],
self.assertEqual(a_new_domain.owners[0].user_id,
self.mm_client.get_user('su@example.com').user_id)
self.assertTrue(
MailDomain.objects.filter(mail_domain='example.com').exists())
......
......@@ -101,14 +101,17 @@ class AddRemoveOwnerTest(ViewTestCase):
url = reverse('list_members', args=('foo@example.com', 'owner',))
response = self.client.post(url, {'email': 'newowner@example.com'})
self.assertRedirects(response, url)
self.assertTrue('newowner@example.com' in self.foo_list.owners)
owners_emails = [owner.email for owner in self.foo_list.owners]
self.assertTrue('newowner@example.com' in owners_emails)
self.client.post(
reverse('remove_role', args=('foo@example.com', 'owner',
'newowner@example.com')))
self.assertFalse('newowner@example.com' in self.foo_list.owners)
owners_emails = [owner.email for owner in self.foo_list.owners]
self.assertFalse('newowner@example.com' in owners_emails)
def test_remove_owner_by_owner(self):
self.assertTrue('su@example.com' in self.foo_list.owners)
owners_emails = [owner.email for owner in self.foo_list.owners]
self.assertTrue('su@example.com' in owners_emails)
# Make the logged in user a simple list owner
self.su.is_superuser = False
self.su.save()
......@@ -116,37 +119,43 @@ class AddRemoveOwnerTest(ViewTestCase):
url = reverse('list_members', args=('foo@example.com', 'owner',))
response = self.client.post(url, {'email': 'newowner@example.com'})
self.assertRedirects(response, url)
self.assertTrue('newowner@example.com' in self.foo_list.owners)
owners_emails = [owner.email for owner in self.foo_list.owners]
self.assertTrue('newowner@example.com' in owners_emails)
response = self.client.post(
reverse('remove_role', args=('foo@example.com', 'owner',
'newowner@example.com')))
self.assertFalse('newowner@example.com' in self.foo_list.owners)
self.assertHasSuccessMessage(response)
owners_emails = [owner.email for owner in self.foo_list.owners]
self.assertFalse('newowner@example.com' in owners_emails)
def test_remove_owner_as_owner_self_last(self):
# It is allowed to remove itself, but only if there's another owner
# left.
mm_list = self.mm_client.get_list('foo@example.com')
mm_list.add_owner('otherowner@example.com')
self.assertTrue('su@example.com' in self.foo_list.owners)
self.assertTrue('otherowner@example.com' in self.foo_list.owners)
owners_emails = [owner.email for owner in mm_list.owners]
self.assertTrue('su@example.com' in owners_emails)
self.assertTrue('otherowner@example.com' in owners_emails)
response = self.client.post(
reverse('remove_role', args=('foo@example.com', 'owner',
'su@example.com')))
self.assertFalse('su@example.com' in self.foo_list.owners)
self.assertEqual(response.status_code, 302)
self.assertHasSuccessMessage(response)
owners_emails = [owner.email for owner in mm_list.owners]
self.assertFalse('su@example.com' in owners_emails)
# But not to remove the last owner
mm_list.add_owner('su@example.com')
mm_list.remove_owner('otherowner@example.com')
self.assertTrue('su@example.com' in self.foo_list.owners)
self.assertFalse('otherowner@example.com' in self.foo_list.owners)
owners_emails = [owner.email for owner in mm_list.owners]
self.assertTrue('su@example.com' in owners_emails)
self.assertFalse('otherowner@example.com' in owners_emails)
response = self.client.post(
reverse('remove_role', args=('foo@example.com', 'owner',
'su@example.com')))
self.assertTrue('su@example.com' in self.foo_list.owners)
self.assertEqual(response.status_code, 302)
self.assertHasErrorMessage(response)
owners_emails = [owner.email for owner in mm_list.owners]
self.assertTrue('su@example.com' in owners_emails)
class AddModeratorTest(ViewTestCase):
......@@ -175,7 +184,8 @@ class AddModeratorTest(ViewTestCase):
self.domain.delete()
def test_new_moderator_added(self):
self.assertTrue('newmod@example.com' in self.foo_list.moderators)
mods_emails = [mod.email for mod in self.foo_list.moderators]
self.assertTrue('newmod@example.com' in mods_emails)
class ListMembersTest(ViewTestCase):
......
......@@ -70,7 +70,8 @@ class ListCreationTest(ViewTestCase):
# self.assertHasSuccessMessage(response)
a_new_list = self.mm_client.get_list('a_new_list@example.com')
self.assertEqual(a_new_list.fqdn_listname, 'a_new_list@example.com')
self.assertEqual(a_new_list.owners, ['owner@example.com'])
owner_emails = [owner.email for owner in a_new_list.owners]
self.assertEqual(owner_emails, ['owner@example.com'])
def test_listname_validation(self):
self.client.login(username='su', password='pwd')
......
......@@ -53,6 +53,12 @@ def create_user():
return user
class MockMember():
def __init__(self, email):
self.email = email
class ListOwnerRequiredTest(TestCase):
"""Tests the list_owner_required auth decorator."""
......@@ -94,7 +100,7 @@ class ListOwnerRequiredTest(TestCase):
def test_non_list_owner(self, mock_get_list):
"""Should raise PermissionDenied if user is not a list owner."""
# prepare mock list object
self.mock_list.owners = ['geddy@rush.it']
self.mock_list.owners = [MockMember('geddy@rush.it')]
mock_get_list.return_value = self.mock_list
# prepare request
request = self.request_factory.get(
......@@ -107,7 +113,7 @@ class ListOwnerRequiredTest(TestCase):
def test_list_owner(self, mock_get_list):
"""Should return fn return value if user is the list owner."""
# prepare mock list object
self.mock_list.owners = ['les@primus.org']
self.mock_list.owners = [MockMember('les@primus.org')]
mock_get_list.return_value = self.mock_list
# prepare request
request = self.request_factory.get(
......@@ -159,7 +165,7 @@ class ListModeratorRequiredTest(TestCase):
def test_non_list_moderator(self, mock_get_list):
"""Should raise PermissionDenied if user is not a list owner."""
# prepare mock list object
self.mock_list.moderators = ['geddy@rush.it']
self.mock_list.moderators = [MockMember('geddy@rush.it')]
mock_get_list.return_value = self.mock_list
# prepare request
request = self.request_factory.get(
......@@ -172,7 +178,7 @@ class ListModeratorRequiredTest(TestCase):
def test_list_owner(self, mock_get_list):
"""Should return fn return value if user is the list owner."""
# prepare mock list object
self.mock_list.owners = ['les@primus.org']
self.mock_list.owners = [MockMember('les@primus.org')]
mock_get_list.return_value = self.mock_list
# prepare request
request = self.request_factory.get(
......@@ -186,7 +192,7 @@ class ListModeratorRequiredTest(TestCase):
def test_list_moderator(self, mock_get_list):
"""Should return fn return value if user is the list moderator."""
# prepare mock list object
self.mock_list.moderators = ['les@primus.org']
self.mock_list.moderators = [MockMember('les@primus.org')]
mock_get_list.return_value = self.mock_list
# prepare request
request = self.request_factory.get(
......
......@@ -761,11 +761,10 @@ def remove_role(request, list_id=None, role=None, address=None,
template='postorius/lists/confirm_remove_role.html'):
"""Removes a list moderator or owner."""
the_list = List.objects.get_or_404(fqdn_listname=list_id)
redirect_on_success = redirect('list_members', the_list.list_id, role)
roster = getattr(the_list, '{}s'.format(role))
if address not in roster:
all_emails = [each.email for each in roster]
if address not in all_emails:
messages.error(request,
_('The user %(email)s is not in the %(role)s group')
% {'email': address, 'role': role})
......
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