Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions site/cds_rdm/requests/ep_public_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2026 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the GPL-2.0 License; see LICENSE file for more details.

"""Helpers for creating a public record following an accepted EP Approval request."""

"""Create a public approved record from an approved draft.

Requires the calling user to be a community manager/owner of the
record's enrolled community.

Steps:
1. Read the approved draft — must have ep_approval.reportnumber set on parent.
2. Build a new public record: copy metadata + files, set access=public.
3. Create draft, import files, write ep_approval to both parents, publish.
4. Return the new public record id and links.
"""


from invenio_pidstore.models import PersistentIdentifier
from invenio_rdm_records.records.api import RDMRecord


def get_record_ep_approval(pid_value: str):
"""Return the EP Approval object for a record by PID."""
src_pid_obj = PersistentIdentifier.get("recid", pid_value)
src_rec_obj = RDMRecord.get_record(src_pid_obj.object_uuid)
ea = (src_rec_obj.parent.get("permission_flags") or {}).get("ep_approval") or {}
return ea
14 changes: 5 additions & 9 deletions site/cds_rdm/requests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from invenio_requests.proxies import current_requests_service
from invenio_requests.resolvers.registry import ResolverRegistry

from cds_rdm.requests.ep_public_record import get_record_ep_approval

from .ep_approval import EPApprovalRequest


Expand Down Expand Up @@ -99,10 +101,7 @@ def publish_public_record(pid_value):
return jsonify({"message": str(e)}), 403

# Read ep_approval from the internal draft's parent.
src_pid_obj = PersistentIdentifier.get("recid", pid_value)
src_rec_obj = RDMRecord.get_record(src_pid_obj.object_uuid)
ea = (src_rec_obj.parent.get("permission_flags") or {}).get("ep_approval") or {}
report_number = ea.get("reportnumber")
ea = get_record_ep_approval(pid_value)

if not report_number:
return jsonify({"message": "Record has no approved report number."}), 400
Expand All @@ -114,10 +113,9 @@ def publish_public_record(pid_value):
if not default_community_id:
return jsonify({"message": "Record has no default community."}), 400

identity = g.identity
allowed_roles = ("curator", "manager", "owner")
if not any(
CommunityRoleNeed(default_community_id, role) in identity.provides
CommunityRoleNeed(default_community_id, role) in g.identity.provides
for role in allowed_roles
):
return jsonify({"message": "Permission denied"}), 403
Expand All @@ -128,9 +126,7 @@ def publish_public_record(pid_value):
try:
appr_pid = PersistentIdentifier.get("recid", approved_version_recid)
appr_rec = RDMRecord.get_record(appr_pid.object_uuid)
cur_pid = PersistentIdentifier.get("recid", pid_value)
cur_rec = RDMRecord.get_record(cur_pid.object_uuid)
if cur_rec.versions.index < appr_rec.versions.index:
if src_rec_obj.versions.index < appr_rec.versions.index:
return (
jsonify(
{
Expand Down
Loading