nicolask has proposed merging lp:~nkarageuzian/mailman/usermanagement into 
lp:mailman.

Requested reviews:
  Mailman Coders (mailman-coders)

For more details, see:
https://code.launchpad.net/~nkarageuzian/mailman/usermanagement/+merge/200128

solves the use case:
user sends a mail to the list without subscribing nor registering
admin accepts message
user wants to register to mailman through API but
create_user method fails as sender's address is registered.

and add tests for usermanager and the create_user function.
-- 
https://code.launchpad.net/~nkarageuzian/mailman/usermanagement/+merge/200128
Your team Mailman Coders is requested to review the proposed merge of 
lp:~nkarageuzian/mailman/usermanagement into lp:mailman.
=== added file 'src/mailman/model/tests/test_usermanager.py'
--- src/mailman/model/tests/test_usermanager.py	1970-01-01 00:00:00 +0000
+++ src/mailman/model/tests/test_usermanager.py	2013-12-28 10:18:08 +0000
@@ -0,0 +1,67 @@
+# Copyright (C) 2011-2013 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 usermanager."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+    'TestUserManager',
+    ]
+
+
+import unittest
+
+from zope.component import getUtility
+
+from mailman.app.lifecycle import create_list
+from mailman.interfaces.usermanager import IUserManager
+from mailman.interfaces.address import ExistingAddressError
+from mailman.interfaces.address import IAddress
+from mailman.testing.layers import ConfigLayer
+from mailman.utilities.datetime import now
+
+
+
+class TestUserManager(unittest.TestCase):
+    """Test usermanager."""
+
+    layer = ConfigLayer
+
+    def setUp(self):
+        self._mlist = create_list('[email protected]')
+        #getUtility(IAddress)('[email protected]','No one')
+    
+    def test_create_user(self):
+        anne = getUtility(IUserManager).create_user(
+            '[email protected]', 'Anne Person')
+        
+    def test_create_user_existing_address_user(self):
+        anne = getUtility(IUserManager).create_user(
+            '[email protected]', 'Anne Person')
+        self.assertRaises(ExistingAddressError, getUtility(IUserManager).create_user,*(
+            '[email protected]', 'Anne Person'))
+            
+    def test_create_user_existing_address_no_user(self):
+        anne = getUtility(IUserManager).create_user(
+            '[email protected]', 'Anne Person')
+        noone = getUtility(IUserManager).create_user(
+            '[email protected]','No one')
+        self.assertTrue(anne.user_id != noone.user_id)
+    
+

=== modified file 'src/mailman/model/usermanager.py'
--- src/mailman/model/usermanager.py	2013-01-01 14:05:42 +0000
+++ src/mailman/model/usermanager.py	2013-12-28 10:18:08 +0000
@@ -40,13 +40,24 @@
 @implementer(IUserManager)
 class UserManager:
     """See `IUserManager`."""
-
-    def create_user(self, email=None, display_name=None):
+    @dbconnection
+    def create_user(self, store, email=None, display_name=None):
         """See `IUserManager`."""
         user = User(display_name, Preferences())
         if email:
-            address = self.create_address(email, display_name)
+            address = None
+            try:
+                address = self.create_address(email, display_name)
+            except:
+                addresses = store.find(Address, email=email.lower())
+                if addresses.count() == 0:
+                    raise Exception("inconsistent results")
+                if addresses.one().user == None:
+                    address = addresses.one()
+                else:
+                    raise ExistingAddressError(email)
             user.link(address)
+        store.add(user)
         return user
 
     @dbconnection

_______________________________________________
Mailman-coders mailing list
[email protected]
https://mail.python.org/mailman/listinfo/mailman-coders

Reply via email to