You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/02/13 16:05:42 UTC
[08/17] git commit: [#6677] ticket:512 refactored my_projects
[#6677] ticket:512 refactored my_projects
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/798e47bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/798e47bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/798e47bf
Branch: refs/heads/cj/7097
Commit: 798e47bfbd12c05893b782b90ea0c566d87ef335
Parents: 84c2b7c
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Mon Jan 27 13:32:09 2014 +0400
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed Feb 12 15:59:47 2014 +0000
----------------------------------------------------------------------
.../ext/user_profile/templates/user_index.html | 8 +++-----
Allura/allura/model/auth.py | 17 ++++++++++++++++-
Allura/allura/tests/model/test_auth.py | 5 +++--
ForgeTracker/forgetracker/tracker_main.py | 2 +-
4 files changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/798e47bf/Allura/allura/ext/user_profile/templates/user_index.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/user_profile/templates/user_index.html b/Allura/allura/ext/user_profile/templates/user_index.html
index e639b58..75425c9 100644
--- a/Allura/allura/ext/user_profile/templates/user_index.html
+++ b/Allura/allura/ext/user_profile/templates/user_index.html
@@ -40,11 +40,9 @@
<b>Projects</b>
<ul>
{% for p in user.my_projects() %}
- {% if h.has_access(p, 'read')() %}
- <li>
- <a class="project-name" href="{{p.url()}}">{{p.name}}</a>
- </li>
- {% endif %}
+ <li>
+ <a class="project-name" href="{{p.url()}}">{{p.name}}</a>
+ </li>
{% endfor %}
</ul>
</div>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/798e47bf/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 542b1f6..f9f73b6 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -743,7 +743,22 @@ class User(MappedClass, ActivityNode, ActivityObject):
def script_name(self):
return '/u/' + self.username + '/'
- def my_projects(self, role_name=None):
+ def my_projects(self):
+ if self.is_anonymous():
+ return
+ if not c.user:
+ c.user = self.anonymous()
+ user_roles = g.credentials.user_roles(user_id=c.user._id)
+ user_projects = [r['project_id'] for r in user_roles]
+
+ roles = g.credentials.user_roles(user_id=self._id)
+ projects = [r['project_id'] for r in roles]
+ from .project import Project
+ for p in Project.query.find({'_id': {'$in': projects}, 'deleted': False}):
+ if (p._id in user_projects) or h.has_access(p, 'read')():
+ yield p
+
+ def my_projects_by_role_name(self, role_name=None):
"""Return projects to which this user belongs.
If ``role_name`` is provided, return only projects for which user has
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/798e47bf/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 cb548da..5119f68 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -96,6 +96,7 @@ def test_user():
# delete one of the projects and make sure it won't appear in my_projects()
p = M.Project.query.get(shortname='test2')
p.deleted = True
+ ThreadLocalORMSession.flush_all()
assert_equal(set(p.shortname for p in c.user.my_projects()),
set(['test', 'u/test-admin', 'adobe-1', '--init--']))
u = M.User.register(dict(
@@ -237,7 +238,7 @@ def test_email_address_claimed_by_user():
def test_user_projects_by_role():
assert_equal(set(p.shortname for p in c.user.my_projects()),
set(['test', 'test2', 'u/test-admin', 'adobe-1', '--init--']))
- assert_equal(set(p.shortname for p in c.user.my_projects('Admin')),
+ assert_equal(set(p.shortname for p in c.user.my_projects_by_role_name('Admin')),
set(['test', 'test2', 'u/test-admin', 'adobe-1', '--init--']))
# Remove admin access from c.user to test2 project
project = M.Project.query.get(shortname='test2')
@@ -250,7 +251,7 @@ def test_user_projects_by_role():
g.credentials.clear()
assert_equal(set(p.shortname for p in c.user.my_projects()),
set(['test', 'test2', 'u/test-admin', 'adobe-1', '--init--']))
- assert_equal(set(p.shortname for p in c.user.my_projects('Admin')),
+ assert_equal(set(p.shortname for p in c.user.my_projects_by_role_name('Admin')),
set(['test', 'u/test-admin', 'adobe-1', '--init--']))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/798e47bf/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index f60df6d..193570d 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -148,7 +148,7 @@ def _my_trackers(user, current_tracker_app_config):
Returns list of 3-tuples (<tracker_id>, '<project>/<mount_point>', <is current tracker?>)
'''
trackers = []
- projects = user.my_projects('Admin')
+ projects = user.my_projects_by_role_name('Admin')
for p in projects:
for ac in p.app_configs:
if ac.tool_name.lower() == 'tickets':