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/09/12 12:29:25 UTC
[11/28] git commit: [#7527] Bugfixing
[#7527] Bugfixing
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/d307dca7
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/d307dca7
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/d307dca7
Branch: refs/heads/je/42cc_4905
Commit: d307dca7cc9ea10685fa6d611644be3d8335d9e1
Parents: 888f604
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Mon Jul 28 21:16:07 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 28 20:27:01 2014 +0000
----------------------------------------------------------------------
Allura/allura/controllers/auth.py | 8 +++---
Allura/allura/lib/mail_util.py | 2 +-
Allura/allura/model/auth.py | 27 +++-----------------
Allura/allura/tests/functional/test_auth.py | 2 +-
Allura/allura/tests/model/test_auth.py | 6 ++---
Allura/allura/tests/test_mail_util.py | 8 +++---
Allura/allura/websetup/bootstrap.py | 4 +++
.../forgeuserstats/tests/test_model.py | 2 +-
.../forgeuserstats/tests/test_stats.py | 2 +-
9 files changed, 23 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index dc3a177..d2c97a7 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -179,7 +179,7 @@ class AuthController(BaseController):
if not email:
redirect('/')
- email_record = M.EmailAddress.query.find({'email': email}).first()
+ email_record = M.EmailAddress.query.get(email=email, confirmed=True)
user_record = M.User.by_email_address(email)
if user_record and email_record.confirmed:
@@ -236,8 +236,6 @@ class AuthController(BaseController):
@expose()
def verify_addr(self, a):
addr = M.EmailAddress.query.get(nonce=a)
- # import pydevd
- # pydevd.settrace('localhost', port=14000, stdoutToServer=True, stderrToServer=True)
if addr:
addr.confirmed = True
@@ -249,12 +247,14 @@ class AuthController(BaseController):
users = [email.claimed_by_user() for email in claimed_by_others]
for user in users:
+ log.info("Removed the email %s from user %s " % (addr.email, user.username))
user.email_addresses.remove(addr.email)
M.EmailAddress.query.remove({
'email': addr.email,
'claimed_by_user_id': {'$ne': addr.claimed_by_user_id}
})
+
flash('Email address confirmed')
M.AuditLog.log_user('Email address verified: %s', addr._id)
else:
@@ -464,7 +464,7 @@ class PreferencesController(BaseController):
flash('Email address already claimed', 'error')
elif mail_util.isvalid(new_addr['addr']):
c.user.email_addresses.append(new_addr['addr'])
- em = M.EmailAddress.upsert(new_addr['addr'])
+ em = M.EmailAddress.create(new_addr['addr'])
em.claimed_by_user_id = c.user._id
em.send_verification_link()
M.AuditLog.log_user('New email address: %s', new_addr['addr'])
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/Allura/allura/lib/mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index a932f13..20fc411 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -159,7 +159,7 @@ def identify_sender(peer, email_address, headers, msg):
from allura import model as M
# Dumb ID -- just look for email address claimed by a particular user
addr = M.EmailAddress.query.get(
- email=M.EmailAddress.canonical(email_address))
+ email=M.EmailAddress.canonical(email_address), confirmed=True)
if addr and addr.claimed_by_user_id:
return addr.claimed_by_user()
from_address = headers.get('From', '').strip()
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 1c753d5..7cc169d 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -115,6 +115,7 @@ class EmailAddress(MappedClass):
class __mongometa__:
name = 'email_address'
session = main_orm_session
+ indexes = ['nonce',]
unique_indexes = [('email', 'claimed_by_user_id'),]
_id = FieldProperty(S.ObjectId)
@@ -127,7 +128,7 @@ class EmailAddress(MappedClass):
return User.query.get(_id=self.claimed_by_user_id, disabled=False)
@classmethod
- def upsert(cls, addr):
+ def create(cls, addr):
addr = cls.canonical(addr)
return cls(email=addr)
@@ -547,7 +548,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
@classmethod
def by_email_address(cls, addr):
- ea = EmailAddress.query.get(email=addr)
+ ea = EmailAddress.query.get(email=addr, confirmed=True)
if ea is None:
return None
return ea.claimed_by_user()
@@ -574,32 +575,12 @@ class User(MappedClass, ActivityNode, ActivityObject):
def claim_address(self, email_address):
addr = EmailAddress.canonical(email_address)
- email_addr = EmailAddress.upsert(addr)
+ email_addr = EmailAddress.create(addr)
email_addr.claimed_by_user_id = self._id
if addr in self.email_addresses:
return
self.email_addresses.append(addr)
- def claim_only_addresses(self, *addresses):
- '''Claims the listed addresses and no others, setting the confirmed
- attribute to True on all.
- '''
- self.email_addresses = [
- EmailAddress.canonical(a) for a in addresses]
- addresses = set(self.email_addresses)
- for addr in EmailAddress.query.find(
- dict(claimed_by_user_id=self._id)):
- if addr.email in addresses:
- if not addr.confirmed:
- addr.confirmed = True
- addresses.remove(addr.email)
- else:
- addr.delete()
- for a in addresses:
- addr = EmailAddress.upsert(a)
- addr.claimed_by_user_id = self._id
- addr.confirmed = True
-
@classmethod
def register(cls, doc, make_project=True):
from allura import model as M
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/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 65d3a50..b4e174e 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -898,7 +898,7 @@ To reset your password on %s, please visit the following URL:
%s/auth/forgotten_password/%s''' % (config['site_name'], config['base_url'], hash)
sendmail.post.assert_called_once_with(
- toaddr=email._id,
+ toaddr=email.email,
fromaddr=config['forgemail.return_path'],
reply_to=config['forgemail.return_path'],
subject='Allura Password recovery',
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/Allura/allura/tests/model/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 165e331..9c5a74c 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -55,15 +55,15 @@ def test_email_address():
claimed_by_user_id=c.user._id)
ThreadLocalORMSession.flush_all()
assert addr.claimed_by_user() == c.user
- addr2 = M.EmailAddress.upsert('test@domain.net')
- addr3 = M.EmailAddress.upsert('test_admin@domain.net')
+ addr2 = M.EmailAddress.create('test@domain.net')
+ addr3 = M.EmailAddress.create('test_admin@domain.net')
# Duplicate emails are allowed, until the email is confirmed
assert addr3 is not addr
assert addr2 is not addr
assert addr2
- addr4 = M.EmailAddress.upsert('test@DOMAIN.NET')
+ addr4 = M.EmailAddress.create('test@DOMAIN.NET')
assert addr4 is not addr2
with patch('allura.lib.app_globals.request', Request.blank('/')):
addr.send_verification_link()
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/Allura/allura/tests/test_mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_mail_util.py b/Allura/allura/tests/test_mail_util.py
index c2fe363..2263940 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -193,7 +193,7 @@ class TestIdentifySender(object):
EA.query.get.side_effect = [
mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda:'user')]
assert_equal(identify_sender(None, 'arg', None, None), 'user')
- EA.query.get.assert_called_once_with(email='arg')
+ EA.query.get.assert_called_once_with(email='arg', confirmed=True)
@mock.patch('allura.model.EmailAddress')
def test_header(self, EA):
@@ -203,7 +203,7 @@ class TestIdentifySender(object):
assert_equal(
identify_sender(None, 'arg', {'From': 'from'}, None), 'user')
assert_equal(EA.query.get.call_args_list,
- [mock.call(email='arg'), mock.call(email='from')])
+ [mock.call(email='arg', confirmed=True), mock.call(email='from')])
@mock.patch('allura.model.User')
@mock.patch('allura.model.EmailAddress')
@@ -213,7 +213,7 @@ class TestIdentifySender(object):
EA.query.get.side_effect = [
None, mock.Mock(claimed_by_user_id=True, claimed_by_user=lambda:'user')]
assert_equal(identify_sender(None, 'arg', {}, None), anon)
- assert_equal(EA.query.get.call_args_list, [mock.call(email='arg')])
+ assert_equal(EA.query.get.call_args_list, [mock.call(email='arg', confirmed=True)])
@mock.patch('allura.model.User')
@mock.patch('allura.model.EmailAddress')
@@ -224,7 +224,7 @@ class TestIdentifySender(object):
assert_equal(
identify_sender(None, 'arg', {'From': 'from'}, None), anon)
assert_equal(EA.query.get.call_args_list,
- [mock.call(email='arg'), mock.call(email='from')])
+ [mock.call(email='arg', confirmed=True), mock.call(email='from')])
def test_parse_message_id():
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/Allura/allura/websetup/bootstrap.py
----------------------------------------------------------------------
diff --git a/Allura/allura/websetup/bootstrap.py b/Allura/allura/websetup/bootstrap.py
index f7b1a99..840f171 100644
--- a/Allura/allura/websetup/bootstrap.py
+++ b/Allura/allura/websetup/bootstrap.py
@@ -212,6 +212,10 @@ def bootstrap(command, conf, vars):
u_admin.email_addresses = ['test-admin@users.localhost']
u_admin.set_password('foo')
u_admin.claim_address('test-admin@users.localhost')
+ ThreadLocalORMSession.flush_all()
+
+ admin_email = M.EmailAddress.query.get(email='test-admin@users.localhost')
+ admin_email.confirmed = True
else:
u_admin = make_user('Admin 1', username='admin1')
# Admin1 is almost root, with admin access for Users and Projects
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/ForgeUserStats/forgeuserstats/tests/test_model.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/tests/test_model.py b/ForgeUserStats/forgeuserstats/tests/test_model.py
index c9a8cf4..e7670de 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_model.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_model.py
@@ -371,7 +371,7 @@ class TestUserStats(unittest.TestCase):
with mock.patch('allura.lib.plugin.session'):
self.user.set_password('testpassword')
- addr = M.EmailAddress.upsert('rcopeland@geek.net')
+ addr = M.EmailAddress.create('rcopeland@geek.net')
self.user.claim_address('rcopeland@geek.net')
repo_dir = pkg_resources.resource_filename(
http://git-wip-us.apache.org/repos/asf/allura/blob/d307dca7/ForgeUserStats/forgeuserstats/tests/test_stats.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/tests/test_stats.py b/ForgeUserStats/forgeuserstats/tests/test_stats.py
index 85f4d09..a09de1e 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_stats.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_stats.py
@@ -195,7 +195,7 @@ class TestGitCommit(TestController, unittest.TestCase):
user = User.by_username('test-admin')
user.set_password('testpassword')
- M.EmailAddress.upsert('rcopeland@geek.net')
+ M.EmailAddress.create('rcopeland@geek.net')
user.claim_address('rcopeland@geek.net')
self.setup_with_tools()