diff options
| author | Barry Warsaw | 2014-04-14 12:14:13 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2014-04-14 12:14:13 -0400 |
| commit | 403cbf23c07839b60c85c0bc791b6437f05c8a85 (patch) | |
| tree | b36d0ecab20e01f23bcf66ab2b27633aaf3e99c3 /src/mailman/model | |
| parent | ff6df86000da8fcb055101c5cede36b27cb0480a (diff) | |
| parent | 3a9725b91ef822122a70170333d71b58e1788a78 (diff) | |
| download | mailman-403cbf23c07839b60c85c0bc791b6437f05c8a85.tar.gz mailman-403cbf23c07839b60c85c0bc791b6437f05c8a85.tar.zst mailman-403cbf23c07839b60c85c0bc791b6437f05c8a85.zip | |
Trunk merge
Diffstat (limited to 'src/mailman/model')
31 files changed, 233 insertions, 40 deletions
diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py index 9f3d2d355..f5e7ddbfd 100644 --- a/src/mailman/model/address.py +++ b/src/mailman/model/address.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2006-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/autorespond.py b/src/mailman/model/autorespond.py index 048354193..c5e736613 100644 --- a/src/mailman/model/autorespond.py +++ b/src/mailman/model/autorespond.py @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2009-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/bans.py b/src/mailman/model/bans.py index f5cbae9ba..673e8e0c1 100644 --- a/src/mailman/model/bans.py +++ b/src/mailman/model/bans.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/bounce.py b/src/mailman/model/bounce.py index 9ae2b585d..134c51263 100644 --- a/src/mailman/model/bounce.py +++ b/src/mailman/model/bounce.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/digests.py b/src/mailman/model/digests.py index 6341d6987..5d9f3ddd1 100644 --- a/src/mailman/model/digests.py +++ b/src/mailman/model/digests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2009-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/docs/registration.rst b/src/mailman/model/docs/registration.rst index 58e9d7a86..77cb75890 100644 --- a/src/mailman/model/docs/registration.rst +++ b/src/mailman/model/docs/registration.rst @@ -104,7 +104,7 @@ But this address is waiting for confirmation. delivery_mode: regular display_name : Anne Person email : aperson@example.com - list_name : alpha@example.com + list_id : alpha.example.com type : registration diff --git a/src/mailman/model/domain.py b/src/mailman/model/domain.py index a71bd12d3..28e346022 100644 --- a/src/mailman/model/domain.py +++ b/src/mailman/model/domain.py @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2008-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/language.py b/src/mailman/model/language.py index 8bf4428be..14cf53f07 100644 --- a/src/mailman/model/language.py +++ b/src/mailman/model/language.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2006-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/listmanager.py b/src/mailman/model/listmanager.py index f1c2941e0..d648a5bde 100644 --- a/src/mailman/model/listmanager.py +++ b/src/mailman/model/listmanager.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/mailinglist.py b/src/mailman/model/mailinglist.py index f9d8b8488..955a76968 100644 --- a/src/mailman/model/mailinglist.py +++ b/src/mailman/model/mailinglist.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2006-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -47,8 +47,8 @@ from mailman.interfaces.digests import DigestFrequency from mailman.interfaces.domain import IDomainManager from mailman.interfaces.languages import ILanguageManager from mailman.interfaces.mailinglist import ( - IAcceptableAlias, IAcceptableAliasSet, IMailingList, Personalization, - ReplyToMunging) + IAcceptableAlias, IAcceptableAliasSet, IListArchiver, IListArchiverSet, + IMailingList, Personalization, ReplyToMunging) from mailman.interfaces.member import ( AlreadySubscribedError, MemberRole, MissingPreferredAddressError, SubscriptionEvent) @@ -539,3 +539,69 @@ class AcceptableAliasSet: AcceptableAlias.mailing_list == self._mailing_list) for alias in aliases: yield alias.alias + + + +@implementer(IListArchiver) +class ListArchiver(Model): + """See `IListArchiver`.""" + + id = Int(primary=True) + + mailing_list_id = Int() + mailing_list = Reference(mailing_list_id, MailingList.id) + name = Unicode() + _is_enabled = Bool() + + def __init__(self, mailing_list, archiver_name, system_archiver): + self.mailing_list = mailing_list + self.name = archiver_name + self._is_enabled = system_archiver.is_enabled + + @property + def system_archiver(self): + for archiver in config.archivers: + if archiver.name == self.name: + return archiver + return None + + @property + def is_enabled(self): + return self.system_archiver.is_enabled and self._is_enabled + + @is_enabled.setter + def is_enabled(self, value): + self._is_enabled = value + + +@implementer(IListArchiverSet) +class ListArchiverSet: + def __init__(self, mailing_list): + self._mailing_list = mailing_list + system_archivers = {} + for archiver in config.archivers: + system_archivers[archiver.name] = archiver + # Add any system enabled archivers which aren't already associated + # with the mailing list. + store = Store.of(self._mailing_list) + for archiver_name in system_archivers: + exists = store.find( + ListArchiver, + And(ListArchiver.mailing_list == mailing_list, + ListArchiver.name == archiver_name)).one() + if exists is None: + store.add(ListArchiver(mailing_list, archiver_name, + system_archivers[archiver_name])) + + @property + def archivers(self): + entries = Store.of(self._mailing_list).find( + ListArchiver, ListArchiver.mailing_list == self._mailing_list) + for entry in entries: + yield entry + + def get(self, archiver_name): + return Store.of(self._mailing_list).find( + ListArchiver, + And(ListArchiver.mailing_list == self._mailing_list, + ListArchiver.name == archiver_name)).one() diff --git a/src/mailman/model/member.py b/src/mailman/model/member.py index 1789a2dc9..438796811 100644 --- a/src/mailman/model/member.py +++ b/src/mailman/model/member.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -136,7 +136,7 @@ class Member(Model): if self._address is None else getUtility(IUserManager).get_user(self._address.email)) - def _lookup(self, preference): + def _lookup(self, preference, default=None): pref = getattr(self.preferences, preference) if pref is not None: return pref @@ -147,7 +147,9 @@ class Member(Model): pref = getattr(self.address.user.preferences, preference) if pref is not None: return pref - return getattr(system_preferences, preference) + if default is None: + return getattr(system_preferences, preference) + return default @property def acknowledge_posts(self): @@ -157,7 +159,13 @@ class Member(Model): @property def preferred_language(self): """See `IMember`.""" - return self._lookup('preferred_language') + missing = object() + language = self._lookup('preferred_language', missing) + if language is missing: + language = ((self.mailing_list and + self.mailing_list.preferred_language) or + system_preferences.preferred_language) + return language @property def receive_list_copy(self): diff --git a/src/mailman/model/message.py b/src/mailman/model/message.py index a955ca865..2d697c30b 100644 --- a/src/mailman/model/message.py +++ b/src/mailman/model/message.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/messagestore.py b/src/mailman/model/messagestore.py index 8b1435ef2..a4950e8c9 100644 --- a/src/mailman/model/messagestore.py +++ b/src/mailman/model/messagestore.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/mime.py b/src/mailman/model/mime.py index 9a853a673..570112a97 100644 --- a/src/mailman/model/mime.py +++ b/src/mailman/model/mime.py @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2009-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py index 29b08f9b7..17513015c 100644 --- a/src/mailman/model/pending.py +++ b/src/mailman/model/pending.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/preferences.py b/src/mailman/model/preferences.py index 3967c0d5c..83271d7d6 100644 --- a/src/mailman/model/preferences.py +++ b/src/mailman/model/preferences.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2006-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/requests.py b/src/mailman/model/requests.py index f9e59e254..f3ad54797 100644 --- a/src/mailman/model/requests.py +++ b/src/mailman/model/requests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/roster.py b/src/mailman/model/roster.py index 4ac1dc37e..5a6a13269 100644 --- a/src/mailman/model/roster.py +++ b/src/mailman/model/roster.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/tests/test_bounce.py b/src/mailman/model/tests/test_bounce.py index ad3467d11..a22da4416 100644 --- a/src/mailman/model/tests/test_bounce.py +++ b/src/mailman/model/tests/test_bounce.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/tests/test_domain.py b/src/mailman/model/tests/test_domain.py index 3d7f95615..0a7ef22f1 100644 --- a/src/mailman/model/tests/test_domain.py +++ b/src/mailman/model/tests/test_domain.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -21,6 +21,8 @@ from __future__ import absolute_import, unicode_literals __metaclass__ = type __all__ = [ + 'TestDomainLifecycleEvents', + 'TestDomainManager', ] diff --git a/src/mailman/model/tests/test_listmanager.py b/src/mailman/model/tests/test_listmanager.py index 5d5cc8395..2d3a4e3dc 100644 --- a/src/mailman/model/tests/test_listmanager.py +++ b/src/mailman/model/tests/test_listmanager.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -17,10 +17,13 @@ """Test the ListManager.""" -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestListCreation', + 'TestListLifecycleEvents', + 'TestListManager', ] @@ -133,8 +136,8 @@ Message-ID: <argon> # must be deleted first or an IntegrityError will be raised. filter_names = ('filter_types', 'pass_types', 'filter_extensions', 'pass_extensions') - for fname in filter_names: - setattr(self._ant, fname, ['test-filter-1', 'test-filter-2']) + for name in filter_names: + setattr(self._ant, name, ['test-filter-1', 'test-filter-2']) getUtility(IListManager).delete(self._ant) store = Store.of(self._ant) filters = store.find(ContentFilter, diff --git a/src/mailman/model/tests/test_mailinglist.py b/src/mailman/model/tests/test_mailinglist.py new file mode 100644 index 000000000..9d6177b54 --- /dev/null +++ b/src/mailman/model/tests/test_mailinglist.py @@ -0,0 +1,106 @@ +# Copyright (C) 2013-2014 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test MailingLists and related model objects..""" + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'TestListArchiver', + 'TestDisabledListArchiver', + ] + + +import unittest + +from mailman.app.lifecycle import create_list +from mailman.config import config +from mailman.interfaces.mailinglist import IListArchiverSet +from mailman.testing.helpers import configuration +from mailman.testing.layers import ConfigLayer + + + +class TestListArchiver(unittest.TestCase): + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('ant@example.com') + self._set = IListArchiverSet(self._mlist) + + def test_list_archivers(self): + # Find the set of archivers registered for this mailing list. + self.assertEqual( + ['mail-archive', 'mhonarc', 'prototype'], + sorted(archiver.name for archiver in self._set.archivers)) + + def test_get_archiver(self): + # Use .get() to see if a mailing list has an archiver. + archiver = self._set.get('prototype') + self.assertEqual(archiver.name, 'prototype') + self.assertTrue(archiver.is_enabled) + self.assertEqual(archiver.mailing_list, self._mlist) + self.assertEqual(archiver.system_archiver.name, 'prototype') + + def test_get_archiver_no_such(self): + # Using .get() on a non-existing name returns None. + self.assertIsNone(self._set.get('no-such-archiver')) + + def test_site_disabled(self): + # Here the system configuration enables all the archivers in time for + # the archive set to be created with all list archivers enabled. But + # then the site-wide archiver gets disabled, so the list specific + # archiver will also be disabled. + archiver_set = IListArchiverSet(self._mlist) + archiver = archiver_set.get('prototype') + self.assertTrue(archiver.is_enabled) + # Disable the site-wide archiver. + config.push('enable prototype', """\ + [archiver.prototype] + enable: no + """) + self.assertFalse(archiver.is_enabled) + config.pop('enable prototype') + + + +class TestDisabledListArchiver(unittest.TestCase): + layer = ConfigLayer + + def setUp(self): + self._mlist = create_list('ant@example.com') + + @configuration('archiver.prototype', enable='no') + def test_enable_list_archiver(self): + # When the system configuration file disables an archiver site-wide, + # the list-specific mailing list will get initialized as not enabled. + # Create the archiver set on the fly so that it doesn't get + # initialized with a configuration that enables the prototype archiver. + archiver_set = IListArchiverSet(self._mlist) + archiver = archiver_set.get('prototype') + self.assertFalse(archiver.is_enabled) + # Enable both the list archiver and the system archiver. + archiver.is_enabled = True + config.push('enable prototype', """\ + [archiver.prototype] + enable: yes + """) + # Get the IListArchiver again. + archiver = archiver_set.get('prototype') + self.assertTrue(archiver.is_enabled) + config.pop('enable prototype') diff --git a/src/mailman/model/tests/test_member.py b/src/mailman/model/tests/test_member.py index c8ddb7f47..5bd3d1594 100644 --- a/src/mailman/model/tests/test_member.py +++ b/src/mailman/model/tests/test_member.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # @@ -17,19 +17,21 @@ """Test members.""" -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestMember', ] import unittest from mailman.app.lifecycle import create_list -from mailman.interfaces.member import MembershipError +from mailman.interfaces.member import MemberRole, MembershipError from mailman.interfaces.user import UnverifiedAddressError from mailman.interfaces.usermanager import IUserManager +from mailman.model.member import Member from mailman.testing.layers import ConfigLayer from mailman.utilities.datetime import now @@ -94,3 +96,9 @@ class TestMember(unittest.TestCase): # The new address is not verified. self.assertRaises(MembershipError, setattr, member, 'address', bart_address) + + def test_member_ctor_value_error(self): + # ValueError when passing in anything but a user or address. + self.assertRaises(ValueError, Member, MemberRole.member, + self._mlist.list_id, + 'aperson@example.com') diff --git a/src/mailman/model/tests/test_requests.py b/src/mailman/model/tests/test_requests.py index 2c85f7340..dc1b9b849 100644 --- a/src/mailman/model/tests/test_requests.py +++ b/src/mailman/model/tests/test_requests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2012-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/tests/test_roster.py b/src/mailman/model/tests/test_roster.py index ccc3958b9..5bd06f485 100644 --- a/src/mailman/model/tests/test_roster.py +++ b/src/mailman/model/tests/test_roster.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2012-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/tests/test_uid.py b/src/mailman/model/tests/test_uid.py index 726c91f38..f74ffed54 100644 --- a/src/mailman/model/tests/test_uid.py +++ b/src/mailman/model/tests/test_uid.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/tests/test_user.py b/src/mailman/model/tests/test_user.py index 80d3397c8..d184eb176 100644 --- a/src/mailman/model/tests/test_user.py +++ b/src/mailman/model/tests/test_user.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/uid.py b/src/mailman/model/uid.py index eb1c7e50e..c60d0f1eb 100644 --- a/src/mailman/model/uid.py +++ b/src/mailman/model/uid.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2011-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py index 082b7adcf..f2c09c626 100644 --- a/src/mailman/model/user.py +++ b/src/mailman/model/user.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/usermanager.py b/src/mailman/model/usermanager.py index 07de5dc90..6f4a7ff5c 100644 --- a/src/mailman/model/usermanager.py +++ b/src/mailman/model/usermanager.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # diff --git a/src/mailman/model/version.py b/src/mailman/model/version.py index 5d4347b8f..e99fb0d1c 100644 --- a/src/mailman/model/version.py +++ b/src/mailman/model/version.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2013 by the Free Software Foundation, Inc. +# Copyright (C) 2007-2014 by the Free Software Foundation, Inc. # # This file is part of GNU Mailman. # |
