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/12 17:00:01 UTC
[1/3] git commit: [#6677] ticket:532 Require role_name
Updated Branches:
refs/heads/master 84c2b7c5c -> 4201b080c
[#6677] ticket:532 Require role_name
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/4201b080
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4201b080
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4201b080
Branch: refs/heads/master
Commit: 4201b080c81dc5a0dee5a41a8f61c35f9eb6a9fe
Parents: 70f0bf3
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Feb 11 16:13:24 2014 +0200
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed Feb 12 15:59:47 2014 +0000
----------------------------------------------------------------------
Allura/allura/model/auth.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4201b080/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index fefc2c5..dfbfc32 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -751,7 +751,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
from .project import Project
return Project.query.find({'_id': {'$in': projects}, 'deleted': False})
- def my_projects_by_role_name(self, role_name=None):
+ def my_projects_by_role_name(self, role_name):
"""
Return only projects for which user has
that role.
[3/3] git commit: [#6677] ticket:512 refactored my_projects
Posted by jo...@apache.org.
[#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/master
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':
[2/3] git commit: [#6677] ticket:532 return has_access and pull
projects in one query
Posted by jo...@apache.org.
[#6677] ticket:532 return has_access and pull projects in one query
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/70f0bf35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/70f0bf35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/70f0bf35
Branch: refs/heads/master
Commit: 70f0bf35a327a8be18b733252a389efd2ed9992e
Parents: 798e47b
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Thu Feb 6 00:00:59 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 | 32 +++++---------------
2 files changed, 12 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/70f0bf35/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 75425c9..77d8028 100644
--- a/Allura/allura/ext/user_profile/templates/user_index.html
+++ b/Allura/allura/ext/user_profile/templates/user_index.html
@@ -40,9 +40,11 @@
<b>Projects</b>
<ul>
{% for p in user.my_projects() %}
- <li>
- <a class="project-name" href="{{p.url()}}">{{p.name}}</a>
- </li>
+ {% if (c.user == user) or h.has_access(p, 'read') %}
+ <li>
+ <a class="project-name" href="{{p.url()}}">{{p.name}}</a>
+ </li>
+ {% endif %}
{% endfor %}
</ul>
</div>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/70f0bf35/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index f9f73b6..fefc2c5 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -746,43 +746,25 @@ class User(MappedClass, ActivityNode, ActivityObject):
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
+ return Project.query.find({'_id': {'$in': projects}, 'deleted': False})
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
+ """
+ Return only projects for which user has
that role.
-
"""
if self.is_anonymous():
return
reaching_role_ids = list(
g.credentials.user_roles(user_id=self._id).reaching_ids_set)
reaching_roles = ProjectRole.query.find(
- {'_id': {'$in': reaching_role_ids}}).all()
- if not role_name:
- named_roles = [r for r in reaching_roles
- if r.name and r.project and not r.project.deleted]
- else:
- named_roles = [r for r in reaching_roles
- if r.name == role_name and r.project and not r.project.deleted]
- seen_project_ids = set()
- for r in named_roles:
- if r.project_id in seen_project_ids:
- continue
- seen_project_ids.add(r.project_id)
- yield r.project
+ {'_id': {'$in': reaching_role_ids}, 'name': role_name})
+ projects = [r['project_id'] for r in reaching_roles]
+ from .project import Project
+ return Project.query.find({'_id': {'$in': projects}, 'deleted': False})
def set_password(self, new_password):
return plugin.AuthenticationProvider.get(request).set_password(