Skip to content

Commit

Permalink
decorator: updates pass_record_or_draft
Browse files Browse the repository at this point in the history
* allows to pass the parent id and returns the latest version
* requires inveniosoftware/invenio-drafts-resources#240
* closes zenodo/rdm-project#174
  • Loading branch information
jrcastro2 committed Aug 8, 2023
1 parent 554c5c9 commit 27976ec
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions invenio_app_rdm/records_ui/views/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from functools import wraps

from flask import g, request
from flask import g, redirect, request, url_for
from invenio_communities.communities.resources.serializer import (
UICommunityJSONSerializer,
)
Expand Down Expand Up @@ -130,8 +130,17 @@ def view(**kwargs):
except NoResultFound:
record = service().read(**read_kwargs)
else:
record = service().read(**read_kwargs)

try:
record = service().read(**read_kwargs)
except NoResultFound:
# If the parent pid is being used we can get the id of the latest record and redirect
latest_version = service().read_latest(**read_kwargs)
return redirect(
url_for(
"invenio_app_rdm_records.record_detail",
pid_value=latest_version.id,
)
)
kwargs["record"] = record
return f(**kwargs)

Expand Down

0 comments on commit 27976ec

Please sign in to comment.