Show More
@@ -16,6 +16,7 b' Authors:' | |||||
16 | # Imports |
|
16 | # Imports | |
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 |
|
18 | |||
|
19 | import os | |||
19 | from tornado import web |
|
20 | from tornado import web | |
20 | HTTPError = web.HTTPError |
|
21 | HTTPError = web.HTTPError | |
21 |
|
22 | |||
@@ -61,7 +62,18 b' class NotebookRedirectHandler(IPythonHandler):' | |||||
61 | url = url_path_join(self.base_project_url, 'tree', path) |
|
62 | url = url_path_join(self.base_project_url, 'tree', path) | |
62 | else: |
|
63 | else: | |
63 | # otherwise, redirect to /files |
|
64 | # otherwise, redirect to /files | |
64 | # TODO: This should check if it's actually a file |
|
65 | if '/files/' in path: | |
|
66 | # redirect without files/ iff it would 404 | |||
|
67 | # this preserves pre-2.0-style 'files/' links | |||
|
68 | # FIXME: this is hardcoded based on notebook_path, | |||
|
69 | # but so is the files handler itself, | |||
|
70 | # so it should work until both are cleaned up. | |||
|
71 | parts = path.split('/') | |||
|
72 | files_path = os.path.join(nbm.notebook_dir, *parts) | |||
|
73 | self.log.warn("filespath: %s", files_path) | |||
|
74 | if not os.path.exists(files_path): | |||
|
75 | path = path.replace('/files/', '/', 1) | |||
|
76 | ||||
65 | url = url_path_join(self.base_project_url, 'files', path) |
|
77 | url = url_path_join(self.base_project_url, 'files', path) | |
66 | url = url_escape(url) |
|
78 | url = url_escape(url) | |
67 | self.log.debug("Redirecting %s to %s", self.request.path, url) |
|
79 | self.log.debug("Redirecting %s to %s", self.request.path, url) |
@@ -17,11 +17,11 b' class FilesTest(NotebookTestBase):' | |||||
17 | def test_hidden_files(self): |
|
17 | def test_hidden_files(self): | |
18 | not_hidden = [ |
|
18 | not_hidden = [ | |
19 | u'Γ₯ b', |
|
19 | u'Γ₯ b', | |
20 |
|
|
20 | u'Γ₯ b/Γ§. d', | |
21 | ] |
|
21 | ] | |
22 | hidden = [ |
|
22 | hidden = [ | |
23 | u'.Γ₯ b', |
|
23 | u'.Γ₯ b', | |
24 |
|
|
24 | u'Γ₯ b/.Γ§ d', | |
25 | ] |
|
25 | ] | |
26 | dirs = not_hidden + hidden |
|
26 | dirs = not_hidden + hidden | |
27 |
|
27 | |||
@@ -40,7 +40,7 b' class FilesTest(NotebookTestBase):' | |||||
40 | path = pjoin(nbdir, d.replace('/', os.sep)) |
|
40 | path = pjoin(nbdir, d.replace('/', os.sep)) | |
41 | r = requests.get(url_path_join(url, 'files', d, 'foo')) |
|
41 | r = requests.get(url_path_join(url, 'files', d, 'foo')) | |
42 | r.raise_for_status() |
|
42 | r.raise_for_status() | |
43 |
self.assertEqual(r. |
|
43 | self.assertEqual(r.text, 'foo') | |
44 | r = requests.get(url_path_join(url, 'files', d, '.foo')) |
|
44 | r = requests.get(url_path_join(url, 'files', d, '.foo')) | |
45 | self.assertEqual(r.status_code, 403) |
|
45 | self.assertEqual(r.status_code, 403) | |
46 |
|
46 | |||
@@ -49,3 +49,37 b' class FilesTest(NotebookTestBase):' | |||||
49 | for foo in ('foo', '.foo'): |
|
49 | for foo in ('foo', '.foo'): | |
50 | r = requests.get(url_path_join(url, 'files', d, foo)) |
|
50 | r = requests.get(url_path_join(url, 'files', d, foo)) | |
51 | self.assertEqual(r.status_code, 403) |
|
51 | self.assertEqual(r.status_code, 403) | |
|
52 | ||||
|
53 | def test_old_files_redirect(self): | |||
|
54 | """pre-2.0 'files/' prefixed links are properly redirected""" | |||
|
55 | nbdir = self.notebook_dir.name | |||
|
56 | base = self.base_url() | |||
|
57 | ||||
|
58 | os.mkdir(pjoin(nbdir, 'files')) | |||
|
59 | os.makedirs(pjoin(nbdir, 'sub', 'files')) | |||
|
60 | ||||
|
61 | for prefix in ('', 'sub'): | |||
|
62 | with open(pjoin(nbdir, prefix, 'files', 'f1.txt'), 'w') as f: | |||
|
63 | f.write(prefix + '/files/f1') | |||
|
64 | with open(pjoin(nbdir, prefix, 'files', 'f2.txt'), 'w') as f: | |||
|
65 | f.write(prefix + '/files/f2') | |||
|
66 | with open(pjoin(nbdir, prefix, 'f2.txt'), 'w') as f: | |||
|
67 | f.write(prefix + '/f2') | |||
|
68 | with open(pjoin(nbdir, prefix, 'f3.txt'), 'w') as f: | |||
|
69 | f.write(prefix + '/f3') | |||
|
70 | ||||
|
71 | url = url_path_join(base, 'notebooks', prefix, 'files', 'f1.txt') | |||
|
72 | r = requests.get(url) | |||
|
73 | self.assertEqual(r.status_code, 200) | |||
|
74 | self.assertEqual(r.text, prefix + '/files/f1') | |||
|
75 | ||||
|
76 | url = url_path_join(base, 'notebooks', prefix, 'files', 'f2.txt') | |||
|
77 | r = requests.get(url) | |||
|
78 | self.assertEqual(r.status_code, 200) | |||
|
79 | self.assertEqual(r.text, prefix + '/files/f2') | |||
|
80 | ||||
|
81 | url = url_path_join(base, 'notebooks', prefix, 'files', 'f3.txt') | |||
|
82 | r = requests.get(url) | |||
|
83 | self.assertEqual(r.status_code, 200) | |||
|
84 | self.assertEqual(r.text, prefix + '/f3') | |||
|
85 |
General Comments 0
You need to be logged in to leave comments.
Login now