You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/12/06 19:46:54 UTC

git commit: [#5428] resurrect user-project if needed

Updated Branches:
  refs/heads/db/5428 [created] 9a71d0dc6


[#5428] resurrect user-project if needed


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/9a71d0dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/9a71d0dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/9a71d0dc

Branch: refs/heads/db/5428
Commit: 9a71d0dc698974f2784658d8c2ee249945ccb260
Parents: c9c3489
Author: Dave Brondsema <db...@geek.net>
Authored: Thu Dec 6 18:46:39 2012 +0000
Committer: Dave Brondsema <db...@geek.net>
Committed: Thu Dec 6 18:46:39 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py            |    2 +-
 Allura/allura/model/auth.py            |    6 +++++-
 Allura/allura/tests/model/test_auth.py |   11 +++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a71d0dc/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 6067e27..dbd159e 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -427,7 +427,7 @@ class ProjectRegistrationProvider(object):
 
         p = M.Project.query.get(shortname=shortname, neighborhood_id=neighborhood._id)
         if p:
-            raise forge_exc.ProjectConflict()
+            raise forge_exc.ProjectConflict('%s already exists in nbhd %s' % (shortname, neighborhood._id))
 
     def _create_project(self, neighborhood, shortname, project_name, user, user_project, private_project, apps):
         '''

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a71d0dc/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 1493400..47f917f 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -585,12 +585,16 @@ class User(MappedClass, ActivityNode, ActivityObject):
         from .project import Project
         auth_provider = plugin.AuthenticationProvider.get(request)
         project_shortname = auth_provider.user_project_shortname(self)
-        p = Project.query.get(shortname=project_shortname, deleted=False)
+        p = Project.query.get(shortname=project_shortname)
         if not p and self != User.anonymous():
             # create user-project on demand if it is missing
             from allura import model as M
             n = M.Neighborhood.query.get(name='Users')
             p = n.register_project(project_shortname, user=self, user_project=True)
+        elif p and p.deleted:
+            # un-delete it, since registering a new project would conflict with the 'deleted' one
+            log.info('undeleting user project %s', project_shortname)
+            p.deleted = False
         return p
 
     @property

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9a71d0dc/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 46bdf97..191e382 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -93,6 +93,17 @@ def test_user_project_creates_on_demand():
     assert M.Project.query.get(shortname='u/foobar123')
 
 @with_setup(setUp)
+def test_user_project_already_deleted_creates_on_demand():
+    u = M.User.register(dict(username='foobar123'), make_project=True)
+    p = M.Project.query.get(shortname='u/foobar123')
+    p.deleted = True
+    ThreadLocalORMSession.flush_all()
+    assert not M.Project.query.get(shortname='u/foobar123', deleted=False)
+    assert u.private_project()
+    ThreadLocalORMSession.flush_all()
+    assert M.Project.query.get(shortname='u/foobar123', deleted=False)
+
+@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)