Skip to content

Commit

Permalink
links conditioned by permissions and search item links
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Nov 19, 2024
1 parent 26e953c commit e7dc095
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
26 changes: 22 additions & 4 deletions oarepo_model_builder/datatypes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
26 changes: 23 additions & 3 deletions tests/test_simple_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit e7dc095

Please sign in to comment.