@@ -289,6 +289,135 @@ def update(self, preprint, validated_data):
289
289
if not preprint .has_permission (auth .user , osf_permissions .WRITE ):
290
290
raise exceptions .PermissionDenied (detail = 'User must have admin or write permissions to update a preprint.' )
291
291
292
+ save_preprint = False
293
+ recently_published = False
294
+
295
+ for field in ['conflict_of_interest_statement' , 'why_no_data' , 'why_no_prereg' ]:
296
+ if field in validated_data :
297
+ value = validated_data [field ]
298
+ if isinstance (value , str ) and not value .strip ():
299
+ validated_data [field ] = None
300
+
301
+ updated_has_coi = validated_data .get ('has_coi' , preprint .has_coi )
302
+ updated_conflict_statement = validated_data .get ('conflict_of_interest_statement' , preprint .conflict_of_interest_statement )
303
+
304
+ updated_has_data_links = validated_data .get ('has_data_links' , preprint .has_data_links )
305
+ updated_why_no_data = validated_data .get ('why_no_data' , preprint .why_no_data )
306
+
307
+ updated_has_prereg_links = validated_data .get ('has_prereg_links' , preprint .has_prereg_links )
308
+ updated_why_no_prereg = validated_data .get ('why_no_prereg' , preprint .why_no_prereg )
309
+
310
+ if updated_has_coi is False and updated_conflict_statement :
311
+ raise exceptions .ValidationError (
312
+ detail = 'Cannot provide conflict of interest statement when has_coi is set to False.' ,
313
+ )
314
+
315
+ if updated_has_data_links != 'no' and updated_why_no_data :
316
+ raise exceptions .ValidationError (
317
+ detail = 'You cannot edit this statement while your data links availability is set to true or is unanswered.' ,
318
+ )
319
+
320
+ if updated_has_data_links == 'no' and 'data_links' in validated_data and validated_data ['data_links' ]:
321
+ raise exceptions .ValidationError (
322
+ detail = 'Cannot provide data links when has_data_links is set to "no".' ,
323
+ )
324
+
325
+ if updated_has_prereg_links != 'no' and updated_why_no_prereg :
326
+ raise exceptions .ValidationError (
327
+ detail = 'You cannot edit this statement while your prereg links availability is set to true or is unanswered.' ,
328
+ )
329
+
330
+ if updated_has_prereg_links != 'available' :
331
+ if 'prereg_links' in validated_data and validated_data ['prereg_links' ]:
332
+ raise exceptions .ValidationError (
333
+ detail = 'You cannot edit this field while your prereg links availability is set to false or is unanswered.' ,
334
+ )
335
+ if 'prereg_link_info' in validated_data and validated_data ['prereg_link_info' ]:
336
+ raise exceptions .ValidationError (
337
+ detail = 'You cannot edit this field while your prereg links availability is set to false or is unanswered.' ,
338
+ )
339
+
340
+ def require_admin_permission ():
341
+ if not preprint .has_permission (auth .user , osf_permissions .ADMIN ):
342
+ raise exceptions .PermissionDenied (detail = 'Must have admin permissions to update author assertion fields.' )
343
+
344
+ if 'has_coi' in validated_data :
345
+ require_admin_permission ()
346
+ try :
347
+ preprint .update_has_coi (auth , validated_data ['has_coi' ])
348
+ save_preprint = True
349
+ except PreprintStateError as e :
350
+ raise exceptions .ValidationError (detail = str (e ))
351
+
352
+ if 'conflict_of_interest_statement' in validated_data :
353
+ require_admin_permission ()
354
+ try :
355
+ preprint .update_conflict_of_interest_statement (auth , validated_data ['conflict_of_interest_statement' ])
356
+ save_preprint = True
357
+ except PreprintStateError as e :
358
+ raise exceptions .ValidationError (detail = str (e ))
359
+
360
+ if 'has_data_links' in validated_data :
361
+ require_admin_permission ()
362
+ try :
363
+ preprint .update_has_data_links (auth , validated_data ['has_data_links' ])
364
+ save_preprint = True
365
+ except PreprintStateError as e :
366
+ raise exceptions .ValidationError (detail = str (e ))
367
+
368
+ if 'why_no_data' in validated_data :
369
+ require_admin_permission ()
370
+ try :
371
+ preprint .update_why_no_data (auth , validated_data ['why_no_data' ])
372
+ save_preprint = True
373
+ except PreprintStateError as e :
374
+ raise exceptions .ValidationError (detail = str (e ))
375
+
376
+ if 'data_links' in validated_data :
377
+ require_admin_permission ()
378
+ try :
379
+ preprint .update_data_links (auth , validated_data ['data_links' ])
380
+ save_preprint = True
381
+ except PreprintStateError as e :
382
+ raise exceptions .ValidationError (detail = str (e ))
383
+ else :
384
+ if updated_has_data_links == 'no' and preprint .data_links :
385
+ preprint .update_data_links (auth , [])
386
+ save_preprint = True
387
+
388
+ if 'has_prereg_links' in validated_data :
389
+ require_admin_permission ()
390
+
391
+ try :
392
+ preprint .update_has_prereg_links (auth , validated_data ['has_prereg_links' ])
393
+ save_preprint = True
394
+ except PreprintStateError as e :
395
+ raise exceptions .ValidationError (detail = str (e ))
396
+
397
+ if 'why_no_prereg' in validated_data :
398
+ require_admin_permission ()
399
+ try :
400
+ preprint .update_why_no_prereg (auth , validated_data ['why_no_prereg' ])
401
+ save_preprint = True
402
+ except PreprintStateError as e :
403
+ raise exceptions .ValidationError (detail = str (e ))
404
+
405
+ if 'prereg_links' in validated_data :
406
+ require_admin_permission ()
407
+ try :
408
+ preprint .update_prereg_links (auth , validated_data ['prereg_links' ])
409
+ save_preprint = True
410
+ except PreprintStateError as e :
411
+ raise exceptions .ValidationError (detail = str (e ))
412
+
413
+ if 'prereg_link_info' in validated_data :
414
+ require_admin_permission ()
415
+ try :
416
+ preprint .update_prereg_link_info (auth , validated_data ['prereg_link_info' ])
417
+ save_preprint = True
418
+ except PreprintStateError as e :
419
+ raise exceptions .ValidationError (detail = str (e ))
420
+
292
421
published = validated_data .pop ('is_published' , None )
293
422
if published and preprint .provider .is_reviewed :
294
423
url = absolute_reverse (
@@ -369,8 +498,6 @@ def update(self, preprint, validated_data):
369
498
preprint .custom_publication_citation = validated_data ['custom_publication_citation' ] or None
370
499
save_preprint = True
371
500
372
- self .handle_author_assertions (preprint , validated_data , auth )
373
-
374
501
if published is not None :
375
502
if not preprint .primary_file :
376
503
raise exceptions .ValidationError (
@@ -396,76 +523,6 @@ def update(self, preprint, validated_data):
396
523
397
524
return preprint
398
525
399
- def handle_author_assertions (self , preprint , validated_data , auth ):
400
- author_assertions = {
401
- 'has_coi' ,
402
- 'conflict_of_interest_statement' ,
403
- 'has_data_links' ,
404
- 'why_no_data' ,
405
- 'data_links' ,
406
- 'why_no_prereg' ,
407
- 'prereg_links' ,
408
- 'has_prereg_links' ,
409
- 'prereg_link_info' ,
410
- }
411
- if author_assertions & validated_data .keys ():
412
- if not preprint .is_admin_contributor (auth .user ):
413
- raise exceptions .PermissionDenied ('User must be admin to add author assertions' )
414
-
415
- if 'has_coi' in validated_data :
416
- try :
417
- preprint .update_has_coi (auth , validated_data ['has_coi' ])
418
- except PreprintStateError as e :
419
- raise exceptions .ValidationError (detail = str (e ))
420
-
421
- if 'conflict_of_interest_statement' in validated_data :
422
- try :
423
- preprint .update_conflict_of_interest_statement (auth , validated_data ['conflict_of_interest_statement' ])
424
- except PreprintStateError as e :
425
- raise exceptions .ValidationError (detail = str (e ))
426
-
427
- if 'has_data_links' in validated_data :
428
- try :
429
- preprint .update_has_data_links (auth , validated_data ['has_data_links' ])
430
- except PreprintStateError as e :
431
- raise exceptions .ValidationError (detail = str (e ))
432
-
433
- if 'why_no_data' in validated_data :
434
- try :
435
- preprint .update_why_no_data (auth , validated_data ['why_no_data' ])
436
- except PreprintStateError as e :
437
- raise exceptions .ValidationError (detail = str (e ))
438
-
439
- if 'data_links' in validated_data :
440
- try :
441
- preprint .update_data_links (auth , validated_data ['data_links' ])
442
- except PreprintStateError as e :
443
- raise exceptions .ValidationError (detail = str (e ))
444
-
445
- if 'has_prereg_links' in validated_data :
446
- try :
447
- preprint .update_has_prereg_links (auth , validated_data ['has_prereg_links' ])
448
- except PreprintStateError as e :
449
- raise exceptions .ValidationError (detail = str (e ))
450
-
451
- if 'why_no_prereg' in validated_data :
452
- try :
453
- preprint .update_why_no_prereg (auth , validated_data ['why_no_prereg' ])
454
- except PreprintStateError as e :
455
- raise exceptions .ValidationError (detail = str (e ))
456
-
457
- if 'prereg_links' in validated_data :
458
- try :
459
- preprint .update_prereg_links (auth , validated_data ['prereg_links' ])
460
- except PreprintStateError as e :
461
- raise exceptions .ValidationError (detail = str (e ))
462
-
463
- if 'prereg_link_info' in validated_data :
464
- try :
465
- preprint .update_prereg_link_info (auth , validated_data ['prereg_link_info' ])
466
- except PreprintStateError as e :
467
- raise exceptions .ValidationError (detail = str (e ))
468
-
469
526
def set_field (self , func , val , auth , save = False ):
470
527
try :
471
528
func (val , auth )
0 commit comments