You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/03/29 16:24:28 UTC
[1/2] git commit: [#5971] don't re-query the Users nbhd every time we
look up a user-project
Updated Branches:
refs/heads/master 34729f5cc -> 53635e778
[#5971] don't re-query the Users nbhd every time we look up a user-project
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/53635e77
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/53635e77
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/53635e77
Branch: refs/heads/master
Commit: 53635e778f61d8a8a20f0205caa45eabdbe0d143
Parents: d7846b2
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Mar 28 19:12:50 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Mar 29 15:23:59 2013 +0000
----------------------------------------------------------------------
Allura/allura/model/auth.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/53635e77/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index ee9abec..5ccfd60 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -23,6 +23,7 @@ from ming.orm import session, state
from ming.orm import FieldProperty, RelationProperty, ForeignIdProperty
from ming.orm.declarative import MappedClass
from ming.orm.ormsession import ThreadLocalORMSession
+from ming.utils import LazyProperty
import allura.tasks.mail_tasks
from allura.lib import helpers as h
@@ -583,6 +584,11 @@ class User(MappedClass, ActivityNode, ActivityObject):
user=user, user_project=True)
return user
+ @LazyProperty
+ def neighborhood(self):
+ from allura import model as M
+ return M.Neighborhood.query.get(name='Users')
+
def private_project(self):
'''
Returns the personal user-project for the user
@@ -591,7 +597,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
return None
from allura import model as M
- n = M.Neighborhood.query.get(name='Users')
+ n = self.neighborhood
auth_provider = plugin.AuthenticationProvider.get(request)
project_shortname = auth_provider.user_project_shortname(self)
p = M.Project.query.get(shortname=project_shortname, neighborhood_id=n._id)
[2/2] git commit: [#5971] don't show or create user-projects for
disabled users
Posted by tv...@apache.org.
[#5971] don't show or create user-projects for disabled users
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/d7846b25
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/d7846b25
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/d7846b25
Branch: refs/heads/master
Commit: d7846b25df18c085792f64a42fbfb7ffab7366a5
Parents: 34729f5
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Mar 28 19:08:45 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Fri Mar 29 15:23:59 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/project.py | 7 ++++++-
Allura/allura/model/auth.py | 3 +++
.../allura/tests/functional/test_neighborhood.py | 7 +++++++
Allura/allura/tests/model/test_auth.py | 7 +++++++
4 files changed, 23 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7846b25/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index ebeba77..7a1551f 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -67,7 +67,7 @@ class NeighborhoodController(object):
project = M.Project.query.get(shortname=self.prefix + pname, neighborhood_id=self.neighborhood._id)
if project is None and self.prefix == 'u/':
# create user-project if it is missing
- user = M.User.query.get(username=pname)
+ user = M.User.query.get(username=pname, disabled=False)
if user:
project = self.neighborhood.register_project(
plugin.AuthenticationProvider.get(request).user_project_shortname(user),
@@ -77,6 +77,11 @@ class NeighborhoodController(object):
project = self.neighborhood.neighborhood_project
c.project = project
return ProjectController()._lookup(pname, *remainder)
+ if project and self.prefix == 'u/':
+ # make sure user-projects are associated with an enabled user
+ user = project.user_project_of
+ if not user or user.disabled:
+ raise exc.HTTPNotFound
if project.database_configured == False:
if remainder == ('user_icon',):
redirect(g.forge_static('images/user.png'))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7846b25/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 8df4a58..ee9abec 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -587,6 +587,9 @@ class User(MappedClass, ActivityNode, ActivityObject):
'''
Returns the personal user-project for the user
'''
+ if self.disabled:
+ return None
+
from allura import model as M
n = M.Neighborhood.query.get(name='Users')
auth_provider = plugin.AuthenticationProvider.get(request)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7846b25/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 9c86a67..815f557 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -813,6 +813,13 @@ class TestNeighborhood(TestController):
ThreadLocalORMSession.flush_all()
self.app.get('/u/donald-duck/')
+ def test_disabled_user_has_no_user_project(self):
+ user = M.User.register(dict(username='donald-duck'))
+ self.app.get('/u/donald-duck/') # assert it's there
+ M.User.query.update(dict(username='donald-duck'), {'$set': {'disabled': True}})
+ self.app.get('/u/donald-duck/', status=404)
+
+
def test_more_projects_link(self):
r = self.app.get('/adobe/adobe-1/admin/')
link = r.html.find('div', {'class':'neighborhood_title_link'}).find('a')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7846b25/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 8fd0b65..9e0ff48 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -104,6 +104,13 @@ def test_user_project_already_deleted_creates_on_demand():
assert M.Project.query.get(shortname='u/foobar123', deleted=False)
@with_setup(setUp)
+def test_user_project_does_not_create_on_demand_for_disabled_user():
+ u = M.User.register(dict(username='foobar123', disabled=True), make_project=False)
+ ThreadLocalORMSession.flush_all()
+ assert not u.private_project()
+ assert not M.Project.query.get(shortname='u/foobar123')
+
+@with_setup(setUp)
def test_project_role():
role = M.ProjectRole(project_id=c.project._id, name='test_role')
c.user.project_role().roles.append(role._id)