Browse Source

HUE-1023 [fb] Access content of directories with conflicting URL names

Directories named stat, display, download... could not be accessed because
of URL conflicts
Add test
Romain Rigaux 13 years ago
parent
commit
4bdaf9862a

+ 6 - 6
apps/filebrowser/src/filebrowser/templates/chooser.mako

@@ -13,12 +13,12 @@
 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
-<%namespace name="dir" file="listdir_components.mako" />
 
-      <div class="fb-actions" data-filters="ArtButtonBar">
-        <a class="fb-upload" data-filters="ArtButton" data-icon-styles="{'width': 16, 'height' : 16}" href="${url('filebrowser.views.upload')}?dest=${path|u}&next=${current_request_path|u}">Upload Files</a>
-        <a class="fb-mkdir" data-filters="ArtButton" data-icon-styles="{'width': 16, 'height': 16}" href="${url('filebrowser.views.mkdir')}?path=${path|u}&next=${current_request_path|u}">New Directory</a>
-      </div>
+<%namespace name="dir" file="listdir_components.mako" />
 
-    ${dir.list_table_chooser(files, path_enc, current_request_path)}
+<div class="fb-actions" data-filters="ArtButtonBar">
+  <a class="fb-upload" data-filters="ArtButton" data-icon-styles="{'width': 16, 'height' : 16}" href="${url('filebrowser.views.upload_file')}?dest=${path|u}&next=${current_request_path|u}">Upload Files</a>
+  <a class="fb-mkdir" data-filters="ArtButton" data-icon-styles="{'width': 16, 'height': 16}" href="${url('filebrowser.views.mkdir')}?path=${path|u}&next=${current_request_path|u}">New Directory</a>
+</div>
 
+${dir.list_table_chooser(files, path_enc, current_request_path)}

+ 20 - 19
apps/filebrowser/src/filebrowser/urls.py

@@ -22,26 +22,27 @@ urlpatterns = patterns('filebrowser.views',
   # Base view
   url(r'^$', 'index', name='index'),
 
-  url(r'listdir(?P<path>/.*)', 'listdir', name='listdir'),
-  url(r'display(?P<path>/.*)', 'display', name='display'),
-  url(r'stat(?P<path>/.*)', 'stat', name='stat'),
-  url(r'download(?P<path>/.*)', 'download', name='download'),
-  url(r'status', 'status', name='status'),
-  url(r'home_relative_view(?P<path>/.*)', 'home_relative_view', name='home_relative_view'),
   # Catch-all for viewing a file (display) or a directory (listdir)
-  url(r'view(?P<path>/.*)', 'view', name='view'),
-  url(r'chooser(?P<path>/.*)', 'chooser', name='choose'),
-  url(r'edit(?P<path>/.*)', 'edit', name='edit'),
-  url(r'save', 'save_file'),
+  url(r'^view(?P<path>/.*)$', 'view', name='view'),
+
+  url(r'^listdir(?P<path>/.*)$', 'listdir', name='listdir'),
+  url(r'^display(?P<path>/.*)$', 'display', name='display'),
+  url(r'^stat(?P<path>/.*)$', 'stat', name='stat'),
+  url(r'^download(?P<path>/.*)$', 'download', name='download'),
+  url(r'^status$', 'status', name='status'),
+  url(r'^home_relative_view(?P<path>/.*)$', 'home_relative_view', name='home_relative_view'),
+  url(r'^chooser(?P<path>/.*)$', 'chooser', name='choose'),
+  url(r'^edit(?P<path>/.*)$', 'edit', name='edit'),
 
   # POST operations
-  url(r'upload/file$', 'upload_file', name='upload_file'),
-  url(r'upload/archive$', 'upload_archive', name='upload_archive'),
-  url(r'rename', 'rename', name='rename'),
-  url(r'mkdir', 'mkdir', name='mkdir'),
-  url(r'touch', 'touch', name='touch'),
-  url(r'move', 'move', name='move'),
-  url(r'rmtree', 'rmtree', name='rmtree'),
-  url(r'chmod', 'chmod', name='chmod'),
-  url(r'chown', 'chown', name='chown'),
+  url(r'^save$', 'save_file'),
+  url(r'^upload/file$', 'upload_file', name='upload_file'),
+  url(r'^upload/archive$', 'upload_archive', name='upload_archive'),
+  url(r'^rename$', 'rename', name='rename'),
+  url(r'^mkdir$', 'mkdir', name='mkdir'),
+  url(r'^touch$', 'touch', name='touch'),
+  url(r'^move$', 'move', name='move'),
+  url(r'^rmtree$', 'rmtree', name='rmtree'),
+  url(r'^chmod$', 'chmod', name='chmod'),
+  url(r'^chown$', 'chown', name='chown'),
 )

+ 6 - 0
apps/filebrowser/src/filebrowser/views_test.py

@@ -422,6 +422,12 @@ def test_listdir():
     response = c.get('/filebrowser/view' + prefix)
     assert_equal(response.context['home_directory'], home)
 
+    # Test URL conflicts with filenames
+    stat_dir = '%sstat/dir' % prefix
+    cluster.fs.do_as_user('test', cluster.fs.mkdir, stat_dir)
+    response = c.get('/filebrowser/view%s' % stat_dir)
+    assert_equal(stat_dir, response.context['path'])
+
     response = c.get('/filebrowser/view/test-filebrowser/?default_to_home')
     assert_true(re.search('%s$' % home, response['Location']))