Repository navigation
fix(publish-public): keep internal cdsrn as related idenitfier in the… #1083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zzacharo
wants to merge
2
commits into
CERNDocumentServer:master
Choose a base branch
from
zzacharo:fix-cdsrn-on-publish-public
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,25 +50,34 @@ def submit_committee_approval(pid_value): | |
| return jsonify({"message": str(e)}), 409 | ||
|
|
||
| body = request.get_json(force=True) or {} | ||
| receiver_group = body.pop("receiver_group", None) | ||
| # The receiver always comes from the community's enrollment. A | ||
| # client-provided ``receiver_group`` is ignored so that callers cannot | ||
| # route the request (and its accept action) to a group of their choice. | ||
| body.pop("receiver_group", None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't the request body validated against a schema where the existence of this field could raise a validation error? |
||
| payload = body.get("payload", {}) | ||
|
|
||
| if not receiver_group: | ||
| return jsonify({"message": "receiver_group is required"}), 400 | ||
| default_community_id = (record._record.parent.get("communities", {}) or {}).get( | ||
| "default" | ||
| ) | ||
| enrollment = get_committee_approval_enrollment(default_community_id) | ||
| if not enrollment: | ||
| return ( | ||
| jsonify( | ||
| { | ||
| "message": "The record's community is not enrolled in the " | ||
| "committee approval workflow." | ||
| } | ||
| ), | ||
| 400, | ||
| ) | ||
|
|
||
| try: | ||
| # Resolve receiver group entity. | ||
| receiver = ResolverRegistry.resolve_entity( | ||
| {"group": receiver_group}, raise_=True | ||
| {"group": enrollment.referee_group}, raise_=True | ||
| ) | ||
|
|
||
| title = record.data.get("metadata", {}).get("title", "") | ||
| default_community_id = ( | ||
| record._record.parent.get("communities", {}) or {} | ||
| ).get("default") | ||
| enrollment = get_committee_approval_enrollment(default_community_id) | ||
| approval_label = (enrollment and enrollment.label) or "Committee approval" | ||
| payload["approval_label"] = approval_label | ||
| payload["approval_label"] = enrollment.label or "Committee approval" | ||
| req = current_requests_service.create( | ||
| identity=g.identity, | ||
| data={ | ||
|
|
@@ -176,12 +185,15 @@ def publish_public_record(pid_value): | |
| src = draft_record.data | ||
| src_id = src["id"] | ||
|
|
||
| src_identifiers = src.get("metadata", {}).get("identifiers", []) | ||
| src_resource_type = src.get("metadata", {}).get("resource_type") | ||
|
|
||
| # Strip apprn from identifiers — CommitteeApprovalComponent regenerates it | ||
| # from committee_approval.reportnumber on every update_draft / publish. | ||
| # Strip cdsrn too: CDS report numbers are unique per record and stay on | ||
| # the restricted record. They are added below as related identifiers. | ||
| new_identifiers = [ | ||
| i | ||
| for i in src.get("metadata", {}).get("identifiers", []) | ||
| if i.get("scheme") != "apprn" | ||
| i for i in src_identifiers if i.get("scheme") not in ("apprn", "cdsrn") | ||
| ] | ||
|
|
||
| new_related = list(src.get("metadata", {}).get("related_identifiers", [])) | ||
|
|
@@ -190,11 +202,25 @@ def publish_public_record(pid_value): | |
| "scheme": "cds", | ||
| "relation_type": {"id": "isversionof"}, | ||
| } | ||
| src_resource_type = src.get("metadata", {}).get("resource_type") | ||
| if src_resource_type: | ||
| isversionof_entry["resource_type"] = src_resource_type | ||
| new_related.append(isversionof_entry) | ||
|
|
||
| # Keep the report numbers findable on the public record, in the same | ||
| # shape the INSPIRE harvester writes and matches (related cdsrn, | ||
| # isvariantformof). | ||
| for identifier in src_identifiers: | ||
| if identifier.get("scheme") != "cdsrn": | ||
| continue | ||
| report_number_entry = { | ||
| "identifier": identifier["identifier"], | ||
| "scheme": "cdsrn", | ||
| "relation_type": {"id": "isvariantformof"}, | ||
| } | ||
| if src_resource_type: | ||
| report_number_entry["resource_type"] = src_resource_type | ||
| new_related.append(report_number_entry) | ||
|
|
||
| new_metadata = { | ||
| **copy.deepcopy(src.get("metadata", {})), | ||
| "identifiers": new_identifiers, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user provided
receiver_groupis popped inviews.pyis this even a possibility?