@@ -404,7 +404,7 @@ def check_unfinished_or_unpublished_version(self):
404
404
return None , None
405
405
406
406
@classmethod
407
- def create_version (cls , create_from_guid , auth , assign_version_number = None , ignore_permission = False ):
407
+ def create_version (cls , create_from_guid , auth , assign_version_number = None , ignore_permission = False , ignore_existing_versions = False ):
408
408
"""Create a new version for a given preprint. `create_from_guid` can be any existing versions of the preprint
409
409
but `create_version` always finds the latest version and creates a new version from it. In addition, this
410
410
creates an "incomplete" new preprint version object using the model class and returns both the new object and
@@ -425,19 +425,21 @@ def create_version(cls, create_from_guid, auth, assign_version_number=None, igno
425
425
sentry .log_message (f'ADMIN permission for the latest version is required to create a new version: '
426
426
f'[user={ auth .user ._id } , guid={ guid_obj ._id } , latest_version={ latest_version ._id } ]' )
427
427
raise PermissionsError
428
- unfinished_version , unpublished_version = latest_version .check_unfinished_or_unpublished_version ()
429
- if unpublished_version :
430
- logger .error ('Failed to create a new version due to unpublished pending version already exists: '
431
- f'[version={ unpublished_version .version } , '
432
- f'_id={ unpublished_version ._id } , '
433
- f'state={ unpublished_version .machine_state } ].' )
434
- raise UnpublishedPendingPreprintVersionExists
435
- if unfinished_version :
436
- logger .warning (f'Use existing initiated but unfinished version instead of creating a new one: '
437
- f'[version={ unfinished_version .version } , '
438
- f'_id={ unfinished_version ._id } , '
439
- f'state={ unfinished_version .machine_state } ].' )
440
- return unfinished_version , None
428
+ if not ignore_existing_versions :
429
+ unfinished_version , unpublished_version = latest_version .check_unfinished_or_unpublished_version ()
430
+ if unpublished_version :
431
+ message = ('Failed to create a new version due to unpublished pending version already exists: '
432
+ f'[version={ unpublished_version .version } , '
433
+ f'_id={ unpublished_version ._id } , '
434
+ f'state={ unpublished_version .machine_state } ].' )
435
+ logger .error (message )
436
+ raise UnpublishedPendingPreprintVersionExists (message )
437
+ if unfinished_version :
438
+ logger .warning (f'Use existing initiated but unfinished version instead of creating a new one: '
439
+ f'[version={ unfinished_version .version } , '
440
+ f'_id={ unfinished_version ._id } , '
441
+ f'state={ unfinished_version .machine_state } ].' )
442
+ return unfinished_version , None
441
443
442
444
# Prepare the data to clone/update
443
445
data_to_update = {
@@ -536,7 +538,13 @@ def create_version(cls, create_from_guid, auth, assign_version_number=None, igno
536
538
guid_obj .save ()
537
539
538
540
if latest_version .node :
539
- preprint .set_supplemental_node (latest_version .node , auth , save = False , ignore_node_permissions = True )
541
+ preprint .set_supplemental_node (
542
+ latest_version .node ,
543
+ auth ,
544
+ save = False ,
545
+ ignore_node_permissions = True ,
546
+ ignore_permission = ignore_permission
547
+ )
540
548
541
549
return preprint , data_to_update
542
550
0 commit comments