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 2015/07/09 21:22:00 UTC

allura git commit: [#7916] better handling of user-projects that have different names than the usernames

Repository: allura
Updated Branches:
  refs/heads/db/7916 [created] 98ca4f010


[#7916] better handling of user-projects that have different names than the usernames


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

Branch: refs/heads/db/7916
Commit: 98ca4f0101035322a68b582ec6d17a89085d75e6
Parents: 93a1ecc
Author: Dave Brondsema <da...@brondsema.net>
Authored: Thu Jul 9 15:21:48 2015 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Thu Jul 9 15:21:48 2015 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/project.py                |  9 +++++----
 Allura/allura/tests/functional/test_user_profile.py | 13 +++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/98ca4f01/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 195115f..4526e62 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -105,10 +105,11 @@ class NeighborhoodController(object):
             # create user-project if it is missing
             user = M.User.query.get(username=pname, disabled=False, pending=False)
             if user:
-                project = self.neighborhood.register_project(
-                    plugin.AuthenticationProvider.get(
-                        request).user_project_shortname(user),
-                    user=user, user_project=True)
+                project = user.private_project()
+                if project.shortname != self.prefix + pname:
+                    # might be different URL than the URL requested
+                    # e.g. if username isn't valid project name and user_project_shortname() converts the name
+                    redirect(project.url())
         if project is None:
             # look for neighborhood tools matching the URL
             project = self.neighborhood.neighborhood_project

http://git-wip-us.apache.org/repos/asf/allura/blob/98ca4f01/Allura/allura/tests/functional/test_user_profile.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index ffdde56..4425ace 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -53,6 +53,19 @@ class TestUserProfile(TestController):
         assert p is not None and p.is_user_project
         response = self.app.get('/u/test-user/profile/', status=404)
 
+    def test_differing_profile_proj_shortname(self):
+        User.upsert('foo_bar')
+
+        # default auth provider's user_project_shortname() converts _ to - for the project name
+        response = self.app.get('/u/foo_bar/profile/', status=302)
+        assert_equal(response.location, 'http://localhost/u/foo-bar/')
+
+        # unfortunately this doesn't work because the default auth provider's user_by_project_shortname()
+        # doesn't try converting back (and it probably shouldn't since you could get multiple users with conflicting proj names)
+        # at least this works with other auth providers that have a more complete implementation of both
+        # user_project_shortname() and user_by_project_shortname()
+        #self.app.get('/u/foo-bar/profile/')
+
     @td.with_user_project('test-admin')
     @td.with_wiki
     def test_feed(self):