From 057e5b7008fb7fff0eaaabde4920f61924f0e487 Mon Sep 17 00:00:00 2001 From: anikachurilova Date: Wed, 6 Sep 2023 17:03:53 +0200 Subject: [PATCH] links: add media files archive link * fix typo in permissions * closes https://github.com/zenodo/rdm-project/issues/219 --- invenio_rdm_records/services/config.py | 15 +++++++++++++-- invenio_rdm_records/services/permissions.py | 2 +- tests/resources/test_serialized_links.py | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/invenio_rdm_records/services/config.py b/invenio_rdm_records/services/config.py index 222788872..922538410 100644 --- a/invenio_rdm_records/services/config.py +++ b/invenio_rdm_records/services/config.py @@ -442,6 +442,17 @@ class RDMRecordServiceConfig(RecordServiceConfig, ConfiguratorMixin): when=archive_download_enabled, ), ), + "archive_media": ConditionalLink( + cond=is_record, + if_=RecordLink( + "{+api}/records/{id}/media-files-archive", + when=archive_download_enabled, + ), + else_=RecordLink( + "{+api}/records/{id}/draft/media-files-archive", + when=archive_download_enabled, + ), + ), "latest": RecordLink("{+api}/records/{id}/versions/latest", when=is_record), "latest_html": RecordLink("{+ui}/records/{id}/latest", when=is_record), "draft": RecordLink("{+api}/records/{id}/draft", when=is_record), @@ -531,7 +542,7 @@ class RDMMediaFileRecordServiceConfig(FileServiceConfig, ConfiguratorMixin): file_links_list = { "self": RecordLink("{+api}/records/{id}/media-files"), "archive": RecordLink( - "{+api}/records/{id}/media-files-archive", # TODO needed? + "{+api}/records/{id}/media-files-archive", when=archive_download_enabled, ), } @@ -596,7 +607,7 @@ class RDMMediaFileDraftServiceConfig(FileServiceConfig, ConfiguratorMixin): file_links_list = { "self": RecordLink("{+api}/records/{id}/draft/media-files"), "archive": RecordLink( - "{+api}/records/{id}/draft/media-files-archive", # TODO needed? + "{+api}/records/{id}/draft/media-files-archive", when=archive_download_enabled, ), } diff --git a/invenio_rdm_records/services/permissions.py b/invenio_rdm_records/services/permissions.py index feed767d6..55cbd7e62 100644 --- a/invenio_rdm_records/services/permissions.py +++ b/invenio_rdm_records/services/permissions.py @@ -229,7 +229,7 @@ class RDMRecordPermissionPolicy(RecordPermissionPolicy): # it was simpler and less coupling to implement this as permission check IfFileIsLocal(then_=can_read, else_=[SystemProcess()]) ] - can_media_create__files = [Disable()] + can_media_create_files = [Disable()] can_media_set_content_files = [Disable()] can_media_commit_files = [Disable()] can_media_update_files = [Disable()] diff --git a/tests/resources/test_serialized_links.py b/tests/resources/test_serialized_links.py index cdabc16a2..08d8b1fa8 100644 --- a/tests/resources/test_serialized_links.py +++ b/tests/resources/test_serialized_links.py @@ -65,6 +65,7 @@ def test_draft_links(client, draft_json, minimal_record, headers): "files": f"https://127.0.0.1:5000/api/records/{pid_value}/draft/files", "media_files": f"https://127.0.0.1:5000/api/records/{pid_value}/draft/media-files", "archive": f"https://127.0.0.1:5000/api/records/{pid_value}/draft/files-archive", # noqa + "archive_media": f"https://127.0.0.1:5000/api/records/{pid_value}/draft/media-files-archive", # noqa "reserve_doi": f"https://127.0.0.1:5000/api/records/{pid_value}/draft/pids/doi", # noqa "self_iiif_manifest": f"https://127.0.0.1:5000/api/iiif/draft:{pid_value}/manifest", # noqa "self_iiif_sequence": f"https://127.0.0.1:5000/api/iiif/draft:{pid_value}/sequence/default", # noqa @@ -97,6 +98,7 @@ def test_record_links(client, published_json, headers): "files": f"https://127.0.0.1:5000/api/records/{pid_value}/files", "media_files": f"https://127.0.0.1:5000/api/records/{pid_value}/media-files", "archive": f"https://127.0.0.1:5000/api/records/{pid_value}/files-archive", + "archive_media": f"https://127.0.0.1:5000/api/records/{pid_value}/media-files-archive", "parent": f"https://127.0.0.1:5000/api/records/{parent_pid_value}", "parent_doi": f"https://127.0.0.1:5000/doi/{parent_doi_value}", "parent_html": f"https://127.0.0.1:5000/records/{parent_pid_value}",