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 2015/02/13 22:12:47 UTC
[1/3] allura git commit: [#7823] ticket:724 Change
EmailAddress.canonical behavior on invalid emails
Repository: allura
Updated Branches:
refs/heads/master 17d427623 -> 0d6a44318
[#7823] ticket:724 Change EmailAddress.canonical behavior on invalid emails
Return None, instead of 'nobody@example.com'.
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/0d6a4431
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/0d6a4431
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/0d6a4431
Branch: refs/heads/master
Commit: 0d6a44318b399203a9e732d276b6ebf873e36d8c
Parents: 1c2d973
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Feb 12 13:10:32 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Feb 13 20:48:35 2015 +0000
----------------------------------------------------------------------
Allura/allura/controllers/auth.py | 32 +++++++++++++++-------------
Allura/allura/lib/utils.py | 38 +++++++++++++++++++++++++++++++++-
Allura/allura/model/auth.py | 28 +++++++++++++++++--------
Allura/allura/tests/test_utils.py | 19 ++++++++++++++++-
4 files changed, 92 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/0d6a4431/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 453ad8a..2183032 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -232,7 +232,8 @@ class AuthController(BaseController):
user.set_tool_data('allura', pwd_reset_preserve_session=session.id) # else the first password set causes this session to be invalidated
if require_email:
em = user.claim_address(email)
- em.send_verification_link()
+ if em:
+ em.send_verification_link()
flash('User "%s" registered. Verification link was sent to your email.' % username)
else:
plugin.AuthenticationProvider.get(request).login(user)
@@ -490,22 +491,25 @@ class PreferencesController(BaseController):
elif mail_util.isvalid(new_addr['addr']):
em = M.EmailAddress.create(new_addr['addr'])
- user.email_addresses.append(em.email)
- em.claimed_by_user_id = user._id
-
- confirmed_emails = filter(lambda email: email.confirmed, claimed_emails)
- if not confirmed_emails:
- if not admin:
- em.send_verification_link()
+ if em:
+ user.email_addresses.append(em.email)
+ em.claimed_by_user_id = user._id
+
+ 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:
- AuthController()._verify_addr(em)
- else:
- em.send_claim_attempt()
+ em.send_claim_attempt()
- if not admin:
- flash('A verification email has been sent. Please check your email and click to confirm.')
+ if not admin:
+ flash('A verification email has been sent. Please check your email and click to confirm.')
- h.auditlog_user('New email address: %s', new_addr['addr'], user=user)
+ h.auditlog_user('New email address: %s', new_addr['addr'], user=user)
+ else:
+ flash('Email address %s is invalid' % new_addr['addr'], 'error')
else:
flash('Email address %s is invalid' % new_addr['addr'], 'error')
if not primary_addr and not user.get_pref('email_address') and user.email_addresses:
http://git-wip-us.apache.org/repos/asf/allura/blob/0d6a4431/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 35bc039..7a56603 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -48,6 +48,7 @@ import html5lib.sanitizer
from ew import jinja2_ew as ew
from ming.utils import LazyProperty
+from ming.odm.odmsession import ODMCursor
MARKDOWN_EXTENSIONS = ['.markdown', '.mdown', '.mkdn', '.mkd', '.md']
@@ -555,4 +556,39 @@ def ip_address(request):
ip = request.remote_addr
if tg.config.get('ip_address_header'):
ip = request.headers.get(tg.config['ip_address_header']) or ip
- return ip
\ No newline at end of file
+ return ip
+
+
+class EmptyCursor(ODMCursor):
+ """Ming cursor with no results"""
+
+ def __init__(self, *args, **kw):
+ pass
+
+ @property
+ def extensions(self):
+ return []
+
+ def count(self):
+ return 0
+
+ def _next_impl(self):
+ raise StopIteration
+
+ def next(self):
+ raise StopIteration
+
+ def options(self, **kw):
+ return self
+
+ def limit(self, limit):
+ return self
+
+ def skip(self, skip):
+ return self
+
+ def hint(self, index_or_name):
+ return self
+
+ def sort(self, *args, **kw):
+ return self
http://git-wip-us.apache.org/repos/asf/allura/blob/0d6a4431/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index e8bd8a6..0b92443 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -128,7 +128,11 @@ class EmailAddress(MappedClass):
'''Equivalent to Ming's query.get but calls self.canonical on address
before lookup. You should always use this instead of query.get'''
if kw.get('email'):
- kw['email'] = cls.canonical(kw['email'])
+ email = cls.canonical(kw['email'])
+ if email is not None:
+ kw['email'] = email
+ else:
+ return None
return cls.query.get(**kw)
@classmethod
@@ -137,7 +141,11 @@ class EmailAddress(MappedClass):
before lookup. You should always use this instead of query.find'''
if q:
if q.get('email'):
- q['email'] = cls.canonical(q['email'])
+ email = cls.canonical(q['email'])
+ if email is not None:
+ q['email'] = email
+ else:
+ return utils.EmptyCursor()
return cls.query.find(q)
return cls.query.find()
@@ -152,7 +160,8 @@ class EmailAddress(MappedClass):
@classmethod
def create(cls, addr):
addr = cls.canonical(addr)
- return cls(email=addr)
+ if addr is not None:
+ return cls(email=addr)
@classmethod
def canonical(cls, addr):
@@ -163,7 +172,7 @@ class EmailAddress(MappedClass):
user, domain = addr.split('@')
return '%s@%s' % (user, domain.lower())
else:
- return 'nobody@example.com'
+ return None
def send_claim_attempt(self):
confirmed_email = self.find(dict(email=self.email, confirmed=True)).all()
@@ -666,11 +675,12 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
def claim_address(self, email_address):
addr = EmailAddress.canonical(email_address)
email_addr = EmailAddress.create(addr)
- email_addr.claimed_by_user_id = self._id
- if addr not in self.email_addresses:
- self.email_addresses.append(addr)
- session(email_addr).flush(email_addr)
- return email_addr
+ if email_addr:
+ email_addr.claimed_by_user_id = self._id
+ if addr not in self.email_addresses:
+ self.email_addresses.append(addr)
+ session(email_addr).flush(email_addr)
+ return email_addr
@classmethod
def register(cls, doc, make_project=True):
http://git-wip-us.apache.org/repos/asf/allura/blob/0d6a4431/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 209d0df..e5f9c43 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -23,7 +23,7 @@ from os import path
from webob import Request
from mock import Mock, patch
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_raises
from pygments import highlight
from pygments.lexers import get_lexer_for_filename
from tg import config
@@ -278,3 +278,20 @@ def test_ip_address_header_not_set():
with h.push_config(config, **{'ip_address_header': 'X_FORWARDED_FOR'}):
assert_equal(utils.ip_address(req),
'1.2.3.4')
+
+
+def test_empty_cursor():
+ """EmptyCursors conforms to specification of Ming's ODMCursor"""
+ cursor = utils.EmptyCursor()
+ assert_equal(cursor.count(), 0)
+ assert_equal(cursor.first(), None)
+ assert_equal(cursor.all(), [])
+ assert_equal(cursor.limit(10), cursor)
+ assert_equal(cursor.skip(10), cursor)
+ assert_equal(cursor.sort('name', 1), cursor)
+ assert_equal(cursor.hint('index'), cursor)
+ assert_equal(cursor.extensions, [])
+ assert_equal(cursor.options(arg1='val1', arg2='val2'), cursor)
+ assert_raises(ValueError, cursor.one)
+ assert_raises(StopIteration, cursor.next)
+ assert_raises(StopIteration, cursor._next_impl)
[3/3] allura git commit: [#7823] ticket:724 s/emai/email/
Posted by br...@apache.org.
[#7823] ticket:724 s/emai/email/
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/f155a687
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f155a687
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f155a687
Branch: refs/heads/master
Commit: f155a687eff70872b852b6dd0c21c52ebb7658ab
Parents: 17d4276
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Feb 12 10:28:05 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Feb 13 20:48:35 2015 +0000
----------------------------------------------------------------------
Allura/allura/model/repo_refresh.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/f155a687/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index cdd71dc..3dbad4a 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -142,7 +142,7 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False):
if user is not None:
g.statsUpdater.newCommit(new, repo.app_config.project, user)
actor = user or TransientActor(
- activity_name=new.committed.name or new.committed.emai)
+ activity_name=new.committed.name or new.committed.email)
g.director.create_activity(actor, 'committed', new,
related_nodes=[repo.app_config.project],
tags=['commit', repo.tool.lower()])
[2/3] allura git commit: [#7823] ticket:724 Add tests for new
EmailAddress.canonical behavior
Posted by br...@apache.org.
[#7823] ticket:724 Add tests for new EmailAddress.canonical behavior
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1c2d973c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1c2d973c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1c2d973c
Branch: refs/heads/master
Commit: 1c2d973c7961195101699270a6dff0e3af644337
Parents: f155a68
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Feb 12 10:28:46 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Feb 13 20:48:35 2015 +0000
----------------------------------------------------------------------
Allura/allura/tests/model/test_auth.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/1c2d973c/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 3356ce1..12db982 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -74,6 +74,7 @@ def test_email_address():
@with_setup(setUp)
def test_email_address_lookup_helpers():
addr = M.EmailAddress.create('TEST@DOMAIN.NET')
+ nobody = M.EmailAddress.create('nobody@example.com')
ThreadLocalORMSession.flush_all()
assert_equal(addr.email, 'TEST@domain.net')
@@ -81,14 +82,30 @@ def test_email_address_lookup_helpers():
assert_equal(M.EmailAddress.get(email='TEST@domain.net'), addr)
assert_equal(M.EmailAddress.get(email='test@domain.net'), None)
assert_equal(M.EmailAddress.get(email=None), None)
+ assert_equal(M.EmailAddress.get(email='nobody@example.com'), nobody)
+ # invalid email returns None, but not nobody@example.com as before
+ assert_equal(M.EmailAddress.get(email='invalid'), None)
assert_equal(M.EmailAddress.find(dict(email='TEST@DOMAIN.NET')).all(), [addr])
assert_equal(M.EmailAddress.find(dict(email='TEST@domain.net')).all(), [addr])
assert_equal(M.EmailAddress.find(dict(email='test@domain.net')).all(), [])
assert_equal(M.EmailAddress.find(dict(email=None)).all(), [])
+ assert_equal(M.EmailAddress.find(dict(email='nobody@example.com')).all(), [nobody])
+ # invalid email returns empty query, but not nobody@example.com as before
+ assert_equal(M.EmailAddress.find(dict(email='invalid')).all(), [])
@with_setup(setUp)
+def test_email_address_canonical():
+ assert_equal(M.EmailAddress.canonical('nobody@EXAMPLE.COM'),
+ 'nobody@example.com')
+ assert_equal(M.EmailAddress.canonical('nobody@example.com'),
+ 'nobody@example.com')
+ assert_equal(M.EmailAddress.canonical('I Am Nobody <no...@example.com>'),
+ 'nobody@example.com')
+ assert_equal(M.EmailAddress.canonical('invalid'), None)
+
+@with_setup(setUp)
def test_email_address_send_verification_link():
addr = M.EmailAddress(email='test_admin@domain.net',
claimed_by_user_id=c.user._id)
@@ -178,7 +195,6 @@ def test_user_by_email_address(log):
claimed_by_user_id=u1._id)
addr2 = M.EmailAddress(email='abc123@abc.me', confirmed=True,
claimed_by_user_id=u2._id)
-
# both users are disabled
u1.disabled, u2.disabled = True, True
ThreadLocalORMSession.flush_all()
@@ -197,6 +213,14 @@ def test_user_by_email_address(log):
assert_in(M.User.by_email_address('abc123@abc.me'), [u1, u2])
assert_equal(log.warn.call_count, 1)
+ # invalid email returns None, but not user which claimed
+ # nobody@example.com as before
+ nobody = M.EmailAddress(email='nobody@example.com', confirmed=True,
+ claimed_by_user_id=u1._id)
+ ThreadLocalORMSession.flush_all()
+ assert_equal(M.User.by_email_address('nobody@example.com'), u1)
+ assert_equal(M.User.by_email_address('invalid'), None)
+
@with_setup(setUp)
def test_project_role():