This is an automated email from the ASF dual-hosted git repository. kentontaylor pushed a commit to branch kt/8462 in repository https://gitbox.apache.org/repos/asf/allura.git
commit d678f5b872c1b652fe931a5959bae8856332a3d7 Author: Kenton Taylor <[email protected]> AuthorDate: Fri Sep 9 13:21:04 2022 +0000 [#8462] Redirect any missing tools as 301 instead of 404 --- Allura/allura/controllers/project.py | 9 +++++---- Allura/allura/tests/functional/test_neighborhood.py | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py index 153bd347b..6b195ebd3 100644 --- a/Allura/allura/controllers/project.py +++ b/Allura/allura/controllers/project.py @@ -364,7 +364,9 @@ class ProjectController(FeedController): c.project = subproject c.app = None return ProjectController(), remainder - raise exc.HTTPNotFound(name) + + # if a tool doesn't exist, redirect to the first valid tool instead of 404 + self.index() @expose('jinja:allura:templates/members.html') @with_trailing_slash @@ -399,11 +401,10 @@ class ProjectController(FeedController): if mount is not None: if hasattr(app, 'default_redirect'): app.default_redirect() - # 301 redirect for user profiles only - args = dict(redirect_with=exc.HTTPMovedPermanently) if isinstance(app, UserProfileApp) else dict() + args = dict(redirect_with=exc.HTTPMovedPermanently) redirect(app.url() if callable(app.url) else app.url, **args) # Application has property; Subproject has method else: - redirect(c.project.app_configs[0].url()) + redirect(c.project.app_configs[0].url(), redirect_with=exc.HTTPMovedPermanently) def get_feed(self, project, app, user): """Return a :class:`allura.controllers.feed.FeedArgs` object describing diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py index a60820621..162377da8 100644 --- a/Allura/allura/tests/functional/test_neighborhood.py +++ b/Allura/allura/tests/functional/test_neighborhood.py @@ -861,12 +861,12 @@ class TestNeighborhood(TestController): def test_neighborhood_project(self): self.app.get('/adobe/adobe-1/admin/', status=200) self.app.get('/p/test/sub1/wiki/') - self.app.get('/p/test/sub1/', status=302) - self.app.get('/p/test/no-such-app/', status=404) + self.app.get('/p/test/sub1/', status=301) + self.app.get('/p/test/no-such-app/', status=301) def test_neighborhood_namespace(self): # p/test exists, so try creating adobe/test - self.app.get('/adobe/test/wiki/', status=404) + self.app.get('/adobe/test/wiki/', status=301) r = self.app.post('/adobe/register', params=dict( project_unixname='test', project_name='Test again', @@ -984,7 +984,7 @@ class TestPhoneVerificationOnProjectRegistration(TestController): def test_verify_phone_no_params(self): with h.push_config(config, **{'project.verify_phone': 'true'}): - self.app.get('/p/verify_phone', status=404) + self.app.get('/p/verify_phone', status=301) def test_verify_phone_error(self): with h.push_config(config, **{'project.verify_phone': 'true'}): @@ -1039,7 +1039,7 @@ class TestPhoneVerificationOnProjectRegistration(TestController): def test_check_phone_verification_no_params(self): with h.push_config(config, **{'project.verify_phone': 'true'}): - self.app.get('/p/check_phone_verification', status=404) + self.app.get('/p/check_phone_verification', status=301) @patch.object(g, 'phone_service', autospec=True) def test_check_phone_verification_error(self, phone_service):
