You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/10/28 10:11:27 UTC

[3/8] git commit: [#7717] Send claim notification if the email was confirmed by other user

[#7717] Send claim notification if the email was confirmed by other user


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

Branch: refs/heads/master
Commit: 67d8b38cf6505d693e052e334183a36fe84a2f28
Parents: dd0ab3e
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Wed Oct 15 16:31:25 2014 -0700
Committer: Alexander Luberg <al...@slashdotmedia.com>
Committed: Mon Oct 27 14:55:57 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py           | 19 +++++++++++++++++--
 Allura/allura/tests/functional/test_auth.py | 10 +++++++++-
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/67d8b38c/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index ee8f0e8..c63fb6e 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -468,12 +468,27 @@ class PreferencesController(BaseController):
                 em = M.EmailAddress.create(new_addr['addr'])
                 em.claimed_by_user_id = user._id
 
-                if not any(email.confirmed for email in claimed_emails):
+                confirmed_emails = filter(lambda email: email.confirmed, claimed_emails)
+                if not confirmed_emails:
                     if not admin:
                         em.send_verification_link()
                     else:
                         AuthController()._verify_addr(em)
-
+                else:
+                    owner = M.User.query.get(_id=confirmed_emails[0].claimed_by_user_id)
+                    text = g.jinja2_env.get_template('allura:templates/mail/claimed_existing_email.txt').render(dict(
+                        email=confirmed_emails[0],
+                        user=owner,
+                        config=config
+                    ))
+
+                    allura.tasks.mail_tasks.sendsimplemail.post(
+                        toaddr=confirmed_emails[0].email,
+                        fromaddr=config['forgemail.return_path'],
+                        reply_to=config['forgemail.return_path'],
+                        subject=u'%s - Email address claim attempt' % config['site_name'],
+                        message_id=h.gen_message_id(),
+                        text=text)
                 if not admin:
                     flash('A verification email has been sent.  Please check your email and click to confirm.')
 

http://git-wip-us.apache.org/repos/asf/allura/blob/67d8b38c/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 374f041..e46ff44 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -174,7 +174,15 @@ class TestAuth(TestController):
 
         assert json.loads(self.webflash(r))['status'] == 'ok'
         assert json.loads(self.webflash(r))['message'] == 'A verification email has been sent.  Please check your email and click to confirm.'
-        assert not sendsimplemail.post.called
+
+        args, kwargs = sendsimplemail.post.call_args
+
+        assert sendsimplemail.post.call_count == 1
+        assert kwargs['toaddr'] == email_address
+        assert kwargs['subject'] == u'%s - Email address claim attempt' % config['site_name']
+        assert "You tried to add %s to your Allura account, " \
+               "but it is already claimed by your %s account." % (email_address, user.username) in kwargs['text']
+
         assert len(M.User.query.get(username='test-admin').email_addresses) == addresses_number + 1
         assert len(M.EmailAddress.query.find(dict(email=email_address)).all()) == 2