Skip to content

[ENG-8193] Fix issues with Preprint submission via API #11185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: feature/pbs-25-10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions api/actions/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.core.exceptions import ValidationError as DjangoValidationError
from guardian.shortcuts import get_objects_for_user
from rest_framework import generics
from rest_framework import permissions
from rest_framework.exceptions import NotFound, PermissionDenied
from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError

from api.actions.permissions import ReviewActionPermission
from api.actions.serializers import NodeRequestActionSerializer, ReviewActionSerializer, PreprintRequestActionSerializer
Expand Down Expand Up @@ -186,7 +187,10 @@ def perform_create(self, serializer):
),
)

serializer.save(user=self.request.user)
try:
serializer.save(user=self.request.user)
except (ValueError, DjangoValidationError) as exc:
raise ValidationError(str(exc)) from exc

# overrides ListFilterMixin
def get_default_queryset(self):
Expand Down
35 changes: 35 additions & 0 deletions api_tests/actions/views/test_action_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,38 @@ def test_invalid_target_id(self, app, moderator):
expect_errors=True
)
assert res.status_code == 404

def test_submit_preprint_without_files_returns_400(self, app, url, preprint, node_admin):
# Ensure preprint has no files
preprint.primary_file = None
preprint.save()

submit_payload = self.create_payload(
preprint._id,
trigger='submit'
)

res = app.post_json_api(
url,
submit_payload,
auth=node_admin.auth,
expect_errors=True
)
assert res.status_code == 400

def test_provider_not_reviewed_returns_409(self, app, url, preprint, node_admin):
preprint.provider = PreprintProviderFactory(reviews_workflow=None)
preprint.save()

submit_payload = self.create_payload(
preprint._id,
trigger='submit'
)

res = app.post_json_api(
url,
submit_payload,
auth=node_admin.auth,
expect_errors=True
)
assert res.status_code == 409
Loading