From fbc7e69a11876d746f61db445b06db265d831111 Mon Sep 17 00:00:00 2001 From: zzacharo Date: Wed, 18 Nov 2026 15:58:50 +0000 Subject: [PATCH 1/2] fix(committee-approval): send requests to the enrollment's referee group The committee approval endpoint took the receiver group from the request body, so an API client could send the request to any group. That group could then accept it and get an approval report number. * views: ignore any client-provided receiver_group and use the referee group of the record community's enrollment. Return a 400 with a clear message when the community is not enrolled, instead of a bare 403. * submit action: refuse a request whose receiver is not the enrollment's referee group, which also covers callers that create the request through the service directly. * tests: cover a request sent to another group. Co-Authored-By: Claude Opus 5.5 --- site/cds_rdm/requests/committee_approval.py | 8 ++++++ site/cds_rdm/requests/views.py | 31 +++++++++++++-------- site/tests/test_committee_approval.py | 23 +++++++++++++++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/site/cds_rdm/requests/committee_approval.py b/site/cds_rdm/requests/committee_approval.py index 13c2cb47..686355d2 100644 --- a/site/cds_rdm/requests/committee_approval.py +++ b/site/cds_rdm/requests/committee_approval.py @@ -105,6 +105,14 @@ def execute(self, identity: Identity, uow: UnitOfWork) -> None: # the request is persisted as submitted. enrollment = _resolve_enrollment(self.request) + # Only the enrollment's referee group may receive (and so accept) the + # request, whatever receiver the caller passed. + if self.request.receiver.reference_dict != {"group": enrollment.referee_group}: + raise ValidationError( + "Committee approval requests must be sent to the community's " + "referee group." + ) + # Reject if the parent already carries an approval report number. if ( topic.parent.get("permission_flags", {}) diff --git a/site/cds_rdm/requests/views.py b/site/cds_rdm/requests/views.py index d26b8453..6b943f7e 100644 --- a/site/cds_rdm/requests/views.py +++ b/site/cds_rdm/requests/views.py @@ -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) 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={ diff --git a/site/tests/test_committee_approval.py b/site/tests/test_committee_approval.py index a3113af3..24078a3d 100644 --- a/site/tests/test_committee_approval.py +++ b/site/tests/test_committee_approval.py @@ -695,6 +695,29 @@ def test_committee_approval_submit_permissions( assert request.data["status"] == "submitted" +def test_committee_approval_submit_rejects_other_receiver_group( + record_in_enrolled_community, + community_manager, + ep_referee_group, + ep_request_payload, + app, + db, +): + """A request sent to any group but the enrollment's referee group is refused.""" + ds = app.extensions["invenio-accounts"].datastore + ds.create_role(id="not-the-referees", name="not-the-referees") + db.session.commit() + + with pytest.raises(ValidationError, match="referee group"): + current_requests_service.create( + identity=community_manager.identity, + data=ep_request_payload, + request_type=current_request_type_registry.lookup("committee-approval"), + receiver={"group": "not-the-referees"}, + topic={"record": record_in_enrolled_community.id}, + ) + + # --------------------------------------------------------------------------- # Permissions: who can read an EP approval request # --------------------------------------------------------------------------- From 85185d9d79ba2b014bf879d100f34fd11b7b43cf Mon Sep 17 00:00:00 2001 From: zzacharo Date: Wed, 18 Nov 2026 15:58:50 +0000 Subject: [PATCH 2/2] fix(publish-public): keep cdsrn as related identifier on the public record Creating the public record copied the CDS report numbers (cdsrn) of the restricted record into its identifiers. Report numbers are unique per record, so publishing failed with "The CDS report number ... is already taken" for every paper that carries its own report number. The public record now leaves cdsrn out of its identifiers and gets each one as a related identifier (scheme cdsrn, relation isvariantformof), the same shape the INSPIRE harvester writes and matches on. The restricted record keeps the report numbers. Co-Authored-By: Claude Opus 5.5 --- site/cds_rdm/requests/views.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/site/cds_rdm/requests/views.py b/site/cds_rdm/requests/views.py index 6b943f7e..c0591e81 100644 --- a/site/cds_rdm/requests/views.py +++ b/site/cds_rdm/requests/views.py @@ -185,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", [])) @@ -199,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,