You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/01/16 00:11:56 UTC

git commit: [#7062] set first email to primary if none; unset primary when its deleted

Updated Branches:
  refs/heads/db/7062 [created] cc8bbaa6d


[#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/cc8bbaa6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/cc8bbaa6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/cc8bbaa6

Branch: refs/heads/db/7062
Commit: cc8bbaa6d98f2568eb44d4a4eb6bf64cdccc2c48
Parents: 05f5804
Author: Dave Brondsema <da...@brondsema.net>
Authored: Wed Jan 15 18:11:52 2014 -0500
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Wed Jan 15 18:11:52 2014 -0500

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cc8bbaa6/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 8e08e13..89a1f1a 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -450,10 +450,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')
@@ -462,6 +464,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: