Return-Path: X-Original-To: apmail-allura-commits-archive@www.apache.org Delivered-To: apmail-allura-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8380A18BE3 for ; Tue, 19 Jan 2016 21:44:57 +0000 (UTC) Received: (qmail 71930 invoked by uid 500); 19 Jan 2016 21:44:57 -0000 Delivered-To: apmail-allura-commits-archive@allura.apache.org Received: (qmail 71909 invoked by uid 500); 19 Jan 2016 21:44:57 -0000 Mailing-List: contact commits-help@allura.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@allura.apache.org Delivered-To: mailing list commits@allura.apache.org Received: (qmail 71888 invoked by uid 99); 19 Jan 2016 21:44:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2016 21:44:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 319AEDFCB5; Tue, 19 Jan 2016 21:44:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: heiths@apache.org To: commits@allura.apache.org Date: Tue, 19 Jan 2016 21:44:57 -0000 Message-Id: <7e6d99886b754888aeaa9746f26ab33d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] allura git commit: When /u/someuser/ needs to redirect, make sure it preserves /rest/ and any trailing URL parts Repository: allura Updated Branches: refs/heads/master b07e55f87 -> 607bea2bc When /u/someuser/ needs to redirect, make sure it preserves /rest/ and any trailing URL parts Project: http://git-wip-us.apache.org/repos/asf/allura/repo Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/3f7c7138 Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/3f7c7138 Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/3f7c7138 Branch: refs/heads/master Commit: 3f7c7138ef7895a4c1f3d18e2d2665f9639fb56f Parents: 7c93162 Author: Dave Brondsema Authored: Fri Jan 15 16:43:44 2016 -0500 Committer: Dave Brondsema Committed: Fri Jan 15 16:43:44 2016 -0500 ---------------------------------------------------------------------- Allura/allura/controllers/project.py | 2 +- Allura/allura/controllers/rest.py | 13 ++++++++++--- Allura/allura/tests/functional/test_user_profile.py | 11 ++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/allura/blob/3f7c7138/Allura/allura/controllers/project.py ---------------------------------------------------------------------- diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py index 96bfd0d..1742372 100644 --- a/Allura/allura/controllers/project.py +++ b/Allura/allura/controllers/project.py @@ -89,7 +89,7 @@ class NeighborhoodController(object): @expose() def _lookup(self, pname, *remainder): - c.project, remainder = nbhd_lookup_first_path(self.neighborhood, pname, c.user, *remainder) + c.project, remainder = nbhd_lookup_first_path(self.neighborhood, pname, c.user, remainder) return ProjectController(), remainder @expose('jinja:allura:templates/neighborhood_project_list.html') http://git-wip-us.apache.org/repos/asf/allura/blob/3f7c7138/Allura/allura/controllers/rest.py ---------------------------------------------------------------------- diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py index e59087c..a8a98fd 100644 --- a/Allura/allura/controllers/rest.py +++ b/Allura/allura/controllers/rest.py @@ -273,7 +273,7 @@ class AppRestControllerMixin(object): return rest_has_access(c.app, user, perm) -def nbhd_lookup_first_path(nbhd, name, current_user, *remainder): +def nbhd_lookup_first_path(nbhd, name, current_user, remainder, api=False): """ Resolve first part of a neighborhood url. May raise 404, redirect, or do other side effects. @@ -283,6 +283,7 @@ def nbhd_lookup_first_path(nbhd, name, current_user, *remainder): :param name: project or tool name (next part of url) :param current_user: a User :param remainder: remainder of url + :param bool api: whether this is handling a /rest/ request or not :return: project (to be set as c.project) :return: remainder (possibly modified) @@ -305,7 +306,13 @@ def nbhd_lookup_first_path(nbhd, name, current_user, *remainder): if project.shortname != 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()) + new_url = project.url() + if api: + new_url = '/rest' + new_url + new_url += '/'.join(remainder) + if request.query_string: + new_url += '?' + request.query_string + redirect(new_url) if project is None: # look for neighborhood tools matching the URL project = nbhd.neighborhood_project @@ -341,7 +348,7 @@ class NeighborhoodRestController(object): def _lookup(self, name=None, *remainder): if not name: raise exc.HTTPNotFound - c.project, remainder = nbhd_lookup_first_path(self._neighborhood, name, c.user, *remainder) + c.project, remainder = nbhd_lookup_first_path(self._neighborhood, name, c.user, remainder, api=True) return ProjectRestController(), remainder http://git-wip-us.apache.org/repos/asf/allura/blob/3f7c7138/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 14c28bf..d3c502d 100644 --- a/Allura/allura/tests/functional/test_user_profile.py +++ b/Allura/allura/tests/functional/test_user_profile.py @@ -57,8 +57,10 @@ class TestUserProfile(TestController): 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) + response = self.app.get('/u/foo_bar/', status=302) assert_equal(response.location, 'http://localhost/u/foo-bar/') + response = self.app.get('/u/foo_bar/profile/xyz?a=b', status=302) + assert_equal(response.location, 'http://localhost/u/foo-bar/profile/xyz?a=b') # 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) @@ -66,6 +68,13 @@ class TestUserProfile(TestController): # user_project_shortname() and user_by_project_shortname() #self.app.get('/u/foo-bar/profile/') + def test_differing_profile_proj_shortname_rest_api(self): + User.upsert('foo_bar') + + # default auth provider's user_project_shortname() converts _ to - for the project name + response = self.app.get('/rest/u/foo_bar/', status=302) + assert_equal(response.location, 'http://localhost/rest/u/foo-bar/') + @td.with_user_project('test-admin') @td.with_wiki def test_feed(self):