Skip to content

Commit

Permalink
fix some validation states
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jul 23, 2024
1 parent 1c4346e commit d1753c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
25 changes: 11 additions & 14 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,22 @@ def _validate_state(self, ev):
from django.core.exceptions import ValidationError
if not self.primary_file:
raise ValidationError('Cannot transition non-initial preprint without primary file.')

if not self.title:
raise ValidationError('Cannot publish a preprint without a title')
if self.is_retracted:
raise ValidationError('Cannot transition that has been retracted.')
if not self.provider:
raise ValidationError('Preprint provider not specified; cannot publish.')
if not self.subjects.exists():
raise ValidationError('Preprint must have at least one subject to be published.')

def _validate_submit(self, ev):
if not self.provider:
raise ValidationError('Preprint provider not specified; cannot publish.')
if not self.primary_file:
raise ValueError('Preprint doesn\'t have a primary file.')
if not (self.primary_file and self.primary_file.target == self):
raise ValueError('Preprint is not a valid preprint; cannot publish.')
if not self.title:
raise ValidationError('Cannot publish a preprint without a title')

assert self.provider.reviews_workflow

@property
def ever_published(self):
Expand All @@ -212,14 +217,6 @@ def perform_submit(self, ev):
self.ever_public = True
self.save()

def perform_post_mod_submission(self, ev):
action = self.actions.last()
now = action.created if action is not None else timezone.now()
self.date_published = now
self.is_published = True
self.ever_public = True
self.save()

@property
def pre_moderation(self):
from osf.utils.workflows import ModerationWorkflows
Expand Down Expand Up @@ -857,7 +854,7 @@ def get_doi_client(self):
return None

def save(self, *args, **kwargs):
saved_fields = self.get_dirty_fields() or []
saved_fields = self.get_dirty_fields()

if saved_fields and self.verified_publishable:
request, user_id = get_request_and_user_id()
Expand Down
8 changes: 4 additions & 4 deletions osf/utils/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,23 @@ class ModerationWorkflows(ModerationEnum):
'source': [PreprintStates.INITIAL],
'dest': PreprintStates.PENDING,
'conditions': 'pre_moderation',
'before': ['_validate_state'],
'before': ['_validate_submit'],
'after': ['notify_submit'],
},
{
'trigger': 'submit',
'source': [PreprintStates.INITIAL],
'dest': PreprintStates.PENDING,
'conditions': 'post_moderation',
'before': ['_validate_state'],
'after': ['perform_accept', 'notify_submit'],
'before': ['_validate_submit'],
'after': ['perform_submit', 'notify_submit'],
},
{
'trigger': 'submit',
'source': [PreprintStates.PENDING, PreprintStates.REJECTED],
'conditions': 'resubmission_allowed',
'dest': PreprintStates.PENDING,
'before': ['_validate_state'],
'before': ['_validate_submit'],
'after': ['notify_resubmit'],
},
{
Expand Down

0 comments on commit d1753c4

Please sign in to comment.