allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [26/26] git commit: [#7062] set first email to primary if none; unset primary when its deleted
Date Wed, 22 Jan 2014 20:57:18 GMT
[#7062] set first email to primary if none; unset primary when its deleted


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/72248751
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/72248751
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/72248751

Branch: refs/heads/db/7062
Commit: 72248751466a4decbbf190d9eae123d9543bc50c
Parents: a2bc2dd
Author: Dave Brondsema <dave@brondsema.net>
Authored: Wed Jan 15 18:11:52 2014 -0500
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Wed Jan 22 15:55:58 2014 -0500

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py           |  8 ++++++-
 Allura/allura/tests/functional/test_auth.py | 29 +++++++++++++-----------
 2 files changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/72248751/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index e7a58b8..2b93dc4 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -446,10 +446,12 @@ class PreferencesController(BaseController):
             for i, (old_a, data) in enumerate(zip(c.user.email_addresses, addr or [])):
                 obj = c.user.address_object(old_a)
                 if data.get('delete') or not obj:
+                    if primary_addr == c.user.email_addresses[i]:
+                        c.user.set_pref('email_address', None)
+                        primary_addr = None
                     del c.user.email_addresses[i]
                     if obj:
                         obj.delete()
-            c.user.set_pref('email_address', primary_addr)
             if new_addr.get('claim'):
                 if M.EmailAddress.query.get(_id=new_addr['addr'], confirmed=True):
                     flash('Email address already claimed', 'error')
@@ -458,6 +460,10 @@ class PreferencesController(BaseController):
                     em = M.EmailAddress.upsert(new_addr['addr'])
                     em.claimed_by_user_id = c.user._id
                     em.send_verification_link()
+            if not primary_addr and not c.user.get_pref('email_address') and c.user.email_addresses:
+                primary_addr = c.user.email_addresses[0]
+            if primary_addr:
+                c.user.set_pref('email_address', primary_addr)
             for i, (old_oid, data) in enumerate(zip(c.user.open_ids, oid or [])):
                 obj = c.user.openid_object(old_oid)
                 if data.get('delete') or not obj:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/72248751/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index cff1e47..e41a220 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -74,7 +74,13 @@ class TestAuth(TestController):
     def test_prefs(self):
         r = self.app.get('/auth/preferences/',
                          extra_environ=dict(username='test-admin'))
+        # check preconditions of test data
         assert 'test@example.com' not in r
+        assert 'test-admin@users.localhost' in r
+        assert_equal(M.User.query.get(username='test-admin').get_pref('email_address'),
+                     'test-admin@users.localhost')
+
+        # add test@example
         r = self.app.post('/auth/preferences/update', params={
             'preferences.display_name': 'Test Admin',
             'new_addr.addr': 'test@example.com',
@@ -84,27 +90,24 @@ class TestAuth(TestController):
             extra_environ=dict(username='test-admin'))
         r = self.app.get('/auth/preferences/')
         assert 'test@example.com' in r
+        assert_equal(M.User.query.get(username='test-admin').get_pref('email_address'),
+                     'test-admin@users.localhost')
+
+        # remove test-admin@users.localhost
         r = self.app.post('/auth/preferences/update', params={
             'preferences.display_name': 'Test Admin',
             'addr-1.ord': '1',
-            'addr-2.ord': '1',
-            'addr-2.delete': 'on',
+            'addr-1.delete': 'on',
+            'addr-2.ord': '2',
             'new_addr.addr': '',
             'primary_addr': 'test-admin@users.localhost',
             'preferences.email_format': 'plain'},
             extra_environ=dict(username='test-admin'))
         r = self.app.get('/auth/preferences/')
-        assert 'test@example.com' not in r
-        ea = M.EmailAddress.query.get(_id='test-admin@users.localhost')
-        ea.confirmed = True
-        ThreadLocalORMSession.flush_all()
-        r = self.app.post('/auth/preferences/update', params={
-            'preferences.display_name': 'Test Admin',
-            'new_addr.addr': 'test-admin@users.localhost',
-            'new_addr.claim': 'Claim Address',
-            'primary_addr': 'test-admin@users.localhost',
-            'preferences.email_format': 'plain'},
-            extra_environ=dict(username='test-admin'))
+        assert 'test-admin@users.localhost' not in r
+        # preferred address has changed to remaining address
+        assert_equal(M.User.query.get(username='test-admin').get_pref('email_address'),
+                     'test@example.com')
 
     @td.with_user_project('test-admin')
     def test_prefs_subscriptions(self):


Mime
View raw message