Skip to content

Commit 22a933a

Browse files
committed
config: make community request type classes customizable
* Allows to customize community submissions and inclusion request type classes via the ``RDM_COMMUNITY_SUBMISSION_REQUEST_CLS`` and ``RDM_COMMUNITY_INCLUSION_REQUEST_CLS`` config variables.
1 parent a339cfa commit 22a933a

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

invenio_rdm_records/config.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from invenio_rdm_records.services.components.verified import UserModerationHandler
2727

2828
from . import tokens
29+
from .requests.community_inclusion import CommunityInclusion
30+
from .requests.community_submission import CommunitySubmission
2931
from .resources.serializers import DataCite43JSONSerializer
3032
from .services import facets
3133
from .services.config import lock_edit_published_files
@@ -124,8 +126,11 @@ def always_valid(identifier):
124126
# Record review requests
125127
#
126128
RDM_RECORDS_REVIEWS = [
127-
"community-submission",
129+
CommunitySubmission.type_id,
128130
]
131+
"""List of review request types."""
132+
RDM_COMMUNITY_SUBMISSION_REQUEST_CLS = CommunitySubmission
133+
"""Request type for community submission requests."""
129134

130135
#
131136
# Record files configuration
@@ -147,6 +152,8 @@ def always_valid(identifier):
147152
#
148153
RDM_COMMUNITY_REQUIRED_TO_PUBLISH = False
149154
"""Enforces at least one community per record."""
155+
RDM_COMMUNITY_INCLUSION_REQUEST_CLS = CommunityInclusion
156+
"""Request type for record inclusion requests."""
150157

151158
#
152159
# Search configuration

invenio_rdm_records/requests/community_inclusion.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from invenio_notifications.services.uow import NotificationOp
1313
from invenio_records_resources.services.uow import RecordIndexOp
1414
from invenio_requests.customizations import RequestType, actions
15-
from invenio_requests.errors import CannotExecuteActionError
1615

1716
from invenio_rdm_records.notifications.builders import (
1817
CommunityInclusionAcceptNotificationBuilder,
@@ -68,7 +67,7 @@ def execute(self, identity, uow, **kwargs):
6867
parent_community = getattr(community, "parent", None)
6968
if (
7069
parent_community
71-
and not str(parent_community.id) in record.parent.communities.ids
70+
and str(parent_community.id) not in record.parent.communities.ids
7271
):
7372
record.parent.communities.add(parent_community, request=self.request)
7473

@@ -120,3 +119,15 @@ class CommunityInclusion(RequestType):
120119
"cancel": actions.CancelAction,
121120
"expire": actions.ExpireAction,
122121
}
122+
123+
124+
def get_request_type(app):
125+
"""Return the community inclusion request type from config.
126+
127+
This function is only used to register the request type via the
128+
``invenio_requests.types`` entrypoint, and allow to customize the request type
129+
class via the ``RDM_COMMUNITY_INCLUSION_REQUEST_CLS`` application config.
130+
"""
131+
if not app:
132+
return
133+
return app.config.get("RDM_COMMUNITY_INCLUSION_REQUEST_CLS", CommunityInclusion)

invenio_rdm_records/requests/community_submission.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,15 @@ class CommunitySubmission(ReviewRequest):
204204
"cancel": CancelAction,
205205
"expire": ExpireAction,
206206
}
207+
208+
209+
def get_request_type(app):
210+
"""Return the community submission request type from config.
211+
212+
This function is only used to register the request type via the
213+
``invenio_requests.types`` entrypoint, and allow to customize the request type
214+
class via the ``RDM_COMMUNITY_SUBMISSION_REQUEST_CLS`` application config.
215+
"""
216+
if not app:
217+
return
218+
return app.config.get("RDM_COMMUNITY_SUBMISSION_REQUEST_CLS", CommunitySubmission)

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ invenio_search.mappings =
123123
invenio_i18n.translations =
124124
invenio_rdm_records = invenio_rdm_records
125125
invenio_requests.types =
126-
community_inclusion = invenio_rdm_records.requests:CommunityInclusion
127-
community_submission = invenio_rdm_records.requests:CommunitySubmission
126+
community_inclusion = invenio_rdm_records.requests.community_inclusion:get_request_type
127+
community_submission = invenio_rdm_records.requests.community_submission:get_request_type
128128
user_access_request = invenio_rdm_records.requests:UserAccessRequest
129129
guest_access_request = invenio_rdm_records.requests:GuestAccessRequest
130130
invenio_requests.entity_resolvers =

0 commit comments

Comments
 (0)