backoffice: add redirects for all /form-url-name/ legacy URLs (#7812)

This commit is contained in:
Frédéric Péters 2015-07-09 16:00:37 +02:00
parent 06d4796274
commit cd92204ff2
2 changed files with 23 additions and 4 deletions

View File

@ -211,6 +211,19 @@ def test_backoffice_listing(pub):
else:
assert resp.body.count('data-link') == 33
def test_backoffice_legacy_urls(pub):
create_superuser(pub)
create_environment(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/form-title/')
assert resp.location == 'http://example.net/backoffice/management/form-title/'
resp = app.get('/backoffice/form-title/1/')
assert resp.location == 'http://example.net/backoffice/management/form-title/1/'
resp = app.get('/backoffice/form-title/listing/?bla')
assert resp.location == 'http://example.net/backoffice/management/form-title/listing/?bla'
resp = app.get('/backoffice/form-title/listing/foo?bla')
assert resp.location == 'http://example.net/backoffice/management/form-title/listing/foo?bla'
def test_backoffice_columns(pub):
create_superuser(pub)
create_environment(pub)

View File

@ -68,6 +68,16 @@ class RootDirectory(BackofficeRootDirectory):
]
def _q_traverse(self, path):
if not hasattr(self, self._q_translate(path[0]) or path[0]):
try:
# keep compatibility with previous versions, redirect from
# legacy URL to new ones under management/
FormDef.get_by_urlname(path[0], ignore_migration=True)
url = get_request().get_path_query()
url = url.replace('/backoffice/', '/backoffice/management/', 1)
return redirect(url)
except KeyError:
pass
get_response().add_javascript(['jquery.js', 'gadjo.sidepage.js'])
return super(RootDirectory, self)._q_traverse(path)
@ -228,10 +238,6 @@ class RootDirectory(BackofficeRootDirectory):
if not self.is_accessible(component):
raise errors.AccessForbiddenError()
return getattr(self, component)
if FormDef.has_key(component):
# keep compatibility with previous versions, redirect from legacy
# URL to new ones under management/
return redirect('management/%s/' % component)
return super(RootDirectory, self)._q_lookup(component)
def get_menu_items(self):