Skip to content

Commit cd38c97

Browse files
committed
Record: Improve handling of draft PID in RecordCommunitiesService (#1822)
* Records: catch PIDUnregistered error * Add draft class to RecordCommunitiesService * Closes inveniosoftware/invenio-app-rdm#2857
1 parent d87426d commit cd38c97

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

invenio_rdm_records/services/communities/service.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Copyright (C) 2023-2024 CERN.
4-
# Copyright (C) 2024 Graz University of Technology.
4+
# Copyright (C) 2024 Graz University of Technology.
5+
# Copyright (C) 2024 KTH Royal Institute of Technology.
56
#
67
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
78
# it under the terms of the MIT License; see LICENSE file for more details.
@@ -16,7 +17,7 @@
1617
)
1718
from invenio_i18n import lazy_gettext as _
1819
from invenio_notifications.services.uow import NotificationOp
19-
from invenio_pidstore.errors import PIDDoesNotExistError
20+
from invenio_pidstore.errors import PIDDoesNotExistError, PIDUnregistered
2021
from invenio_records_resources.services import (
2122
RecordIndexerMixin,
2223
Service,
@@ -65,6 +66,11 @@ def record_cls(self):
6566
"""Factory for creating a record class."""
6667
return self.config.record_cls
6768

69+
@property
70+
def draft_cls(self):
71+
"""Factory for creating a draft class."""
72+
return self.config.draft_cls
73+
6874
def _exists(self, community_id, record):
6975
"""Return the request id if an open request already exists, else None."""
7076
results = current_requests_service.search(
@@ -246,7 +252,10 @@ def search(
246252
**kwargs,
247253
):
248254
"""Search for record's communities."""
249-
record = self.record_cls.pid.resolve(id_)
255+
try:
256+
record = self.record_cls.pid.resolve(id_)
257+
except PIDUnregistered:
258+
record = self.draft_cls.pid.resolve(id_, registered_only=False)
250259
self.require_permission(identity, "read", record=record)
251260

252261
communities_ids = record.parent.communities.ids

invenio_rdm_records/services/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# Copyright (C) 2020-2021 Northwestern University.
55
# Copyright (C) 2021 TU Wien.
66
# Copyright (C) 2021-2023 Graz University of Technology.
7-
# Copyright (C) 2022 Universität Hamburg
7+
# Copyright (C) 2022 Universität Hamburg
8+
# Copyright (C) 2024 KTH Royal Institute of Technology.
89
#
910
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
1011
# it under the terms of the MIT License; see LICENSE file for more details.
@@ -195,6 +196,7 @@ class RDMRecordCommunitiesConfig(ServiceConfig, ConfiguratorMixin):
195196
service_id = "record-communities"
196197

197198
record_cls = FromConfig("RDM_RECORD_CLS", default=RDMRecord)
199+
draft_cls = FromConfig("RDM_DRAFT_CLS", default=RDMDraft)
198200
permission_policy_cls = FromConfig(
199201
"RDM_PERMISSION_POLICY", default=RDMRecordPermissionPolicy, import_string=True
200202
)

0 commit comments

Comments
 (0)