allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [4/4] allura git commit: [#7816] use User object for status checks (solr record could be old one before pending status introduced)
Date Thu, 15 Jan 2015 18:29:40 GMT
[#7816] use User object for status checks (solr record could be old one before pending status
introduced)


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

Branch: refs/heads/master
Commit: 32ae5ff6f1d9462ab5f8152f3feb914ff6fd7037
Parents: 4a5275c
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Wed Jan 14 17:02:52 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Jan 14 17:02:52 2015 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py |  2 +-
 Allura/allura/lib/helpers.py            | 11 +++--------
 Allura/allura/tests/test_helpers.py     | 12 +++++-------
 3 files changed, 9 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/32ae5ff6/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index d284113..f150370 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -325,7 +325,7 @@ class SiteAdminController(object):
         fields = [('username', 'username'), ('display_name', 'display name')]
         add_fields = aslist(tg.config.get('search.user.additional_search_fields'), ',')
         r = self._search(M.User, fields, add_fields, q, f, page, limit, **kw)
-        r['objects'] = [dict(u, status=h.get_user_status(u)) for u in r['objects']]
+        r['objects'] = [dict(u, status=h.get_user_status(u['object'])) for u in r['objects']]
         r['search_results_template'] = 'allura:templates/site_admin_search_users_results.html'
         r['additional_display_fields'] = \
             aslist(tg.config.get('search.user.additional_display_fields'), ',')

http://git-wip-us.apache.org/repos/asf/allura/blob/32ae5ff6/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index ad238e3..3cd14fb 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1214,15 +1214,10 @@ def get_user_status(user):
     '''
     Get user status based on disabled and pending attrs
 
-    :param user: a dict or :class:`allura.model.auth.User`
+    :param user: a :class:`allura.model.auth.User`
     '''
-    from allura import model as M
-    if isinstance(user, M.User):
-        disabled = user.disabled
-        pending = user.pending
-    else:
-        disabled = user['disabled']
-        pending = user['pending']
+    disabled = user.disabled
+    pending = user.pending
 
     if not disabled and not pending:
         return 'enabled'

http://git-wip-us.apache.org/repos/asf/allura/blob/32ae5ff6/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 780f21c..49032eb 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -551,16 +551,14 @@ class TestIterEntryPoints(TestCase):
                                 list, h.iter_entry_points('allura'))
 
 def test_get_user_status():
-    user = {'pending': False, 'disabled': False}
+    user = M.User.by_username('test-admin')
     assert_equals(h.get_user_status(user), 'enabled')
 
-    user = {'pending': True, 'disabled': True}
-    assert_equals(h.get_user_status(user), 'disabled')
-    user = {'pending': False, 'disabled': True}
+    user = Mock(disabled=True, pending=False)
     assert_equals(h.get_user_status(user), 'disabled')
 
-    user = {'pending': True, 'disabled': False}
+    user = Mock(disabled=False, pending=True)
     assert_equals(h.get_user_status(user), 'pending')
 
-    user = M.User.by_username('test-admin')
-    assert_equals(h.get_user_status(user), 'enabled')
+    user = Mock(disabled=True, pending=True)  # not an expected combination
+    assert_equals(h.get_user_status(user), 'disabled')


Mime
View raw message