@@ -349,8 +349,8 @@ async def upsert_project_linked_product(
349349 .on_conflict_do_nothing ()
350350 )
351351
352+ @staticmethod
352353 def _create_private_workspace_query (
353- self ,
354354 * ,
355355 product_name : ProductName ,
356356 user_id : UserID ,
@@ -434,8 +434,8 @@ def _create_private_workspace_query(
434434
435435 return private_workspace_query
436436
437+ @staticmethod
437438 def _create_shared_workspace_query (
438- self ,
439439 * ,
440440 product_name : ProductName ,
441441 workspace_query : WorkspaceQuery ,
@@ -533,6 +533,74 @@ def _create_shared_workspace_query(
533533
534534 return None
535535
536+ @staticmethod
537+ def _create_attributes_filters (
538+ * ,
539+ filter_by_project_type : ProjectType | None ,
540+ filter_hidden : bool | None ,
541+ filter_published : bool | None ,
542+ filter_trashed : bool | None ,
543+ search_by_multi_columns : str | None ,
544+ search_by_project_name : str | None ,
545+ filter_tag_ids_list : list [int ] | None ,
546+ folder_query : FolderQuery ,
547+ project_tags_subquery : sql .Subquery ,
548+ ) -> list [ColumnElement ]:
549+ attributes_filters : list [ColumnElement ] = []
550+
551+ if filter_by_project_type is not None :
552+ attributes_filters .append (projects .c .type == filter_by_project_type .value )
553+
554+ if filter_hidden is not None :
555+ attributes_filters .append (projects .c .hidden .is_ (filter_hidden ))
556+
557+ if filter_published is not None :
558+ attributes_filters .append (projects .c .published .is_ (filter_published ))
559+
560+ if filter_trashed is not None :
561+ attributes_filters .append (
562+ # marked explicitly as trashed
563+ (
564+ projects .c .trashed .is_not (None )
565+ & projects .c .trashed_explicitly .is_ (True )
566+ )
567+ if filter_trashed
568+ # not marked as trashed
569+ else projects .c .trashed .is_ (None )
570+ )
571+
572+ if search_by_multi_columns is not None :
573+ attributes_filters .append (
574+ (projects .c .name .ilike (f"%{ search_by_multi_columns } %" ))
575+ | (projects .c .description .ilike (f"%{ search_by_multi_columns } %" ))
576+ | (projects .c .uuid .ilike (f"%{ search_by_multi_columns } %" ))
577+ | (users .c .name .ilike (f"%{ search_by_multi_columns } %" ))
578+ )
579+
580+ if search_by_project_name is not None :
581+ attributes_filters .append (
582+ projects .c .name .like (f"%{ search_by_project_name } %" )
583+ )
584+
585+ if filter_tag_ids_list :
586+ attributes_filters .append (
587+ sa .func .coalesce (
588+ project_tags_subquery .c .tags ,
589+ sa .cast (sa .text ("'{}'" ), sa .ARRAY (sa .Integer )),
590+ ).op ("@>" )(filter_tag_ids_list )
591+ )
592+
593+ if folder_query .folder_scope is not FolderScope .ALL :
594+ if folder_query .folder_scope == FolderScope .SPECIFIC :
595+ attributes_filters .append (
596+ projects_to_folders .c .folder_id == folder_query .folder_id
597+ )
598+ else :
599+ assert folder_query .folder_scope == FolderScope .ROOT # nosec
600+ attributes_filters .append (projects_to_folders .c .folder_id .is_ (None ))
601+
602+ return attributes_filters
603+
536604 async def list_projects_dicts ( # pylint: disable=too-many-arguments,too-many-statements,too-many-branches
537605 self ,
538606 * ,
@@ -600,55 +668,17 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st
600668 # Attributes Filters
601669 ###
602670
603- attributes_filters : list [ColumnElement ] = []
604- if filter_by_project_type is not None :
605- attributes_filters .append (
606- projects .c .type == filter_by_project_type .value
607- )
608-
609- if filter_hidden is not None :
610- attributes_filters .append (projects .c .hidden .is_ (filter_hidden ))
611-
612- if filter_published is not None :
613- attributes_filters .append (projects .c .published .is_ (filter_published ))
614-
615- if filter_trashed is not None :
616- attributes_filters .append (
617- # marked explicitly as trashed
618- (
619- projects .c .trashed .is_not (None )
620- & projects .c .trashed_explicitly .is_ (True )
621- )
622- if filter_trashed
623- # not marked as trashed
624- else projects .c .trashed .is_ (None )
625- )
626- if search_by_multi_columns is not None :
627- attributes_filters .append (
628- (projects .c .name .ilike (f"%{ search_by_multi_columns } %" ))
629- | (projects .c .description .ilike (f"%{ search_by_multi_columns } %" ))
630- | (projects .c .uuid .ilike (f"%{ search_by_multi_columns } %" ))
631- | (users .c .name .ilike (f"%{ search_by_multi_columns } %" ))
632- )
633- if search_by_project_name is not None :
634- attributes_filters .append (
635- projects .c .name .like (f"%{ search_by_project_name } %" )
636- )
637- if filter_tag_ids_list :
638- attributes_filters .append (
639- sa .func .coalesce (
640- project_tags_subquery .c .tags ,
641- sa .cast (sa .text ("'{}'" ), sa .ARRAY (sa .Integer )),
642- ).op ("@>" )(filter_tag_ids_list )
643- )
644- if folder_query .folder_scope is not FolderScope .ALL :
645- if folder_query .folder_scope == FolderScope .SPECIFIC :
646- attributes_filters .append (
647- projects_to_folders .c .folder_id == folder_query .folder_id
648- )
649- else :
650- assert folder_query .folder_scope == FolderScope .ROOT # nosec
651- attributes_filters .append (projects_to_folders .c .folder_id .is_ (None ))
671+ attributes_filters = self ._create_attributes_filters (
672+ filter_by_project_type = filter_by_project_type ,
673+ filter_hidden = filter_hidden ,
674+ filter_published = filter_published ,
675+ filter_trashed = filter_trashed ,
676+ search_by_multi_columns = search_by_multi_columns ,
677+ search_by_project_name = search_by_project_name ,
678+ filter_tag_ids_list = filter_tag_ids_list ,
679+ folder_query = folder_query ,
680+ project_tags_subquery = project_tags_subquery ,
681+ )
652682
653683 ###
654684 # Combined
0 commit comments