@@ -348,6 +348,11 @@ async def create_score_set(
348348 if not license_ :
349349 logger .info (msg = "Failed to create score set; The requested license does not exist." , extra = logging_context ())
350350 raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
351+ elif not license_ .active :
352+ logger .info (
353+ msg = "Failed to create score set; The requested license is no longer active." , extra = logging_context ()
354+ )
355+ raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Invalid license" )
351356
352357 save_to_logging_context ({"requested_superseded_score_set" : item_create .superseded_score_set_urn })
353358 if item_create .superseded_score_set_urn is not None :
@@ -651,7 +656,9 @@ async def upload_score_set_variant_data(
651656 return item
652657
653658
654- @router .put ("/score-sets/{urn}" , response_model = score_set .ScoreSet , responses = {422 : {}})
659+ @router .put (
660+ "/score-sets/{urn}" , response_model = score_set .ScoreSet , responses = {422 : {}}, response_model_exclude_none = True
661+ )
655662async def update_score_set (
656663 * ,
657664 urn : str ,
@@ -673,68 +680,73 @@ async def update_score_set(
673680
674681 assert_permission (user_data , item , Action .UPDATE )
675682
676- # Editing unpublished score set
677- if item .private is True :
678- license_ = None
679-
680- if item_update .license_id is not None :
681- save_to_logging_context ({"license" : item_update .license_id })
682- license_ = db .query (License ).filter (License .id == item_update .license_id ).one_or_none ()
683+ for var , value in vars (item_update ).items ():
684+ if var not in [
685+ "contributors" ,
686+ "score_ranges" ,
687+ "doi_identifiers" ,
688+ "experiment_urn" ,
689+ "license_id" ,
690+ "secondary_publication_identifiers" ,
691+ "primary_publication_identifiers" ,
692+ "target_genes" ,
693+ ]:
694+ setattr (item , var , value ) if value else None
695+
696+ if item_update .license_id is not None :
697+ save_to_logging_context ({"license" : item_update .license_id })
698+ license_ = db .query (License ).filter (License .id == item_update .license_id ).one_or_none ()
699+
700+ if not license_ :
701+ logger .info (
702+ msg = "Failed to update score set; The requested license does not exist." , extra = logging_context ()
703+ )
704+ raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
683705
684- if not license_ :
685- logger .info (
686- msg = "Failed to update score set; The requested license does not exist." , extra = logging_context ()
687- )
688- raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Unknown license" )
706+ # Allow in-active licenses to be retained on update if they already exist on the item.
707+ elif not license_ .active and item .licence_id != item_update .license_id :
708+ logger .info (
709+ msg = "Failed to update score set license; The requested license is no longer active." ,
710+ extra = logging_context (),
711+ )
712+ raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Invalid license" )
689713
690- item .license = license_
714+ item .license = license_
691715
692- for var , value in vars (item_update ).items ():
693- if var not in [
694- "contributors" ,
695- "score_ranges" ,
696- "doi_identifiers" ,
697- "experiment_urn" ,
698- "license_id" ,
699- "secondary_publication_identifiers" ,
700- "primary_publication_identifiers" ,
701- "target_genes" ,
702- ]:
703- setattr (item , var , value ) if value else None
704-
705- try :
706- item .contributors = [
707- await find_or_create_contributor (db , contributor .orcid_id )
708- for contributor in item_update .contributors or []
709- ]
710- except NonexistentOrcidUserError as e :
711- logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
712- raise pydantic .ValidationError (
713- [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
714- model = score_set .ScoreSetUpdate ,
715- )
716+ item .doi_identifiers = [
717+ await find_or_create_doi_identifier (db , identifier .identifier )
718+ for identifier in item_update .doi_identifiers or []
719+ ]
720+ primary_publication_identifiers = [
721+ await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
722+ for identifier in item_update .primary_publication_identifiers or []
723+ ]
724+ publication_identifiers = [
725+ await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
726+ for identifier in item_update .secondary_publication_identifiers or []
727+ ] + primary_publication_identifiers
716728
717- item .doi_identifiers = [
718- await find_or_create_doi_identifier (db , identifier .identifier )
719- for identifier in item_update .doi_identifiers or []
720- ]
721- primary_publication_identifiers = [
722- await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
723- for identifier in item_update .primary_publication_identifiers or []
724- ]
725- publication_identifiers = [
726- await find_or_create_publication_identifier (db , identifier .identifier , identifier .db_name )
727- for identifier in item_update .secondary_publication_identifiers or []
728- ] + primary_publication_identifiers
729+ # create a temporary `primary` attribute on each of our publications that indicates
730+ # to our association proxy whether it is a primary publication or not
731+ primary_identifiers = [p .identifier for p in primary_publication_identifiers ]
732+ for publication in publication_identifiers :
733+ setattr (publication , "primary" , publication .identifier in primary_identifiers )
729734
730- # create a temporary `primary` attribute on each of our publications that indicates
731- # to our association proxy whether it is a primary publication or not
732- primary_identifiers = [pub .identifier for pub in primary_publication_identifiers ]
733- for publication in publication_identifiers :
734- setattr (publication , "primary" , publication .identifier in primary_identifiers )
735+ item .publication_identifiers = publication_identifiers
735736
736- item .publication_identifiers = publication_identifiers
737+ try :
738+ item .contributors = [
739+ await find_or_create_contributor (db , contributor .orcid_id ) for contributor in item_update .contributors or []
740+ ]
741+ except NonexistentOrcidUserError as e :
742+ logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
743+ raise pydantic .ValidationError (
744+ [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
745+ model = score_set .ScoreSetUpdate ,
746+ )
737747
748+ # Score set has not been published and attributes affecting scores may still be edited.
749+ if item .private :
738750 if item_update .score_ranges :
739751 item .score_ranges = item_update .score_ranges .dict ()
740752 else :
@@ -889,35 +901,8 @@ async def update_score_set(
889901 if job is not None :
890902 save_to_logging_context ({"worker_job_id" : job .job_id })
891903 logger .info (msg = "Enqueud variant creation job." , extra = logging_context ())
892-
893- for var , value in vars (item_update ).items ():
894- if var not in [
895- "score_ranges" ,
896- "contributors" ,
897- "doi_identifiers" ,
898- "experiment_urn" ,
899- "primary_publication_identifiers" ,
900- "secondary_publication_identifiers" ,
901- "target_genes" ,
902- ]:
903- setattr (item , var , value ) if value else None
904-
905- # Editing published score set
906904 else :
907- for var , value in vars (item_update ).items ():
908- if var in ["title" , "method_text" , "abstract_text" , "short_description" ]:
909- setattr (item , var , value ) if value else None
910- try :
911- item .contributors = [
912- await find_or_create_contributor (db , contributor .orcid_id )
913- for contributor in item_update .contributors or []
914- ]
915- except NonexistentOrcidUserError as e :
916- logger .error (msg = "Could not find ORCID user with the provided user ID." , extra = logging_context ())
917- raise pydantic .ValidationError (
918- [pydantic .error_wrappers .ErrorWrapper (ValidationError (str (e )), loc = "contributors" )],
919- model = score_set .ScoreSetUpdate ,
920- )
905+ logger .debug (msg = "Skipped score range and target gene update. Score set is published." , extra = logging_context ())
921906
922907 db .add (item )
923908 db .commit ()
0 commit comments