Merge lp:~ilasc/loggerhead/fix-download-links into lp:loggerhead

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 536
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~ilasc/loggerhead/fix-download-links
Merge into: lp:loggerhead
Diff against target: 101 lines (+45/-5)
5 files modified
loggerhead/controllers/download_ui.py (+1/-1)
loggerhead/templates/inventory.pt (+2/-2)
loggerhead/tests/fixtures.py (+2/-2)
loggerhead/tests/test_controllers.py (+9/-0)
loggerhead/tests/test_inventory_ui.py (+31/-0)
To merge this branch: bzr merge lp:~ilasc/loggerhead/fix-download-links
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Jelmer Vernooij Approve
Review via email: mp+429230@code.launchpad.net

Commit message

Fix file download links in inventory UI

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

I think this is reasonable - it matches the URL structure used by some other similar controllers, e.g. view.

review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/controllers/download_ui.py'
2--- loggerhead/controllers/download_ui.py 2022-08-29 16:33:16 +0000
3+++ loggerhead/controllers/download_ui.py 2022-08-31 14:08:49 +0000
4@@ -62,7 +62,7 @@
5 self._branch.absolute_url('/changes'))
6 revid = h.fix_revid(args[0])
7 try:
8- path, filename, content = h.get_file(args[1], revid)
9+ path, filename, content = h.get_file("/".join(args[1:]), revid)
10 except (NoSuchFile, NoSuchRevision):
11 raise httpexceptions.HTTPNotFound()
12 mime_type, encoding = mimetypes.guess_type(filename)
13
14=== modified file 'loggerhead/templates/inventory.pt'
15--- loggerhead/templates/inventory.pt 2022-08-08 16:33:50 +0000
16+++ loggerhead/templates/inventory.pt 2022-08-31 14:08:49 +0000
17@@ -157,8 +157,8 @@
18 </a>
19 </td>
20 <td class="expcell">
21- <a tal:attributes="href python:url(['/download', file.revid.decode('utf-8'), file.filename]);
22- title string:Download ${file.filename} at revision ${file.change.revno}">
23+ <a tal:attributes="href python:url(['/download', file.revid.decode('utf-8'), file.absolutepath]);
24+ title string:Download ${file.absolutepath} at revision ${file.change.revno}">
25 <img tal:attributes="src python:branch.static_url('/static/images/ico_file_download.gif')" alt="Download File" />
26 </a>
27 </td>
28
29=== modified file 'loggerhead/tests/fixtures.py'
30--- loggerhead/tests/fixtures.py 2022-07-06 12:45:28 +0000
31+++ loggerhead/tests/fixtures.py 2022-08-31 14:08:49 +0000
32@@ -33,10 +33,10 @@
33 self.filecontents = (
34 'some\nmultiline\ndata\n'
35 'with<htmlspecialchars\n')
36- filenames = ['myfilename', 'anotherfile<']
37+ filenames = ['myfilename', 'anotherfile<', 'folder/', 'folder/myfilename']
38 self.testcase.build_tree_contents(
39 (filename, self.filecontents) for filename in filenames)
40 self.tree.add(filenames)
41 self.path = 'myfilename'
42 self.msg = 'a very exciting commit message <'
43- self.revid = self.tree.commit(message=self.msg)
44+ self.revid = self.tree.commit(message=self.msg, rev_id=b'rev-1')
45
46=== modified file 'loggerhead/tests/test_controllers.py'
47--- loggerhead/tests/test_controllers.py 2022-08-08 16:33:50 +0000
48+++ loggerhead/tests/test_controllers.py 2022-08-31 14:08:49 +0000
49@@ -459,6 +459,15 @@
50 app.get, '/download/1/notmyfilename')
51 self.assertContainsRe(str(e), '404 Not Found')
52
53+ def test_download_from_subdirectory(self):
54+ app = self.setUpLoggerhead()
55+ response = app.get('/download/1/folder/myfilename')
56+ self.assertEqual(
57+ b'some\nmultiline\ndata\nwith<htmlspecialchars\n', response.body)
58+ self.assertThat(
59+ response,
60+ MatchesDownloadHeaders('myfilename', 'application/octet-stream'))
61+
62
63 class IsTarfile(Matcher):
64
65
66=== added file 'loggerhead/tests/test_inventory_ui.py'
67--- loggerhead/tests/test_inventory_ui.py 1970-01-01 00:00:00 +0000
68+++ loggerhead/tests/test_inventory_ui.py 2022-08-31 14:08:49 +0000
69@@ -0,0 +1,31 @@
70+# Copyright (C) 2022 Canonical Ltd.
71+#
72+# This program is free software; you can redistribute it and/or modify
73+# it under the terms of the GNU General Public License as published by
74+# the Free Software Foundation; either version 2 of the License, or
75+# (at your option) any later version.
76+#
77+# This program is distributed in the hope that it will be useful,
78+# but WITHOUT ANY WARRANTY; without even the implied warranty of
79+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80+# GNU General Public License for more details.
81+#
82+# You should have received a copy of the GNU General Public License
83+# along with this program; if not, write to the Free Software
84+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
85+#
86+
87+from .test_simple import TestWithSimpleTree
88+
89+
90+class TestInventoryUI(TestWithSimpleTree):
91+
92+ def test_authors_vs_committer(self):
93+ app = self.setUpLoggerhead()
94+ res = app.get('/files')
95+ # download url in top directory is composed correctly
96+ res.mustcontain('/download/rev-1/myfilename')
97+
98+ res2 = app.get('/files/head:/folder')
99+ # download url in subdirectory is composed correctly
100+ res2.mustcontain('/download/rev-1/folder/myfilename')
101\ No newline at end of file

Subscribers

People subscribed via source and target branches