Skip to content

Commit

Permalink
Merge pull request #259 from oarepo/miroslavsimek/be-563-detai-page-p…
Browse files Browse the repository at this point in the history
…review

feat: preview for draft files
  • Loading branch information
mirekys authored Nov 29, 2024
2 parents 67ba9f5 + 049182a commit bc3a39b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion oarepo_ui/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class RecordsUIResourceConfig(UIResourceConfig):
"export": "/<pid_value>/export/<export_format>",
"export_preview": "/<pid_value>/preview/export/<export_format>",
"preview": "/<pid_value>/preview",
"file_preview": "/<pid_value>/files/<path:filepath>/preview",
"published_file_preview": "/<pid_value>/files/<path:filepath>/preview",
"draft_file_preview": "/<pid_value>/preview/files/<path:filepath>/preview",
}
config_url_prefix = '/configs'
config_routes = {
Expand Down
29 changes: 18 additions & 11 deletions oarepo_ui/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,27 @@ def detail(self):

@request_read_args
@request_file_view_args
def file_preview(self, *args, is_preview=False, **kwargs):
def published_file_preview(self, *args, **kwargs):
"""Return file preview for published record."""
record = self._get_record(
resource_requestctx, allow_draft=False
)._record

return self._file_preview(record)

@request_read_args
@request_file_view_args
def draft_file_preview(self, *args, **kwargs):
"""Return file preview for draft record."""
record = self._get_record(
resource_requestctx, allow_draft=True
)._record
return self._file_preview(record)

def _file_preview(self, record):
pid_value = resource_requestctx.view_args["pid_value"]
filepath = resource_requestctx.view_args["filepath"]

# TODO: this is a hack that should be fixed
try:
record = self._get_record(
resource_requestctx, allow_draft=is_preview
)._record
except Forbidden:
record = self._get_record(
resource_requestctx, allow_draft=not is_preview
)._record

file_service = get_file_service_for_record_class(type(record))
file_metadata = file_service.read_file_metadata(g.identity, pid_value, filepath)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-ui
version = 5.2.27
version = 5.2.28
description = UI module for invenio 3.5+
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit bc3a39b

Please sign in to comment.