Skip to content

Commit

Permalink
Merge pull request #33 from oarepo/krist/be-287-change-the-links-for-…
Browse files Browse the repository at this point in the history
…drafts-html-pages-in-links-section

edit_html link; self_html link points to preview for draft
  • Loading branch information
mesemus authored Apr 25, 2024
2 parents 8206a0e + 45bc9d0 commit 83fca1d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
14 changes: 13 additions & 1 deletion oarepo_model_builder_drafts/datatypes/components/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,26 @@ def process_links(self, datatype, section: Section, **kwargs):
link_args=[
"cond=is_published_record",
f'if_=RecordLink("{{+ui}}{html_url_prefix}{{id}}")',
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/edit")',
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/preview")',
],
imports=[
Import("invenio_records_resources.services.ConditionalLink"),
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.records.is_published_record"),
],
),
Link(
name="edit_html",
link_class="RecordLink",
link_args=[
f'"{{+ui}}{html_url_prefix}{{id}}/edit"',
"when=has_draft",
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.records.has_draft"),
],
),
Link(
name="latest",
link_class="RecordLink",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def process_tests(self, datatype, section, **extra_kwargs):
"publish": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft/actions/publish",
"record": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}",
"self": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft",
"self_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/edit",
"self_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/preview",
"versions": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions",
},
"links_record": {
Expand All @@ -45,6 +45,9 @@ 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",
},
"links_when_draft": {
"edit_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/edit",
},
"page_size": "10",
"sort_search": "newest",
"sort_versions": "version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ def assert_expected_links_record(pid_value, links, base_urls, site_hostname="127
}
assert expected_links.items() <= links.items()

def has_expected_links_when_has_draft(pid_value, links, base_urls, site_hostname="127.0.0.1:5000"):
"""Compare generated links to expected links."""
expected_links = {
{% for link_name, link in test_constants.links_when_draft.items() %}
"{{ link_name }}": f"{{ link }}",
{% endfor %}
}
return expected_links.items() <= links.items()

def test_read_links_record(app, client_with_credentials, input_data, base_urls, sample_published_record, search_clear):
pid_value = sample_published_record["id"]
res = client_with_credentials.get(f"{base_urls['base_url']}{pid_value}")
Expand Down Expand Up @@ -292,4 +301,28 @@ def test_pagination_links(
base_url_user_search = (f"https://{site_hostname}/api/user{base_urls['base_url']}")

link_test(base_url_search, page_size, sort_search)
link_test(base_url_user_search, page_size, sort_search)
link_test(base_url_user_search, page_size, sort_search)


def test_when_draft_links(
app,
vocab_cf,
client_with_credentials,
input_data,
base_urls,
sample_draft,
sample_published_record,
search_clear,
):
draft_id = sample_draft["id"]
published_record_id = sample_published_record["id"]
draft_resp = client_with_credentials.get(f"{base_urls['base_url']}{draft_id}/draft")
published_record_resp = client_with_credentials.get(f"{base_urls['base_url']}{published_record_id}")

new_draft = client_with_credentials.post(f"{base_urls['base_url']}{published_record_id}/draft")
published_record_with_draft_resp = client_with_credentials.get(f"{base_urls['base_url']}{published_record_id}")

assert has_expected_links_when_has_draft(draft_id, draft_resp.json["links"], base_urls)
assert not has_expected_links_when_has_draft(published_record_id, published_record_resp.json["links"], base_urls)
assert has_expected_links_when_has_draft(published_record_id, published_record_with_draft_resp.json["links"], base_urls)

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.28
version = 4.0.29
description =
authors = Ronald Krist <krist@cesnet.cz>
readme = README.md
Expand Down

0 comments on commit 83fca1d

Please sign in to comment.