@@ -431,7 +431,7 @@ def clone_project(
431431 project_description : Optional [NotEmptyStr ] = None ,
432432 copy_annotation_classes : Optional [StrictBool ] = True ,
433433 copy_settings : Optional [StrictBool ] = True ,
434- copy_workflow : Optional [StrictBool ] = True ,
434+ copy_workflow : Optional [StrictBool ] = False ,
435435 copy_contributors : Optional [StrictBool ] = False ,
436436 ):
437437 """Create a new project in the team using annotation classes and settings from from_project.
@@ -455,22 +455,54 @@ def clone_project(
455455 :return: dict object metadata of the new project
456456 :rtype: dict
457457 """
458- project = self .controller .get_project (from_project )
459- new_project = copy .copy (project )
460- new_project .name = project_name
461- if project_description :
462- new_project .description = project_description
463- response = self .controller .projects .clone (
464- project = project ,
465- new_project = new_project ,
466- copy_annotation_classes = copy_annotation_classes ,
467- copy_settings = copy_settings ,
468- copy_workflow = copy_workflow ,
469- copy_contributors = copy_contributors ,
458+ response = self .controller .projects .get_metadata (
459+ self .controller .get_project (from_project ),
460+ include_annotation_classes = copy_annotation_classes ,
461+ include_settings = copy_settings ,
462+ include_workflow = copy_workflow ,
463+ include_contributors = copy_contributors ,
470464 )
471- if response .errors :
472- raise AppException (response .errors )
473- return ProjectSerializer (response .data ).serialize ()
465+ response .raise_for_status ()
466+ project : entities .ProjectEntity = response .data
467+ if copy_workflow and project .type not in (
468+ constants .ProjectType .VECTOR ,
469+ constants .ProjectType .PIXEL ,
470+ ):
471+ raise AppException (
472+ f"Workflow is not supported in { project .type .name } project."
473+ )
474+ logger .info (
475+ f"Created project { project_name } with type { constants .ProjectType .get_name (project .type )} ."
476+ )
477+ project_copy = copy .copy (project )
478+ if project_description :
479+ project_copy .description = project_description
480+ project_copy .name = project_name
481+ create_response = self .controller .projects .create (project_copy )
482+ create_response .raise_for_status ()
483+ new_project = create_response .data
484+ if copy_contributors :
485+ logger .info (f"Cloning contributors from { from_project } to { project_name } ." )
486+ self .controller .projects .add_contributors (
487+ self .controller .team , new_project , project .contributors
488+ )
489+ if copy_annotation_classes :
490+ logger .info (
491+ f"Cloning annotation classes from { from_project } to { project_name } ."
492+ )
493+ classes_response = self .controller .annotation_classes .create_multiple (
494+ new_project , project .classes
495+ )
496+ classes_response .raise_for_status ()
497+ project .classes = classes_response .data
498+ if copy_workflow :
499+ logger .info (f"Cloning workflow from { from_project } to { project_name } ." )
500+ workflow_response = self .controller .projects .set_workflows (
501+ new_project , project .workflows
502+ )
503+ workflow_response .raise_for_status ()
504+ project .workflows = self .controller .projects .list_workflow (project ).data
505+ return ProjectSerializer (new_project ).serialize ()
474506
475507 def create_folder (self , project : NotEmptyStr , folder_name : NotEmptyStr ):
476508 """Create a new folder in the project.
@@ -2123,8 +2155,12 @@ def add_contributors_to_project(
21232155 :rtype: tuple (2 members) of lists of strs
21242156 """
21252157 project = self .controller .projects .get_by_name (project ).data
2158+ contributors = [
2159+ entities .ContributorEntity (email = email , user_role = constants .UserRole (role ))
2160+ for email in emails
2161+ ]
21262162 response = self .controller .projects .add_contributors (
2127- project = project , team = self .controller .team , emails = emails , role = role
2163+ team = self .controller .team , project = project , contributors = contributors
21282164 )
21292165 if response .errors :
21302166 raise AppException (response .errors )
0 commit comments