Skip to content

Commit 81f0872

Browse files
committed
Record: Improve handling of draft classes in RecordCommunitiesService
* Records: catch PIDUnregistered error * Add draft class to RecordCommunitiesService * Closes inveniosoftware/invenio-app-rdm#2857
1 parent 22f3455 commit 81f0872

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.
@@ -17,7 +18,7 @@
1718
)
1819
from invenio_i18n import lazy_gettext as _
1920
from invenio_notifications.services.uow import NotificationOp
20-
from invenio_pidstore.errors import PIDDoesNotExistError
21+
from invenio_pidstore.errors import PIDDoesNotExistError, PIDUnregistered
2122
from invenio_records_resources.services import (
2223
RecordIndexerMixin,
2324
Service,
@@ -67,6 +68,11 @@ def record_cls(self):
6768
"""Factory for creating a record class."""
6869
return self.config.record_cls
6970

71+
@property
72+
def draft_cls(self):
73+
"""Factory for creating a draft class."""
74+
return self.config.draft_cls
75+
7076
def _exists(self, community_id, record):
7177
"""Return the request id if an open request already exists, else None."""
7278
results = current_requests_service.search(
@@ -264,7 +270,10 @@ def search(
264270
**kwargs,
265271
):
266272
"""Search for record's communities."""
267-
record = self.record_cls.pid.resolve(id_)
273+
try:
274+
record = self.record_cls.pid.resolve(id_)
275+
except PIDUnregistered:
276+
record = self.draft_cls.pid.resolve(id_, registered_only=False)
268277
self.require_permission(identity, "read", record=record)
269278

270279
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.
@@ -260,6 +261,7 @@ class RDMRecordCommunitiesConfig(ServiceConfig, ConfiguratorMixin):
260261
service_id = "record-communities"
261262

262263
record_cls = FromConfig("RDM_RECORD_CLS", default=RDMRecord)
264+
draft_cls = FromConfig("RDM_DRAFT_CLS", default=RDMDraft)
263265
permission_policy_cls = FromConfig(
264266
"RDM_PERMISSION_POLICY", default=RDMRecordPermissionPolicy, import_string=True
265267
)

0 commit comments

Comments
 (0)