Skip to content

Commit

Permalink
fix: publish draft request created even if there are no files on the …
Browse files Browse the repository at this point in the history
…record
  • Loading branch information
mesemus committed Nov 28, 2024
1 parent d74fa20 commit a341cb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions oarepo_requests/types/publish_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import TYPE_CHECKING, Any

import marshmallow as ma
from invenio_access.permissions import system_identity
from invenio_records_resources.services.uow import RecordCommitOp, UnitOfWork
from invenio_requests.proxies import current_requests_service
from oarepo_runtime.datastreams.utils import get_record_service_for_record
Expand Down Expand Up @@ -97,7 +96,24 @@ def can_create(
raise ValueError("Trying to create publish request on published record")
super().can_create(identity, data, receiver, topic, creator, *args, **kwargs)
topic_service = get_record_service_for_record(topic)
topic_service.validate_draft(system_identity, topic["id"])
topic_service.validate_draft(identity, topic["id"])

can_toggle_files = topic_service.check_permission(
identity, "manage_files", record=topic
)

draft_files = topic.files # type: ignore

if draft_files.enabled and not draft_files.items():
if can_toggle_files:
my_message = _(
"Missing uploaded files. To disable files for this record please mark it as metadata-only."
)
else:
my_message = _("Missing uploaded files.")

raise ma.ValidationError({"files.enabled": [my_message]})


@classmethod
def is_applicable_to(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-requests
version = 2.3.2
version = 2.3.3
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit a341cb5

Please sign in to comment.