allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] git commit: [#5971] don't show or create user-projects for disabled users
Date Thu, 28 Mar 2013 19:17:54 GMT
Updated Branches:
  refs/heads/db/5971 [created] 56c54671b


[#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/9ea4b5de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/9ea4b5de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/9ea4b5de

Branch: refs/heads/db/5971
Commit: 9ea4b5de2d89b33cc26c2b067887b0ee137a4fb0
Parents: 6f44f8a
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Thu Mar 28 19:08:45 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Mar 28 19:08:45 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/9ea4b5de/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/9ea4b5de/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/9ea4b5de/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/9ea4b5de/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)


Mime
View raw message