Rev 434: Merge fix for bug #569358. Redirect requests so people can URL hack. in http://bazaar.launchpad.net/~loggerhead-team/loggerhead/trunk-rich

John Arbash Meinel john at arbash-meinel.com
Tue Mar 15 10:24:59 UTC 2011


At http://bazaar.launchpad.net/~loggerhead-team/loggerhead/trunk-rich

------------------------------------------------------------
revno: 434 [merge]
revision-id: john at arbash-meinel.com-20110315102440-n4zr988738z125cd
parent: robertc at robertcollins.net-20110314090814-ks1w4rtlgdqdnshr
parent: jstpierre at mecheye.net-20110315061911-pwc4onpecjis8thf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk-rich
timestamp: Tue 2011-03-15 11:24:40 +0100
message:
  Merge fix for bug #569358. Redirect requests so people can URL hack.
  
  If you edit /files/directory to become /files/directory/filename, redirect it to
  the /view/directory/filename, and conversly if you go to /view/directory redirect
  it to /files/directory. This way people can edit the URL in a logical way
  and still get the view they are expecting.
modified:
  NEWS                           news-20070121024650-6cwmhprgtcegpxvm-1
  loggerhead/controllers/inventory_ui.py inventory_ui.py-20061212203332-s4vehyfs3tn6zm31-1
  loggerhead/controllers/view_ui.py annotate_ui.py-20061213025409-n0tuh5u7v7kwnmd5-1
  loggerhead/tests/test_controllers.py test_controllers.py-20090210051739-5d14nlvjvn2ep4x5-1
  loggerhead/tests/test_simple.py test_simple.py-20070523103003-hrxwg5n1hcebw7l6-1
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2011-03-04 15:49:43 +0000
+++ b/NEWS	2011-03-15 10:24:40 +0000
@@ -16,11 +16,15 @@
     - Merge the pqm changes back into trunk, after trunk was reverted to an old
       revision. (John Arbash Meinel, #716152)
 
+    - Remove ``start-loggerhead`` and ``stop-loggerhead`` which were already
+      deprecated. (John Arbash Meinel)
+
+    - Redirect ``/files/file.txt`` to ``/view/file.txt`` and ``/view/dir`` to
+      ``/files/dir``. (Jasper St. Pierre, #569358)
+
     - The json module is no longer claimed to be supported as alternative for 
       simplejson. (Jelmer Vernooij, #586611)
 
-    - Remove ``start-loggerhead`` and ``stop-loggerhead`` which were already
-      deprecated. (John Arbash Meinel)
 
 
 1.18 [10Nov2010]

=== modified file 'loggerhead/controllers/inventory_ui.py'
--- a/loggerhead/controllers/inventory_ui.py	2009-03-19 00:44:05 +0000
+++ b/loggerhead/controllers/inventory_ui.py	2011-03-12 17:15:08 +0000
@@ -22,7 +22,7 @@
 import posixpath
 import urllib
 
-from paste.httpexceptions import HTTPNotFound
+from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
 
 from bzrlib import errors
 from bzrlib.revision import is_null as is_null_rev
@@ -45,7 +45,7 @@
 
     template_path = 'loggerhead.templates.inventory'
 
-    def get_filelist(self, inv, path, sort_type):
+    def get_filelist(self, inv, path, sort_type, revno_url):
         """
         return the list of all files (and their attributes) within a given
         path subtree.
@@ -58,6 +58,9 @@
         dir_ie = inv[file_id]
         file_list = []
 
+        if dir_ie.kind != 'directory':
+            raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
+
         revid_set = set()
 
         for filename, entry in dir_ie.children.iteritems():
@@ -150,7 +153,7 @@
 
             # Create breadcrumb trail for the path within the branch
             branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
-            filelist = self.get_filelist(rev_tree.inventory, path, sort_type)
+            filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
         else:
             start_revid = None
             change = None

=== modified file 'loggerhead/controllers/view_ui.py'
--- a/loggerhead/controllers/view_ui.py	2010-12-01 08:30:02 +0000
+++ b/loggerhead/controllers/view_ui.py	2011-03-12 17:15:08 +0000
@@ -25,7 +25,7 @@
 import bzrlib.textfile
 import bzrlib.osutils
 
-from paste.httpexceptions import HTTPBadRequest, HTTPServerError
+from paste.httpexceptions import HTTPBadRequest, HTTPServerError, HTTPMovedPermanently
 
 from loggerhead.controllers import TemplatedBranchView
 try:
@@ -120,6 +120,9 @@
             raise HTTPServerError('Could not fetch changes')
         branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
 
+        if inv[file_id].kind == "directory":
+            raise HTTPMovedPermanently(self._branch.context_url(['/files', revno_url, path]))
+
         return {
             # In AnnotateUI, "annotated" is a generator giving revision
             # numbers per lines, but the template checks if "annotated" is

=== modified file 'loggerhead/tests/test_controllers.py'
--- a/loggerhead/tests/test_controllers.py	2011-02-10 17:01:10 +0000
+++ b/loggerhead/tests/test_controllers.py	2011-03-15 02:56:59 +0000
@@ -47,7 +47,7 @@
         bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(
             ['filename'])
         inv = bzrbranch.repository.get_inventory(bzrbranch.last_revision())
-        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename')))
+        self.assertEqual(1, len(inv_ui.get_filelist(inv, '', 'filename', 'head')))
 
     def test_smoke(self):
         bzrbranch, inv_ui = self.make_bzrbranch_and_inventory_ui_for_tree_shape(

=== modified file 'loggerhead/tests/test_simple.py'
--- a/loggerhead/tests/test_simple.py	2011-03-10 14:22:12 +0000
+++ b/loggerhead/tests/test_simple.py	2011-03-15 10:24:40 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007-2011 Canonical Ltd.
+# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@
 
 from loggerhead.apps.branch import BranchWSGIApp
 from paste.fixture import TestApp
-from paste.httpexceptions import HTTPExceptionHandler
+from paste.httpexceptions import HTTPExceptionHandler, HTTPMovedPermanently
 
 
 
@@ -170,6 +170,33 @@
         res = app.get('/changes', status=404)
 
 
+class TestControllerRedirects(BasicTests):
+    """
+    Test that a file under /files redirects to /view,
+    and a directory under /view redirects to /files.
+    """
+
+    def setUp(self):
+        BasicTests.setUp(self)
+        self.createBranch()
+        self.build_tree(('file', 'folder/', 'folder/file'))
+        self.tree.smart_add([])
+        self.tree.commit('')
+
+    def test_view_folder(self):
+        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
+
+        e = self.assertRaises(HTTPMovedPermanently, app.get, '/view/head:/folder')
+        self.assertEqual(e.location(), '/files/head:/folder')
+
+    def test_files_file(self):
+        app = TestApp(BranchWSGIApp(self.tree.branch, '').app)
+
+        e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/folder/file')
+        self.assertEqual(e.location(), '/view/head:/folder/file')
+        e = self.assertRaises(HTTPMovedPermanently, app.get, '/files/head:/file')
+        self.assertEqual(e.location(), '/view/head:/file')
+
 #class TestGlobalConfig(BasicTests):
 #    """
 #    Test that global config settings are respected



More information about the bazaar-commits mailing list