Skip to content

Commit

Permalink
Directory listing permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
darbula committed Jul 27, 2013
1 parent 81d09fb commit 094572a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
10 changes: 7 additions & 3 deletions filer/admin/folderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
permissions = {}
folder_files.sort()
items = folder_children + folder_files
paginator = Paginator(items, FILER_PAGINATE_BY)
items_permissions = [(item, self.has_change_permission(request, item)) for item in items]
paginator = Paginator(items_permissions, FILER_PAGINATE_BY)

# Are we moving to clipboard?
if request.method == 'POST' and '_save' not in request.POST:
Expand Down Expand Up @@ -366,7 +367,7 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
in_clipboards__clipboarditem__clipboard__user=request.user
).distinct(),
'paginator': paginator,
'paginated_items': paginated_items,
'paginated_items': paginated_items, #(item, change_permission)
'permissions': permissions,
'permstest': userperms_for_request(folder, request),
'current_url': request.path,
Expand All @@ -386,7 +387,10 @@ def directory_listing(self, request, folder_id=None, viewtype=None):
'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(paginated_items.object_list)},
'selection_note_all': selection_note_all % {'total_count': paginator.count},
'media': self.media,
'enable_permissions': settings.FILER_ENABLE_PERMISSIONS
'enable_permissions': settings.FILER_ENABLE_PERMISSIONS,
'can_make_folder': request.user.is_superuser or \
(folder.is_root and settings.FILER_ALLOW_REGULAR_USERS_TO_ADD_ROOT_FOLDERS) or \
permissions.get("has_add_children_permission"),
}, context_instance=RequestContext(request))

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions filer/templates/admin/filer/folder/directory_listing.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{% block content %}
<div id="content-main">
<ul class="object-tools">
{% if folder.can_have_subfolders %}<li><a id="id_new_folder" href="{% url 'admin:filer-directory_listing-make_root_folder' %}?parent_id={{ folder.id }}" class="addlink" onclick="return showAddAnotherPopup(this);" title="{% trans "Adds a new Folder" %}">{% trans "New Folder" %}</a>{% endif %}</li>
{% if folder.can_have_subfolders %}{% if can_make_folder %}<li><a id="id_new_folder" href="{% url 'admin:filer-directory_listing-make_root_folder' %}?parent_id={{ folder.id }}" class="addlink" onclick="return showAddAnotherPopup(this);" title="{% trans "Adds a new Folder" %}">{% trans "New Folder" %}</a>{% endif %}{% endif %}</li>
<li><a id="id_upload_button" href="#" class="addlink" title="{% trans 'upload files' %}">{% trans 'Upload' %}</a></li>
{% include 'admin/filer/tools/upload_button_js.html' %}
</ul>
Expand All @@ -78,7 +78,7 @@ <h1 class="folder_header">{% if folder.parent %}<a href="{% url 'admin:filer-dir
<span>
{% if is_popup %}
{% if select_folder and folder.file_type == 'Folder' %}<a class="insertlink insertlinkButton" href="" onclick="opener.dismissRelatedFolderLookupPopup(window, {{ folder.id }}, '{{ folder.quoted_logical_path }}'); return false;" >&nbsp;</a>{% endif %}
{% else %}<a style="display: block; float: right;" class="changelink" href="{% url 'admin:filer_folder_change' folder.id %}" title="{% trans "Change current folder details" %}">{% trans "Change" %}</a>{% endif %}
{% else %}{% if permissions.has_edit_permission %}<a style="display: block; float: right;" class="changelink" href="{% url 'admin:filer_folder_change' folder.id %}" title="{% trans "Change current folder details" %}">{% trans "Change" %}</a>{% endif %}{% endif %}
</span>
</h1>
{% else %}{% if folder.is_smart_folder %}
Expand Down
12 changes: 7 additions & 5 deletions filer/templates/admin/filer/folder/directory_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
</tr>
</thead>
<tbody>
{% for item in paginated_items.object_list %}
{% for item, item_change_permission in paginated_items.object_list %}
{% if item.file_type == 'Folder' or item.file_type == 'DummyFolder' %}{% with item as subfolder%}
<tr class="{% cycle rowcolors %}">
<td>{% if select_folder and item.file_type == 'Folder' %}<a class="insertlink insertlinkButton" href="" onclick="opener.dismissRelatedFolderLookupPopup(window, {{ subfolder.id }}, '{{ subfolder.quoted_logical_path }}'); return false;" >&nbsp;</a>{% else %}{% if action_form and item.pk and not is_popup %}<input type="checkbox" class="action-select" value="folder-{{ item.pk }}" name="_selected_action" />{% endif %}{% endif %}</td>
<!-- DirIcon -->
<td><a href="{{ subfolder.get_admin_directory_listing_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with subfolder.name as item_label %}Change '{{ item_label }}' folder details{% endblocktrans %}"><img src="{{ subfolder.icons.48 }}" alt="{% trans "Folder Icon" %}" /></a></td>
<!-- Directory details -->
<td>
{% if item.file_type == 'Folder' %}
{% if item.file_type == 'Folder' and item_change_permission %}
<a style="display: block; float: right;" class="changelink" href="{{ subfolder.get_admin_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with subfolder.name as item_label %}Change '{{ item_label }}' folder details{% endblocktrans %}">{% trans "Change" %}</a>
{% endif %}
<div><b><a href="{{ subfolder.get_admin_directory_listing_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with subfolder.name as item_label %}Change '{{ item_label }}' folder details{% endblocktrans %}">{{ subfolder.name }}</a></b>{% if not subfolder.is_root %}<span class="tiny"> ({% blocktrans count subfolder.children_count as counter %}1 folder{% plural %}{{ counter }} folders{% endblocktrans %}, {% blocktrans count subfolder.file_count as counter %}1 file{% plural %}{{ counter }} files{% endblocktrans %})</span>{% endif %}</div>
Expand All @@ -36,18 +36,20 @@
<tr class="{% cycle rowcolors %}">
<td>{% if is_popup and not select_folder %}<a class="insertlink insertlinkButton" href="" onclick="opener.dismissRelatedImageLookupPopup(window, {{ file.id }}, '{{ file.icons.48|escapejs }}', '{{ file.label|escapejs }}'); return false;" title="{% trans "Select this file" %}">&nbsp;</a>{% else %}{% if action_form and not is_popup %}<input type="checkbox" class="action-select" value="file-{{ item.pk }}" name="_selected_action" />{% endif %}{% endif %}</td>
<!-- FileIcon -->
<td><a href="{{ file.get_admin_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with file.label as item_label %}Change '{{ item_label }}' details{% endblocktrans %}"><img src="{% if file.icons.48 %}{{ file.icons.48 }}{% else %}{% filer_staticmedia_prefix %}icons/missingfile_48x48.png{% endif %}" alt="{{ file.default_alt_text }}" /></a></td>
<td>{% if item_change_permission %}<a href="{{ file.get_admin_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with file.label as item_label %}Change '{{ item_label }}' details{% endblocktrans %}">{% endif %}<img src="{% if file.icons.48 %}{{ file.icons.48 }}{% else %}{% filer_staticmedia_prefix %}icons/missingfile_48x48.png{% endif %}" alt="{{ file.default_alt_text }}" />{% if item_change_permission %}</a>{% endif %}</td>
<!-- Filename/Dimensions -->
<td>
{% if item_change_permission %}
<a style="display: block; float: right;margin-left: 10px;" class="deletelink" href="{% url 'admin:filer_file_delete' file.pk %}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}"" title="{% blocktrans with file.label as item_label %}Delete '{{ item_label }}'{% endblocktrans %}">{% trans "Delete" %}</a>
<a style="display: block; float: right;" class="changelink" href="{{ file.get_admin_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with file.label as item_label %}Change '{{ item_label }}' details{% endblocktrans %}">{% trans "Change" %}</a>
<div><b><a href="{{ file.get_admin_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with file.label as item_label %}Change '{{ item_label }}' details{% endblocktrans %}">{{ file.label }}</a></b><span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% ifequal file.file_type "Image" %}, {{ file.width }}x{{ file.height }} px{% endifequal %})</span></div>
{% endif %}
<div><b>{% if item_change_permission %}<a href="{{ file.get_admin_url_path }}{% if is_popup %}?_popup=1{% if select_folder %}&select_folder=1{% endif %}{% endif %}" title="{% blocktrans with file.label as item_label %}Change '{{ item_label }}' details{% endblocktrans %}">{% endif %}{{ file.label }}{% if item_change_permission %}</a>{% endif %}</b><span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% ifequal file.file_type "Image" %}, {{ file.width }}x{{ file.height }} px{% endifequal %})</span></div>
<div>{% trans "Owner" %}: {{ file.owner|default:"n/a" }}</div>
{% if enable_permissions %}<div>{% trans "Permissions" %}: {% if file.is_public %}{% trans "disabled" %}{% else %}{% trans "enabled" %}{% endif %}</div>{% endif %}
{# {% if file.has_all_mandatory_data %}<div><img alt="0" src="{% admin_icon_base %}img/admin/icon-yes.gif" /> {% trans "has all mandatory metadata" %}</div>{% else %}<div><img alt="1" src="{% admin_icon_base %}img/admin/icon-no.gif"/> {% trans "missing metadata!" %}</div>{% endif %} #}
</td>
<td style="text-align: right;">
<input type="submit" name="move-to-clipboard-{{ file.id }}" value="&rarr;" title="{% trans "Move to clipboard" %}"{% if file in clipboard_files %} style="color: gray;" disabled="disabled"{% endif %} />
<input type="submit" name="move-to-clipboard-{{ file.id }}" value="&rarr;" title="{% trans "Move to clipboard" %}"{% if file in clipboard_files or not item_change_permission %} style="color: gray;" disabled="disabled"{% endif %} />
</td>
</tr>
{% endwith %}{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion filer/templates/admin/filer/tools/clipboard/clipboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<input type="hidden" name="redirect_to" value="{{ current_url }}" />
{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
{% if select_folder %}<input type="hidden" name="select_folder" value="1" />{% endif %}
<input type="submit" value="&lArr;"{% if folder.is_root %} disabled="disabled" style="color: gray;"{% endif %} title="{% trans "Paste all items here" %}"/>
<input type="submit" value="&lArr;"{% if folder.is_root or not permissions.has_add_children_permission %} disabled="disabled" style="color: gray;"{% endif %} title="{% trans "Paste all items here" %}"/>
</form>
<form action="{% url 'admin:filer-discard_clipboard' %}" method="post" style="display: inline;">{% csrf_token %}
<input type="hidden" name="clipboard_id" value="{{ clipboard.id }}" />
Expand Down

0 comments on commit 094572a

Please sign in to comment.