Skip to content

Commit 83fca1d

Browse files
authored
Merge pull request #33 from oarepo/krist/be-287-change-the-links-for-drafts-html-pages-in-links-section
edit_html link; self_html link points to preview for draft
2 parents 8206a0e + 45bc9d0 commit 83fca1d

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

oarepo_model_builder_drafts/datatypes/components/draft.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,26 @@ def process_links(self, datatype, section: Section, **kwargs):
8686
link_args=[
8787
"cond=is_published_record",
8888
f'if_=RecordLink("{{+ui}}{html_url_prefix}{{id}}")',
89-
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/edit")',
89+
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/preview")',
9090
],
9191
imports=[
9292
Import("invenio_records_resources.services.ConditionalLink"),
9393
Import("invenio_records_resources.services.RecordLink"),
9494
Import("oarepo_runtime.records.is_published_record"),
9595
],
9696
),
97+
Link(
98+
name="edit_html",
99+
link_class="RecordLink",
100+
link_args=[
101+
f'"{{+ui}}{html_url_prefix}{{id}}/edit"',
102+
"when=has_draft",
103+
],
104+
imports=[
105+
Import("invenio_records_resources.services.RecordLink"),
106+
Import("oarepo_runtime.records.has_draft"),
107+
],
108+
),
97109
Link(
98110
name="latest",
99111
link_class="RecordLink",

oarepo_model_builder_drafts/datatypes/components/draft_tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def process_tests(self, datatype, section, **extra_kwargs):
3232
"publish": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft/actions/publish",
3333
"record": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}",
3434
"self": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft",
35-
"self_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/edit",
35+
"self_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/preview",
3636
"versions": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions",
3737
},
3838
"links_record": {
@@ -45,6 +45,9 @@ def process_tests(self, datatype, section, **extra_kwargs):
4545
"self_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}",
4646
"versions": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions",
4747
},
48+
"links_when_draft": {
49+
"edit_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/edit",
50+
},
4851
"page_size": "10",
4952
"sort_search": "newest",
5053
"sort_versions": "version",

oarepo_model_builder_drafts/tests/templates/invenio_test_resources.py.jinja2

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ def assert_expected_links_record(pid_value, links, base_urls, site_hostname="127
214214
}
215215
assert expected_links.items() <= links.items()
216216

217+
def has_expected_links_when_has_draft(pid_value, links, base_urls, site_hostname="127.0.0.1:5000"):
218+
"""Compare generated links to expected links."""
219+
expected_links = {
220+
{% for link_name, link in test_constants.links_when_draft.items() %}
221+
"{{ link_name }}": f"{{ link }}",
222+
{% endfor %}
223+
}
224+
return expected_links.items() <= links.items()
225+
217226
def test_read_links_record(app, client_with_credentials, input_data, base_urls, sample_published_record, search_clear):
218227
pid_value = sample_published_record["id"]
219228
res = client_with_credentials.get(f"{base_urls['base_url']}{pid_value}")
@@ -292,4 +301,28 @@ def test_pagination_links(
292301
base_url_user_search = (f"https://{site_hostname}/api/user{base_urls['base_url']}")
293302

294303
link_test(base_url_search, page_size, sort_search)
295-
link_test(base_url_user_search, page_size, sort_search)
304+
link_test(base_url_user_search, page_size, sort_search)
305+
306+
307+
def test_when_draft_links(
308+
app,
309+
vocab_cf,
310+
client_with_credentials,
311+
input_data,
312+
base_urls,
313+
sample_draft,
314+
sample_published_record,
315+
search_clear,
316+
):
317+
draft_id = sample_draft["id"]
318+
published_record_id = sample_published_record["id"]
319+
draft_resp = client_with_credentials.get(f"{base_urls['base_url']}{draft_id}/draft")
320+
published_record_resp = client_with_credentials.get(f"{base_urls['base_url']}{published_record_id}")
321+
322+
new_draft = client_with_credentials.post(f"{base_urls['base_url']}{published_record_id}/draft")
323+
published_record_with_draft_resp = client_with_credentials.get(f"{base_urls['base_url']}{published_record_id}")
324+
325+
assert has_expected_links_when_has_draft(draft_id, draft_resp.json["links"], base_urls)
326+
assert not has_expected_links_when_has_draft(published_record_id, published_record_resp.json["links"], base_urls)
327+
assert has_expected_links_when_has_draft(published_record_id, published_record_with_draft_resp.json["links"], base_urls)
328+

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = oarepo-model-builder-drafts
3-
version = 4.0.28
3+
version = 4.0.29
44
description =
55
authors = Ronald Krist <[email protected]>
66
readme = README.md

0 commit comments

Comments
 (0)