Skip to content

Commit

Permalink
Merge pull request #24 from oarepo/krist/be-231-fix-apiuserdocs-to-re…
Browse files Browse the repository at this point in the history
…turn-published-draft-user-documents

nr-docs release issues
  • Loading branch information
SilvyPuzzlewell authored Mar 21, 2024
2 parents 9041b86 + 868c223 commit 6d1ad36
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
25 changes: 23 additions & 2 deletions oarepo_model_builder_drafts/datatypes/components/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,31 @@ def process_links(self, datatype, section: Section, **kwargs):
)

if datatype.root.profile == "record":
if "links_search" in section.config:
section.config.pop("links_search")

remove_links_by_names(section.config["links_item"], {"self", "self_html"})

section.config["links_search_drafts"] = [
Link(
name=None,
link_class="pagination_links",
link_args=[f'"{{+api}}/user{url_prefix}{{?args*}}"'],
imports=[
Import("invenio_records_resources.services.pagination_links")
],
),
]

section.config["links_search_versions"] = [
Link(
name=None,
link_class="pagination_links",
link_args=[f'"{{+api}}{url_prefix}{{id}}/versions{{?args*}}"'],
imports=[
Import("invenio_records_resources.services.pagination_links")
],
),
]

section.config["links_item"] += [
Link(
name="self",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
datatype.definition["mapping"] = mapping

super().before_model_prepare(datatype, context=context, **kwargs)
if datatype.root.profile == "draft":
mapping = datatype.definition["mapping"]
mapping_alias = datatype.definition["mapping"]["alias"]
mapping.setdefault("index-field-args", []).append(
f'search_alias="{mapping_alias}"'
)
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ def process_tests(self, datatype, section, **extra_kwargs):
"self_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}",
"versions": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions",
},
"page_size": "25",
"sort_search": "newest",
"sort_versions": "version",
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from oarepo_runtime.records.systemfields.has_draftcheck import HasDraftCheckField

class {{ published_record.record|class_header}}:
has_draft = HasDraftCheckField(draft_cls=lambda: {{ vars.record.class|base_name }}, config_key="HAS_DRAFT_CUSTOM_FIELD")

class {{ vars.record|class_header }}:

has_draft = HasDraftCheckField(config_key="HAS_DRAFT_CUSTOM_FIELD")
{{ vars.record|extra_code }}

{{ published_record.record.class|base_name }}.has_draft = HasDraftCheckField(draft_cls={{ vars.record.class|base_name }}, config_key="HAS_DRAFT_CUSTOM_FIELD")
{{ vars.record|extra_code }}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_list_drafts(client_with_credentials, input_data, vocab_cf, search_clear
{{ vars.record.class|base_name }}.index.refresh()
{{ published_record.record.class|base_name }}.index.refresh()
assert len(client_with_credentials.get({{ vars.resource_config.class|base_name }}.url_prefix).json["hits"]["hits"]) == 1
assert len(client_with_credentials.get(f"user{{"{" }} {{ vars.resource_config.class|base_name }}.url_prefix{{ "}" }}").json["hits"]["hits"]) == 0
assert len(client_with_credentials.get(f"user{{"{" }} {{ vars.resource_config.class|base_name }}.url_prefix{{ "}" }}").json["hits"]["hits"]) == 1 #we want this to list user records now, ie. both drafts and published


def assert_expected_links_record(pid_value, links, base_urls, site_hostname="127.0.0.1:5000"):
Expand All @@ -224,3 +224,14 @@ def test_read_links_record(app, client_with_credentials, input_data, base_urls,
def test_draft_listing_links(app, client_with_credentials, base_urls, sample_draft):
res = client_with_credentials.get(f"/user{base_urls['base_url']}")
assert_expected_links(sample_draft["id"], res.json["hits"]["hits"][0]["links"], base_urls)


def test_pagination_links(app, client_with_credentials, base_urls, sample_draft, sample_published_record, site_hostname="127.0.0.1:5000"):
res_search = client_with_credentials.get(f"/user{base_urls['base_url']}")
page_size = "{{ test_constants.page_size }}"
sort_search = "{{ test_constants.sort_search }}"
sort_versions = "{{ test_constants.sort_versions }}"
assert res_search.json["links"]["self"] == f"https://{site_hostname}/api/user{base_urls['base_url']}?page=1&size={page_size}&sort={sort_search}"
res_versions = client_with_credentials.get(f"{base_urls['base_url']}{sample_published_record['id']}/versions")
assert res_versions.json["links"]["self"] == f"https://{site_hostname}/api{base_urls['base_url']}{sample_published_record['id']}/versions?page=1&size={page_size}&sort={sort_versions}"

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-model-builder-drafts
version = 4.0.21
version = 4.0.22
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 6d1ad36

Please sign in to comment.