Skip to content

Commit

Permalink
Merge pull request #44 from oarepo/krist/be-503-new-version-request-u…
Browse files Browse the repository at this point in the history
…ser-is-not-redirected-to-the-new

Krist/be 503 new version request user is not redirected to the new
  • Loading branch information
mesemus authored Dec 5, 2024
2 parents fb85c13 + 099ec20 commit 7a9fb0e
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: Cache pip
uses: actions/cache@v4
with:
Expand Down
139 changes: 116 additions & 23 deletions oarepo_model_builder_drafts/datatypes/components/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def process_links(self, datatype, section: Section, **kwargs):

if datatype.root.profile == "record":
remove_links_by_names(section.config["links_item"], {"self", "self_html"})
remove_links_by_names(
section.config["links_search_item"], {"self", "self_html"}
)

section.config["links_search_drafts"] = [
Link(
Expand All @@ -52,6 +55,14 @@ def process_links(self, datatype, section: Section, **kwargs):
Import("invenio_records_resources.services.pagination_links")
],
),
Link(
name=None,
link_class="pagination_links_html",
link_args=[f'"{{+ui}}/user{url_prefix}{{?args*}}"'],
imports=[
Import("oarepo_runtime.services.records.pagination_links_html")
],
),
]

section.config["links_search_versions"] = [
Expand All @@ -70,77 +81,159 @@ def process_links(self, datatype, section: Section, **kwargs):
name="self",
link_class="ConditionalLink",
link_args=[
"cond=is_published_record",
f'if_=RecordLink("{{+api}}{url_prefix}{{id}}")',
f'else_=RecordLink("{{+api}}{url_prefix}{{id}}/draft")',
"cond=is_published_record()",
f'if_=RecordLink("{{+api}}{url_prefix}{{id}}"',
'when=has_permission("read"))',
f'else_=RecordLink("{{+api}}{url_prefix}{{id}}/draft"',
'when=has_permission("read_draft"))',
],
imports=[
Import("invenio_records_resources.services.ConditionalLink"),
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.records.is_published_record"),
Import("oarepo_runtime.services.config.is_published_record"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="self_html",
link_class="ConditionalLink",
link_args=[
"cond=is_published_record",
f'if_=RecordLink("{{+ui}}{html_url_prefix}{{id}}")',
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/preview")',
"cond=is_published_record()",
f'if_=RecordLink("{{+ui}}{html_url_prefix}{{id}}"',
'when=has_permission("read"))',
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/preview"',
'when=has_permission("read_draft"))',
],
imports=[
Import("invenio_records_resources.services.ConditionalLink"),
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.records.is_published_record"),
Import("oarepo_runtime.services.config.is_published_record"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="edit_html",
link_class="RecordLink",
link_args=[
f'"{{+ui}}{html_url_prefix}{{id}}/edit"',
"when=has_draft",
'when=has_draft() & has_permission("read_draft")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.records.has_draft"),
Import("oarepo_runtime.services.config.has_draft"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="latest",
link_class="RecordLink",
link_args=[f'"{{+api}}{url_prefix}{{id}}/versions/latest"'],
imports=[Import("invenio_records_resources.services.RecordLink")],
link_args=[
f'"{{+api}}{url_prefix}{{id}}/versions/latest"',
'when=has_permission("read")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="latest_html",
link_class="RecordLink",
link_args=[f'"{{+ui}}{html_url_prefix}{{id}}/latest"'],
imports=[Import("invenio_records_resources.services.RecordLink")],
link_args=[
f'"{{+ui}}{html_url_prefix}{{id}}/latest"',
'when=has_permission("read")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="draft",
link_class="RecordLink",
link_args=[f'"{{+api}}{url_prefix}{{id}}/draft"'],
imports=[Import("invenio_records_resources.services.RecordLink")],
link_args=[
f'"{{+api}}{url_prefix}{{id}}/draft"',
'when=has_draft() & has_permission("read_draft")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="record",
name="record", # this links to self or record with the same id as draft for drafts; but perhaps discuss whether this is optimal
# desired behavioral; ie. it could also link last version if the record isn't available
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_published_record() & has_permission("read")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.has_permission"),
Import("oarepo_runtime.services.config.has_published_record"),
],
),
Link(
name="publish",
link_class="RecordLink",
link_args=[f'"{{+api}}{url_prefix}{{id}}/draft/actions/publish"'],
imports=[Import("invenio_records_resources.services.RecordLink")],
link_args=[
f'"{{+api}}{url_prefix}{{id}}/draft/actions/publish"',
'when=has_permission("publish")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="versions",
link_class="RecordLink",
link_args=[f'"{{+api}}{url_prefix}{{id}}/versions"'],
imports=[Import("invenio_records_resources.services.RecordLink")],
link_args=[
f'"{{+api}}{url_prefix}{{id}}/versions"',
'when=has_permission("search_versions")',
],
imports=[
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
]

section.config["links_search_item"] += [
Link(
name="self",
link_class="ConditionalLink",
link_args=[
"cond=is_published_record()",
f'if_=RecordLink("{{+api}}{url_prefix}{{id}}"',
'when=has_permission("read"))',
f'else_=RecordLink("{{+api}}{url_prefix}{{id}}/draft"',
'when=has_permission("read_draft"))',
],
imports=[
Import("invenio_records_resources.services.ConditionalLink"),
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.is_published_record"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
Link(
name="self_html",
link_class="ConditionalLink",
link_args=[
"cond=is_published_record()",
f'if_=RecordLink("{{+ui}}{html_url_prefix}{{id}}"',
'when=has_permission("read"))',
f'else_=RecordLink("{{+ui}}{html_url_prefix}{{id}}/preview"',
'when=has_permission("read_draft"))',
],
imports=[
Import("invenio_records_resources.services.ConditionalLink"),
Import("invenio_records_resources.services.RecordLink"),
Import("oarepo_runtime.services.config.is_published_record"),
Import("oarepo_runtime.services.config.has_permission"),
],
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ def process_tests(self, datatype, section, **extra_kwargs):
"latest": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions/latest",
"latest_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/latest",
"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}",
"versions": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions",
"self": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft",
"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": {
"draft": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft",
"latest": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions/latest",
"latest_html": "https://{site_hostname}{base_urls['base_html_url']}{pid_value}/latest",
"publish": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/draft/actions/publish",
"versions": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}/versions",
"record": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}",
"self": "https://{site_hostname}/api{base_urls['base_url']}{pid_value}",
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,16 @@ def test_read_links_record(app, client_with_credentials, input_data, base_urls,

assert_expected_links_record(pid_value, res.json["links"], base_urls)

def test_draft_listing_links(app, vocab_cf, client_with_login, base_urls, sample_draft_with_owner, search_clear):
def test_draft_listing_links(
app, vocab_cf, client_with_login, base_urls, sample_draft_with_owner, search_clear, site_hostname="127.0.0.1:5000"
):
ThesisDraft.index.refresh()
res = client_with_login.get(f"/user{base_urls['base_url']}")
assert_expected_links(
sample_draft_with_owner["id"], res.json["hits"]["hits"][0]["links"], base_urls
)
links = res.json["hits"]["hits"][0]["links"]
assert links == {
"self": f"https://{site_hostname}/api{base_urls['base_url']}{sample_draft_with_owner["id"]}/draft",
"self_html": f"https://{site_hostname}{base_urls['base_html_url']}{sample_draft_with_owner["id"]}/preview"
}

def test_pagination_links(
app,
Expand Down
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.35
version = 4.0.36
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 7a9fb0e

Please sign in to comment.