allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [16/26] allura git commit: [#7868] ticket:776 phone_verified returns true for project admins
Date Thu, 28 May 2015 20:13:18 GMT
[#7868] ticket:776 phone_verified returns true for project admins


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

Branch: refs/heads/master
Commit: 77f5ba28e0bd5170bc03c0017ddb1ea48601e03f
Parents: fd699a6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon May 25 16:54:09 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu May 28 20:11:46 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py        |  6 ++++++
 Allura/allura/tests/test_plugin.py | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/77f5ba28/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index ef9b4b1..29a3ee6 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -715,6 +715,8 @@ class ProjectRegistrationProvider(object):
         Returns True if one of the following is true:
             - phone verification is disabled
             - :param user: has 'admin' access to :param neighborhood:
+            - :param user: is has 'admin' access for some project, which belongs
+              to :param neighborhood:
             - phone is already verified for a :param user:
 
         Otherwise returns False.
@@ -723,6 +725,10 @@ class ProjectRegistrationProvider(object):
             return True
         if security.has_access(neighborhood, 'admin', user=user)():
             return True
+        admin_in = [p for p in user.my_projects_by_role_name('Admin')
+                    if p.neighborhood_id == neighborhood._id]
+        if len(admin_in) > 0:
+            return True
         return bool(user.get_tool_data('phone_verification', 'number_hash'))
 
     def verify_phone(self, user, number):

http://git-wip-us.apache.org/repos/asf/allura/blob/77f5ba28/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 9b7b2d1..74859cc 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -90,6 +90,7 @@ class TestProjectRegistrationProvider(object):
 class UserMock(object):
     def __init__(self):
         self.tool_data = {}
+        self._projects = []
 
     def get_tool_data(self, tool, key):
         return self.tool_data.get(tool, {}).get(key, None)
@@ -98,6 +99,12 @@ class UserMock(object):
         d = self.tool_data.setdefault(tool, {})
         d.update(kw)
 
+    def set_projects(self, projects):
+        self._projects = projects
+
+    def my_projects_by_role_name(self, role):
+        return self._projects
+
 
 class TestProjectRegistrationProviderPhoneVerification(object):
 
@@ -117,6 +124,15 @@ class TestProjectRegistrationProviderPhoneVerification(object):
             assert_true(self.p.phone_verified(self.user, self.nbhd))
 
     @patch.object(plugin.security, 'has_access', autospec=True)
+    def test_phone_verified_project_admin(self, has_access):
+        has_access.return_value.return_value = False
+        with h.push_config(tg.config, **{'project.verify_phone': 'true'}):
+            self.user.set_projects([Mock()])
+            assert_false(self.p.phone_verified(self.user, self.nbhd))
+            self.user.set_projects([Mock(neighborhood_id=self.nbhd._id)])
+            assert_true(self.p.phone_verified(self.user, self.nbhd))
+
+    @patch.object(plugin.security, 'has_access', autospec=True)
     def test_phone_verified(self, has_access):
         has_access.return_value.return_value = False
         with h.push_config(tg.config, **{'project.verify_phone': 'true'}):


Mime
View raw message