Skip to content

Commit

Permalink
preview: update file previewer check in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 authored and slint committed Jul 12, 2024
1 parent 0ea5f69 commit 7d4a5d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ <h2 id="files-heading">{{ _('Files') }}</h2>
{%-set preview_file = files|select_preview_file(default_preview=record.files.default_preview) %}
{{ preview_file_box(preview_file, record.id, is_preview, record, include_deleted) }}
{%- endif -%}
{{ file_list_box(files, record.id, is_preview, include_deleted, record) }}
{{ file_list_box(files, record.id, is_preview, include_deleted, record, permissions) }}
{% endif %}
{% else %}
{# record has files BUT user does not have permission to see files #}
Expand Down Expand Up @@ -349,7 +349,7 @@ <h4>{{ _("Request access") }}</h4>
<section id="record-media-files" aria-label="{{ _('System files') }}">
{%- set media_files = media_files | order_entries | selectattr("status", "==", "completed") | list %}
{%- if media_files|length > 0 -%}
{{ media_file_list_box(media_files, record.id, is_preview, include_deleted, record) }}
{{ media_file_list_box(media_files, record.id, is_preview, include_deleted, record, permissions) }}
{%- endif %}
</section>
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ <h3 class="active title panel-heading {{ record.ui.access_status.id }} m-0">
with_preview=true,
download_endpoint='invenio_app_rdm_records.record_file_download',
preview_endpoint='invenio_app_rdm_records.record_file_preview',
is_media=false
is_media=false,
permissions=None
) %}
<table class="ui striped table files fluid {{record.ui.access_status.id}}">
<thead>
Expand Down Expand Up @@ -133,7 +134,7 @@ <h3 class="active title panel-heading {{ record.ui.access_status.id }} m-0">
{%- endmacro %}


{% macro file_list_box(files, pid, is_preview, include_deleted, record) %}
{% macro file_list_box(files, pid, is_preview, include_deleted, record, permissions) %}
{%- set binary_sizes = not config.APP_RDM_DISPLAY_DECIMAL_FILE_SIZES %}
<div class="ui accordion panel mb-10 {{ record.ui.access_status.id }}" href="#files-list-accordion-panel">
<h3 class="active title panel-heading {{ record.ui.access_status.id }} m-0">
Expand All @@ -156,13 +157,13 @@ <h4 class="inline">{{ record.ui.access_status.title_l10n }}</h4>
</div>
{% endif %}
<div>
{{ file_list(files, pid, is_preview, include_deleted, record=record, download_endpoint="invenio_app_rdm_records.record_file_download") }}
{{ file_list(files, pid, is_preview, include_deleted, record=record,download_endpoint="invenio_app_rdm_records.record_file_download", permissions=permissions) }}
</div>
</div>
</div>
{%- endmacro %}

{% macro media_file_list_box(files, pid, is_preview, include_deleted, record) %}
{% macro media_file_list_box(files, pid, is_preview, include_deleted, record, permissions) %}
{%- set binary_sizes = not config.APP_RDM_DISPLAY_DECIMAL_FILE_SIZES %}
<div class="ui accordion panel mb-10 {{ record.access.record }}" href="#media-files-preview-accordion-panel">
<h3 class="active title panel-heading {{ record.access.record }} m-0">
Expand All @@ -186,7 +187,7 @@ <h4 class="inline">{{ record.ui.access_status.title_l10n }}</h4>
</div>
{% endif %}
<div>
{{ file_list(files, pid, is_preview, record=record, with_preview=false, download_endpoint="invenio_app_rdm_records.record_media_file_download", is_media=true) }}
{{ file_list(files, pid, is_preview, include_deleted, record=record, with_preview=false, download_endpoint="invenio_app_rdm_records.record_media_file_download", is_media=true, permissions=permissions) }}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_rdm/records_ui/views/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ def record_file_preview(
"""Render a preview of the specified file."""
# Try to see if specific previewer is set
# TODO: what's the analog of: file_previewer = fileobj.get("previewer") ?
file_previewer = file_metadata.data.get("previewer")

file_previewer = file_metadata.data.get("metadata", {}).get("previewer", {})
url = url_for(
"invenio_app_rdm_records.record_file_download",
pid_value=pid_value,
Expand Down

0 comments on commit 7d4a5d6

Please sign in to comment.