@@ -1225,6 +1225,30 @@ def set_privacy(self, permissions, auth=None, log=True, save=True, meeting_creat
12251225 # Embargoed registrations can be made public early
12261226 self .request_embargo_termination (auth .user )
12271227 return False
1228+
1229+ if not self .get_identifier_value ('doi' ):
1230+ try :
1231+ doi = self .request_identifier ('doi' )['doi' ]
1232+ self .set_identifier_value ('doi' , doi )
1233+ except Exception as e :
1234+ from osf .models .admin_log_entry import update_admin_log , DOI_CREATION_FAILED
1235+ logger .exception (
1236+ f'Failed to create DOI for registration { self ._id } during set_privacy. '
1237+ f'Registration cannot be made public without a DOI.'
1238+ )
1239+ if auth and auth .user :
1240+ update_admin_log (
1241+ user_id = auth .user .id ,
1242+ object_id = self ._id ,
1243+ object_repr = f'Registration { self .title } ' ,
1244+ message = f'DOI creation failed during make public: { str (e )} . DataCite may be unavailable.' ,
1245+ action_flag = DOI_CREATION_FAILED
1246+ )
1247+ raise NodeStateError (
1248+ 'Unable to make registration public: DOI creation failed. '
1249+ 'This may be due to a temporary DataCite service outage. '
1250+ 'Please try again later or contact support if the issue persists.'
1251+ )
12281252 self .is_public = True
12291253 elif permissions == 'private' and self .is_public :
12301254 if self .is_registration and not self .is_pending_embargo and not force :
@@ -1244,12 +1268,24 @@ def set_privacy(self, permissions, auth=None, log=True, save=True, meeting_creat
12441268 if message :
12451269 status .push_status_message (message , kind = 'info' , trust = False )
12461270
1247- # Update existing identifiers
1271+ # Update existing identifiers metadata
12481272 if self .get_identifier_value ('doi' ):
1249- update_doi_metadata_on_change (self ._id )
1250- elif self .is_registration :
1251- doi = self .request_identifier ('doi' )['doi' ]
1252- self .set_identifier_value ('doi' , doi )
1273+ try :
1274+ update_doi_metadata_on_change (self ._id )
1275+ except Exception as e :
1276+ from osf .models .admin_log_entry import update_admin_log , DOI_UPDATE_FAILED
1277+ logger .exception (
1278+ f'Failed to update DOI metadata for { self ._id } during set_privacy. '
1279+ )
1280+ # Log DOI metadata update failures for tracking
1281+ if auth and auth .user and self .is_registration :
1282+ update_admin_log (
1283+ user_id = auth .user .id ,
1284+ object_id = self ._id ,
1285+ object_repr = f'Registration { self .title } ' ,
1286+ message = f'DOI metadata update failed: { str (e )} . DataCite may be unavailable.' ,
1287+ action_flag = DOI_UPDATE_FAILED
1288+ )
12531289
12541290 if log :
12551291 action = NodeLog .MADE_PUBLIC if permissions == 'public' else NodeLog .MADE_PRIVATE
0 commit comments