diff --git a/oarepo_ui/resources/config.py b/oarepo_ui/resources/config.py index 0078f76d..d5d50694 100644 --- a/oarepo_ui/resources/config.py +++ b/oarepo_ui/resources/config.py @@ -88,7 +88,8 @@ class RecordsUIResourceConfig(UIResourceConfig): "export": "//export/", "export_preview": "//preview/export/", "preview": "//preview", - "file_preview": "//files//preview", + "published_file_preview": "//files//preview", + "draft_file_preview": "//preview/files//preview", } config_url_prefix = '/configs' config_routes = { diff --git a/oarepo_ui/resources/resource.py b/oarepo_ui/resources/resource.py index b6795a5b..f314bbd6 100644 --- a/oarepo_ui/resources/resource.py +++ b/oarepo_ui/resources/resource.py @@ -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) diff --git a/setup.cfg b/setup.cfg index 3dd59e07..5f660228 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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