1
1
import pytz
2
2
import json
3
+
4
+ from api .waffle .utils import flag_is_active
5
+ from osf import features
3
6
from website .archiver .utils import normalize_unicode_filenames
4
7
5
8
from packaging .version import Version
@@ -83,7 +86,6 @@ class RegistrationSerializer(NodeSerializer):
83
86
'has_supplements' ,
84
87
])
85
88
86
- manual_guid = ser .CharField (write_only = True , required = False , allow_null = True )
87
89
ia_url = ser .URLField (read_only = True )
88
90
reviews_state = ser .CharField (source = 'moderation_state' , read_only = True )
89
91
title = ser .CharField (required = False )
@@ -734,6 +736,10 @@ def __init__(self, *args, **kwargs):
734
736
else :
735
737
self .fields ['draft_registration' ] = ser .CharField (write_only = True )
736
738
739
+ # For manual GUID and DOI assignment during creation for privileged users
740
+ manual_guid = ser .CharField (write_only = True , required = False , allow_null = True )
741
+ manual_doi = ser .CharField (write_only = True , required = False , allow_null = True )
742
+
737
743
# For newer versions
738
744
embargo_end_date = VersionedDateTimeField (write_only = True , allow_null = True , default = None )
739
745
included_node_ids = ser .ListField (write_only = True , required = False )
@@ -788,7 +794,7 @@ def get_children_by_version(self, validated_data):
788
794
789
795
def create (self , validated_data ):
790
796
791
- guid_str = validated_data .pop ('manual_guid' , None )
797
+ manual_guid = validated_data .pop ('manual_guid' , None )
792
798
auth = get_user_auth (self .context ['request' ])
793
799
draft = validated_data .pop ('draft' , None )
794
800
registration_choice = self .get_registration_choice_by_version (validated_data )
@@ -813,7 +819,7 @@ def create(self, validated_data):
813
819
)
814
820
815
821
try :
816
- registration = draft .register (auth , save = True , child_ids = children , guid_str = guid_str )
822
+ registration = draft .register (auth , save = True , child_ids = children , manual_guid = manual_guid )
817
823
except NodeStateError as err :
818
824
raise exceptions .ValidationError (err )
819
825
@@ -826,6 +832,11 @@ def create(self, validated_data):
826
832
except ValidationError as err :
827
833
raise exceptions .ValidationError (err .message )
828
834
else :
835
+ manual_doi = validated_data .pop ('manual_doi' , None )
836
+ if manual_doi :
837
+ if not flag_is_active (self .context ['request' ], features .MANUAL_DOI_AND_GUID ):
838
+ raise exceptions .ValidationError (detail = 'Manual DOI assignment is not allowed.' )
839
+ registration .set_identifier_value ('doi' , manual_doi )
829
840
try :
830
841
registration .require_approval (auth .user )
831
842
except NodeStateError as err :
0 commit comments