Commit f0b6cc20 authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #1215 from vToMy/fileadmin_action_fix

fixes #1131 - broken action redirect in FileAdmin
parents 97cc3252 846268be
import warnings
from datetime import datetime from datetime import datetime
import os import os
import os.path as op import os.path as op
...@@ -696,9 +697,15 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -696,9 +697,15 @@ class BaseFileAdmin(BaseView, ActionsMixin):
breadcrumbs.append((n, self._separator.join(accumulator))) breadcrumbs.append((n, self._separator.join(accumulator)))
return breadcrumbs return breadcrumbs
@expose('/old_index')
@expose('/old_b/<path:path>')
def index(self, path=None):
warnings.warn('deprecated: use index_view instead.', DeprecationWarning)
return redirect(self.get_url('.index_view', path=path))
@expose('/') @expose('/')
@expose('/b/<path:path>') @expose('/b/<path:path>')
def index(self, path=None): def index_view(self, path=None):
""" """
Index view method Index view method
...@@ -714,7 +721,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -714,7 +721,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
base_path, directory, path = self._normalize_path(path) base_path, directory, path = self._normalize_path(path)
if not self.is_accessible_path(path): if not self.is_accessible_path(path):
flash(gettext('Permission denied.'), 'error') flash(gettext('Permission denied.'), 'error')
return redirect(self._get_dir_url('.index')) return redirect(self._get_dir_url('.index_view'))
# Get directory listing # Get directory listing
items = [] items = []
...@@ -771,11 +778,11 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -771,11 +778,11 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if not self.can_upload: if not self.can_upload:
flash(gettext('File uploading is disabled.'), 'error') flash(gettext('File uploading is disabled.'), 'error')
return redirect(self._get_dir_url('.index', path)) return redirect(self._get_dir_url('.index_view', path))
if not self.is_accessible_path(path): if not self.is_accessible_path(path):
flash(gettext('Permission denied.'), 'error') flash(gettext('Permission denied.'), 'error')
return redirect(self._get_dir_url('.index')) return redirect(self._get_dir_url('.index_view'))
form = self.upload_form() form = self.upload_form()
if self.validate_form(form): if self.validate_form(form):
...@@ -783,7 +790,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -783,7 +790,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
self._save_form_files(directory, path, form) self._save_form_files(directory, path, form)
flash(gettext('Successfully saved file: %(name)s', flash(gettext('Successfully saved file: %(name)s',
name=form.upload.data.filename)) name=form.upload.data.filename))
return redirect(self._get_dir_url('.index', path)) return redirect(self._get_dir_url('.index_view', path))
except Exception as ex: except Exception as ex:
flash(gettext('Failed to save file: %(error)s', error=ex), 'error') flash(gettext('Failed to save file: %(error)s', error=ex), 'error')
...@@ -812,7 +819,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -812,7 +819,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
# backward compatibility with base_url # backward compatibility with base_url
base_url = self.get_base_url() base_url = self.get_base_url()
if base_url: if base_url:
base_url = urljoin(self.get_url('.index'), base_url) base_url = urljoin(self.get_url('.index_view'), base_url)
return redirect(urljoin(base_url, path)) return redirect(urljoin(base_url, path))
return self.storage.send_file(directory) return self.storage.send_file(directory)
...@@ -829,7 +836,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -829,7 +836,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
# Get path and verify if it is valid # Get path and verify if it is valid
base_path, directory, path = self._normalize_path(path) base_path, directory, path = self._normalize_path(path)
dir_url = self._get_dir_url('.index', path) dir_url = self._get_dir_url('.index_view', path)
if not self.can_mkdir: if not self.can_mkdir:
flash(gettext('Directory creation is disabled.'), 'error') flash(gettext('Directory creation is disabled.'), 'error')
...@@ -837,7 +844,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -837,7 +844,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if not self.is_accessible_path(path): if not self.is_accessible_path(path):
flash(gettext('Permission denied.'), 'error') flash(gettext('Permission denied.'), 'error')
return redirect(self._get_dir_url('.index')) return redirect(self._get_dir_url('.index_view'))
form = self.name_form() form = self.name_form()
...@@ -876,9 +883,9 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -876,9 +883,9 @@ class BaseFileAdmin(BaseView, ActionsMixin):
path = form.path.data path = form.path.data
if path: if path:
return_url = self._get_dir_url('.index', op.dirname(path)) return_url = self._get_dir_url('.index_view', op.dirname(path))
else: else:
return_url = self.get_url('.index') return_url = self.get_url('.index_view')
if self.validate_form(form): if self.validate_form(form):
# Get path and verify if it is valid # Get path and verify if it is valid
...@@ -890,7 +897,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -890,7 +897,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if not self.is_accessible_path(path): if not self.is_accessible_path(path):
flash(gettext('Permission denied.'), 'error') flash(gettext('Permission denied.'), 'error')
return redirect(self._get_dir_url('.index')) return redirect(self._get_dir_url('.index_view'))
if self.storage.is_dir(full_path): if self.storage.is_dir(full_path):
if not self.can_delete_dirs: if not self.can_delete_dirs:
...@@ -927,9 +934,9 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -927,9 +934,9 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if path: if path:
base_path, full_path, path = self._normalize_path(path) base_path, full_path, path = self._normalize_path(path)
return_url = self._get_dir_url('.index', op.dirname(path)) return_url = self._get_dir_url('.index_view', op.dirname(path))
else: else:
return redirect(self.get_url('.index')) return redirect(self.get_url('.index_view'))
if not self.can_rename: if not self.can_rename:
flash(gettext('Renaming is disabled.'), 'error') flash(gettext('Renaming is disabled.'), 'error')
...@@ -937,7 +944,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -937,7 +944,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if not self.is_accessible_path(path): if not self.is_accessible_path(path):
flash(gettext('Permission denied.'), 'error') flash(gettext('Permission denied.'), 'error')
return redirect(self._get_dir_url('.index')) return redirect(self._get_dir_url('.index_view'))
if not self.storage.path_exists(full_path): if not self.storage.path_exists(full_path):
flash(gettext('Path does not exist.'), 'error') flash(gettext('Path does not exist.'), 'error')
...@@ -978,7 +985,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -978,7 +985,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
path = request.args.getlist('path') path = request.args.getlist('path')
if not path: if not path:
return redirect(self.get_url('.index')) return redirect(self.get_url('.index_view'))
if len(path) > 1: if len(path) > 1:
next_url = self.get_url('.edit', path=path[1:]) next_url = self.get_url('.edit', path=path[1:])
...@@ -989,9 +996,9 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -989,9 +996,9 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if not self.is_accessible_path(path) or not self.is_file_editable(path): if not self.is_accessible_path(path) or not self.is_file_editable(path):
flash(gettext('Permission denied.'), 'error') flash(gettext('Permission denied.'), 'error')
return redirect(self._get_dir_url('.index')) return redirect(self._get_dir_url('.index_view'))
dir_url = self._get_dir_url('.index', op.dirname(path)) dir_url = self._get_dir_url('.index_view', op.dirname(path))
next_url = next_url or dir_url next_url = next_url or dir_url
form = self.edit_form() form = self.edit_form()
......
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
{% block breadcrums %} {% block breadcrums %}
<ul class="breadcrumb"> <ul class="breadcrumb">
<li> <li>
<a href="{{ get_dir_url('.index', path=None) }}">{{ _gettext('Root') }}</a> <a href="{{ get_dir_url('.index_view', path=None) }}">{{ _gettext('Root') }}</a>
</li> </li>
{% for name, path in breadcrumbs[:-1] %} {% for name, path in breadcrumbs[:-1] %}
<li> <li>
<span class="divider">/</span><a href="{{ get_dir_url('.index', path=path) }}">{{ name }}</a> <span class="divider">/</span><a href="{{ get_dir_url('.index_view', path=path) }}">{{ name }}</a>
</li> </li>
{% endfor %} {% endfor %}
{% if breadcrumbs %} {% if breadcrumbs %}
<li> <li>
<span class="divider">/</span><a href="{{ get_dir_url('.index', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a> <span class="divider">/</span><a href="{{ get_dir_url('.index_view', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
</td> </td>
{% if is_dir %} {% if is_dir %}
<td colspan="2"> <td colspan="2">
<a href="{{ get_dir_url('.index', path)|safe }}"> <a href="{{ get_dir_url('.index_view', path)|safe }}">
<i class="fa fa-folder-o icon-folder-close"></i> <span>{{ name }}</span> <i class="fa fa-folder-o icon-folder-close"></i> <span>{{ name }}</span>
</a> </a>
</td> </td>
......
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
{% block breadcrums %} {% block breadcrums %}
<ul class="breadcrumb"> <ul class="breadcrumb">
<li> <li>
<a href="{{ get_dir_url('.index', path=None) }}">{{ _gettext('Root') }}</a> <a href="{{ get_dir_url('.index_view', path=None) }}">{{ _gettext('Root') }}</a>
</li> </li>
{% for name, path in breadcrumbs[:-1] %} {% for name, path in breadcrumbs[:-1] %}
<li> <li>
<a href="{{ get_dir_url('.index', path=path) }}">{{ name }}</a> <a href="{{ get_dir_url('.index_view', path=path) }}">{{ name }}</a>
</li> </li>
{% endfor %} {% endfor %}
{% if breadcrumbs %} {% if breadcrumbs %}
<li> <li>
<a href="{{ get_dir_url('.index', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a> <a href="{{ get_dir_url('.index_view', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
</td> </td>
{% if is_dir %} {% if is_dir %}
<td colspan="2"> <td colspan="2">
<a href="{{ get_dir_url('.index', path)|safe }}"> <a href="{{ get_dir_url('.index_view', path)|safe }}">
<i class="fa fa-folder-o glyphicon glyphicon-folder-close"></i> <span>{{ name }}</span> <i class="fa fa-folder-o glyphicon glyphicon-folder-close"></i> <span>{{ name }}</span>
</a> </a>
</td> </td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment