diff --git a/oarepo_model_builder/datatypes/model.py b/oarepo_model_builder/datatypes/model.py index 0ffeee9..9dd541c 100644 --- a/oarepo_model_builder/datatypes/model.py +++ b/oarepo_model_builder/datatypes/model.py @@ -58,16 +58,34 @@ def links(self): Link( name="self", link_class="RecordLink", - link_args=[f'"{{+api}}{url_prefix}{{id}}"'], - imports=[Import("invenio_records_resources.services.RecordLink")], + link_args=[f'"{{+api}}{url_prefix}{{id}}"', 'when=has_permission("read")'], + imports=[Import("invenio_records_resources.services.RecordLink"), Import("oarepo_runtime.records.has_permission")], ), Link( name="self_html", link_class="RecordLink", link_args=[ - f'"{{+ui}}{html_url_prefix}{{id}}"', + f'"{{+ui}}{html_url_prefix}{{id}}"', 'when=has_permission("read")' ], - imports=[Import("invenio_records_resources.services.RecordLink")], + imports=[Import("invenio_records_resources.services.RecordLink"), Import("oarepo_runtime.records.has_permission")], + ), + ], + "links_search_item": [ + Link( + name="self", + link_class="RecordLink", + link_args=[f'"{{+api}}{url_prefix}{{id}}"', 'when=has_permission("read")'], + imports=[Import("invenio_records_resources.services.RecordLink"), + Import("oarepo_runtime.records.has_permission")], + ), + Link( + name="self_html", + link_class="RecordLink", + link_args=[ + f'"{{+ui}}{html_url_prefix}{{id}}"', 'when=has_permission("read")' + ], + imports=[Import("invenio_records_resources.services.RecordLink"), + Import("oarepo_runtime.records.has_permission")], ), ], "links_search": [ diff --git a/tests/test_simple_builders.py b/tests/test_simple_builders.py index 9c642d0..3e87f70 100644 --- a/tests/test_simple_builders.py +++ b/tests/test_simple_builders.py @@ -382,6 +382,7 @@ def test_service_config(): from oarepo_runtime.services.config.service import PermissionsPresetsConfigMixin from invenio_records_resources.services import RecordLink from invenio_records_resources.services import pagination_links +from oarepo_runtime.records import has_permission from test.records.api import TestRecord from test.services.records.permissions import TestPermissionPolicy from test.services.records.schema import TestSchema @@ -392,27 +393,46 @@ def test_service_config(): class TestServiceConfig(PermissionsPresetsConfigMixin, InvenioRecordServiceConfig): """TestRecord service config.""" + result_item_cls = TestRecordItem + + result_list_cls = TestRecordList - PERMISSIONS_PRESETS = ["everyone"] + + PERMISSIONS_PRESETS = ["everyone" ] + url_prefix = "/test/" + base_permission_policy_cls = TestPermissionPolicy + + schema = TestSchema + + search = TestSearchOptions + + record_cls = TestRecord + + service_id = "test" + + components = [ *PermissionsPresetsConfigMixin.components, *InvenioRecordServiceConfig.components] + model = "test" + @property def links_item(self): return { - "self":RecordLink("{+api}/test/{id}"), + "self":RecordLink("{+api}/test/{id}", when=has_permission("read")), - "self_html":RecordLink("{+ui}/test/{id}"), + "self_html":RecordLink("{+ui}/test/{id}", when=has_permission("read")), } + @property def links_search(self): return {