Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C501BD41C for ; Thu, 6 Dec 2012 19:36:18 +0000 (UTC) Received: (qmail 96842 invoked by uid 500); 6 Dec 2012 19:36:18 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 96826 invoked by uid 500); 6 Dec 2012 19:36:18 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 96817 invoked by uid 99); 6 Dec 2012 19:36:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Dec 2012 19:36:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 6EE1F81CB58; Thu, 6 Dec 2012 19:36:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: git commit: [#5428] really delete user-project if it exists and is flagged as deleted Message-Id: <20121206193618.6EE1F81CB58@tyr.zones.apache.org> Date: Thu, 6 Dec 2012 19:36:18 +0000 (UTC) Updated Branches: refs/heads/master c9c348915 -> b5d5fa3bf [#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/master Commit: b5d5fa3bf16e3c43c4941ea238359ab1c2cb4ddc Parents: c9c3489 Author: Dave Brondsema Authored: Thu Dec 6 18:46:39 2012 +0000 Committer: Dave Brondsema 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)