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/10/05 21:38:33 UTC

[1/2] allura git commit: [#7991] limit phone number usage to once

Repository: allura
Updated Branches:
  refs/heads/db/7991 [created] b79b85469


[#7991] limit phone number usage to once


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

Branch: refs/heads/db/7991
Commit: b79b854693f1aadebe408e7f95bad2a747cbf047
Parents: c8300e1
Author: Dave Brondsema <da...@brondsema.net>
Authored: Mon Oct 5 15:19:55 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Mon Oct 5 15:38:26 2015 -0400

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                         |  7 ++++++-
 Allura/allura/tests/functional/test_neighborhood.py | 16 +++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/b79b8546/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 2270dcb..46cd3e8 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -726,11 +726,16 @@ class ProjectRegistrationProvider(object):
             return True
         return bool(user.get_tool_data('phone_verification', 'number_hash'))
 
-    def verify_phone(self, user, number):
+    def verify_phone(self, user, number, allow_reuse=False):
+        from allura import model as M
         ok = {'status': 'ok'}
         if not asbool(config.get('project.verify_phone')):
             return ok
         number = utils.clean_phone_number(number)
+        number_hash = utils.phone_number_hash(number)
+        if not allow_reuse and M.User.query.find({'tool_data.phone_verification.number_hash': number_hash}).count():
+            return {'status': 'error',
+                    'error': 'That phone number has already been used.'}
         return g.phone_service.verify(number)
 
     def check_phone_verification(self, user, request_id, pin, number_hash):

http://git-wip-us.apache.org/repos/asf/allura/blob/b79b8546/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 8b6a74f..9b8b215 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -24,7 +24,7 @@ import PIL
 from mock import patch
 from tg import config
 from nose.tools import assert_equal, assert_in, assert_not_equal
-from ming.orm.ormsession import ThreadLocalORMSession
+from ming.orm.ormsession import ThreadLocalORMSession, session
 from paste.httpexceptions import HTTPFound
 from pylons import app_globals as g
 
@@ -33,6 +33,7 @@ from allura import model as M
 from allura.tests import TestController
 from allura.tests import decorators as td
 from allura.lib import helpers as h
+from allura.lib import utils
 from alluratest.controller import setup_trove_categories
 
 
@@ -1006,6 +1007,19 @@ class TestPhoneVerificationOnProjectRegistration(TestController):
         }
         assert_equal(r.json, expected)
 
+    @patch.object(g, 'phone_service', autospec=True)
+    def test_verify_phone_already_used(self, phone_service):
+        with h.push_config(config, **{'project.verify_phone': 'true'}):
+            u = M.User.register(dict(username='existing-user'), make_project=False)
+            u.set_tool_data('phone_verification', number_hash=utils.phone_number_hash('1-555-444-9999'))
+            session(u).flush(u)
+            phone_service.verify.return_value = {'request_id': 'request-id', 'status': 'ok'}
+            r = self.app.get('/p/verify_phone', {'number': '1-555-444-9999'})
+            assert_equal(r.json, {
+                'status': 'error',
+                'error': u'That phone number has already been used.'
+            })
+
     def test_check_phone_verification_no_params(self):
         with h.push_config(config, **{'project.verify_phone': 'true'}):
             self.app.get('/p/check_phone_verification', status=404)


[2/2] allura git commit: [#7991] Add sparse index for phone_verification.number_hash

Posted by br...@apache.org.
[#7991] Add sparse index for phone_verification.number_hash


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

Branch: refs/heads/db/7991
Commit: c8300e128dd3b6c936ce9dacbe88da10b04c05d6
Parents: 0323078
Author: Dave Brondsema <da...@brondsema.net>
Authored: Mon Oct 5 12:05:40 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Mon Oct 5 15:38:26 2015 -0400

----------------------------------------------------------------------
 Allura/allura/command/show_models.py | 10 ++++------
 Allura/allura/model/auth.py          |  3 +++
 Allura/allura/tests/test_commands.py | 13 ++++++++-----
 3 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c8300e12/Allura/allura/command/show_models.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/show_models.py b/Allura/allura/command/show_models.py
index 89a2a88..d651383 100644
--- a/Allura/allura/command/show_models.py
+++ b/Allura/allura/command/show_models.py
@@ -282,24 +282,22 @@ class EnsureIndexCommand(base.Command):
             base.log.info('...... ensure %s:%s', collection.name, idx)
             while True:
                 try:
-                    collection.ensure_index(idx.index_spec, unique=True)
+                    collection.ensure_index(idx.index_spec, **idx.index_options)
                     break
                 except DuplicateKeyError, err:
                     base.log.info('Found dupe key(%s), eliminating dupes', err)
                     self._remove_dupes(collection, idx.index_spec)
         for keys, idx in indexes.iteritems():
             base.log.info('...... ensure %s:%s', collection.name, idx)
-            collection.ensure_index(idx.index_spec, background=True)
+            collection.ensure_index(idx.index_spec, background=True, **idx.index_options)
         # Drop obsolete indexes
         for iname, keys in prev_indexes.iteritems():
             if keys not in indexes:
-                base.log.info('...... drop index %s:%s',
-                              collection.name, iname)
+                base.log.info('...... drop index %s:%s', collection.name, iname)
                 collection.drop_index(iname)
         for iname, keys in prev_uindexes.iteritems():
             if keys not in uindexes:
-                base.log.info('...... drop index %s:%s',
-                              collection.name, iname)
+                base.log.info('...... drop index %s:%s', collection.name, iname)
                 collection.drop_index(iname)
 
     def _recreate_index(self, collection, iname, keys, **creation_options):

http://git-wip-us.apache.org/repos/asf/allura/blob/c8300e12/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 163d5de..955c952 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -272,6 +272,9 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
         session = main_orm_session
         indexes = ['tool_data.sfx.userid', 'tool_data.AuthPasswordReset.hash']
         unique_indexes = ['username']
+        custom_indexes = [
+            dict(fields=('tool_data.phone_verification.number_hash',), sparse=True),
+        ]
 
     type_s = 'User'
 

http://git-wip-us.apache.org/repos/asf/allura/blob/c8300e12/Allura/allura/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_commands.py b/Allura/allura/tests/test_commands.py
index f6800b7..fb5fb03 100644
--- a/Allura/allura/tests/test_commands.py
+++ b/Allura/allura/tests/test_commands.py
@@ -187,7 +187,8 @@ class TestEnsureIndexCommand(object):
             '_foo_bar': {'key': [('foo', 1), ('bar', 1)]},
         }
         indexes = [
-            Mock(unique=False, index_spec=[('foo', 1)]),
+            Mock(unique=False, index_spec=[('foo', 1)],
+                 index_options={'unique': False, 'sparse': False}),
         ]
         cmd = show_models.EnsureIndexCommand('ensure_index')
         cmd._update_indexes(collection, indexes)
@@ -216,8 +217,10 @@ class TestEnsureIndexCommand(object):
             '_foo_baz': {'key': [('foo', 1), ('baz', 1)]},
         }
         indexes = [
-            Mock(index_spec=[('foo', 1), ('bar', 1)], unique=False, ),
-            Mock(index_spec=[('foo', 1), ('baz', 1)], unique=True, ),
+            Mock(index_spec=[('foo', 1), ('bar', 1)], unique=False,
+                 index_options={'unique': False, 'sparse': False}),
+            Mock(index_spec=[('foo', 1), ('baz', 1)], unique=True,
+                 index_options={'unique': True, 'sparse': False}),
         ]
 
         cmd = show_models.EnsureIndexCommand('ensure_index')
@@ -235,8 +238,8 @@ class TestEnsureIndexCommand(object):
             call.drop_index('_foo_baz'),
             call.ensure_index([('foo', 1), ('baz', 1)], unique=True),
             call.drop_index('_foo_baz_temporary_extra_field_for_indexing'),
-            call.ensure_index([('foo', 1), ('baz', 1)], unique=True),
-            call.ensure_index([('foo', 1), ('bar', 1)], background=True)
+            call.ensure_index([('foo', 1), ('baz', 1)], unique=True, sparse=False),
+            call.ensure_index([('foo', 1), ('bar', 1)], unique=False, sparse=False, background=True)
         ])