Skip to content

Commit

Permalink
Merge pull request #92 from oarepo/miroslavsimek/be-572-oarepo-publis…
Browse files Browse the repository at this point in the history
…h-action-fails-if-record-does-not-have-file

fix: file check fails if files are not enabled for topic
  • Loading branch information
mesemus authored Nov 29, 2024
2 parents 68031d4 + 5ae5a91 commit 97c1448
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions oarepo_requests/types/publish_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,22 @@ def validate_topic(cls, identity: Identity, topic: Record) -> None:
"""
topic_service = get_record_service_for_record(topic)
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]})

# if files support is enabled for this topic, check if there are any files
if hasattr(topic, "files"):
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.3
version = 2.3.4
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 97c1448

Please sign in to comment.