Skip to content

Commit

Permalink
Services: Records: Raise CommunityNotSelectedError when community is …
Browse files Browse the repository at this point in the history
…required
  • Loading branch information
sakshamarora1 committed Sep 16, 2024
1 parent a5bb49b commit eec0529
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions invenio_drafts_resources/services/records/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from invenio_records_resources.services import LinksTemplate
from invenio_records_resources.services import RecordService as RecordServiceBase
from invenio_records_resources.services import ServiceSchemaWrapper
from invenio_records_resources.services.errors import CommunityNotSelectedError
from invenio_records_resources.services.uow import (
RecordBulkIndexOp,
RecordCommitOp,
Expand Down Expand Up @@ -375,6 +376,15 @@ def publish(self, identity, id_, uow=None, expand=False):
"""
# Get the draft
draft = self.draft_cls.pid.resolve(id_, registered_only=False)

# If config is True and there are no communities selected
# Then, check for permissions to upload without community
if (
current_app.config["RDM_RECORD_ALWAYS_IN_COMMUNITY"]
and len(draft.parent.communities.ids) == 0
):
if not self.check_permission(identity, "publish", record=draft):
raise CommunityNotSelectedError()
self.require_permission(identity, "publish", record=draft)

# Validate the draft strictly - since a draft can be saved with errors
Expand Down

0 comments on commit eec0529

Please sign in to comment.