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:02 UTC
[2/3] git commit: [#6677] ticket:532 return has_access and pull
projects in one query
[#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(