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 2012/12/07 17:11:48 UTC
[11/21] git commit: [#5428] really delete user-project if it exists
and is flagged as deleted
[#5428] really delete user-project if it exists and is flagged as deleted
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/b5d5fa3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b5d5fa3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b5d5fa3b
Branch: refs/heads/cj/4691
Commit: b5d5fa3bf16e3c43c4941ea238359ab1c2cb4ddc
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 19:31:17 2012 +0000
----------------------------------------------------------------------
Allura/allura/lib/plugin.py | 2 +-
Allura/allura/model/auth.py | 15 ++++++++++-----
Allura/allura/tests/model/test_auth.py | 11 +++++++++++
3 files changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b5d5fa3b/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/b5d5fa3b/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 1493400..b9b11d5 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -5,7 +5,6 @@ import logging
import urllib
import hmac
import hashlib
-import pytz
from urlparse import urlparse
from email import header
from hashlib import sha256
@@ -22,6 +21,7 @@ from ming import Field, collection
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
import allura.tasks.mail_tasks
from allura.lib import helpers as h
@@ -582,14 +582,19 @@ class User(MappedClass, ActivityNode, ActivityObject):
'''
Returns the personal user-project for the user
'''
- from .project import Project
+ from allura import model as M
+ n = M.Neighborhood.query.get(name='Users')
auth_provider = plugin.AuthenticationProvider.get(request)
project_shortname = auth_provider.user_project_shortname(self)
- p = Project.query.get(shortname=project_shortname, deleted=False)
+ p = M.Project.query.get(shortname=project_shortname, neighborhood_id=n._id)
+ if p and p.deleted:
+ # really delete it, since registering a new project would conflict with the "deleted" one
+ log.info('completely deleting user project (was already flagged as deleted) %s', project_shortname)
+ p.delete()
+ ThreadLocalORMSession.flush_all()
+ p = None
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)
return p
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b5d5fa3b/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)