@@ -402,12 +402,10 @@ def stop_time_entry_if_was_left_running(
402402 )
403403 raise CosmosResourceNotFoundError ()
404404
405- def get_all (self , conditions : dict = None , ** kwargs ) -> list :
406- event_ctx = self .create_event_context ("read-many" )
407- conditions .update ({"owner_id" : event_ctx .user_id })
405+ def build_custom_query (self , is_admin : bool , conditions : dict = None ):
408406 custom_query = []
409407 if "user_id" in conditions :
410- if event_ctx . is_admin :
408+ if is_admin :
411409 conditions .pop ("owner_id" )
412410 custom_query = (
413411 []
@@ -423,6 +421,16 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
423421 abort (
424422 HTTPStatus .FORBIDDEN , "You don't have enough permissions."
425423 )
424+ return custom_query
425+
426+ def get_all (self , conditions : dict = None , ** kwargs ) -> list :
427+ event_ctx = self .create_event_context ("read-many" )
428+ conditions .update ({"owner_id" : event_ctx .user_id })
429+
430+ custom_query = self .build_custom_query (
431+ is_admin = event_ctx .is_admin , conditions = conditions ,
432+ )
433+
426434 date_range = self .handle_date_filter_args (args = conditions )
427435 limit = conditions .get ("limit" , None )
428436 conditions .pop ("limit" , None )
@@ -438,25 +446,10 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
438446 event_ctx = self .create_event_context ("read-many" )
439447 conditions .update ({"owner_id" : event_ctx .user_id })
440448
441- # TODO: abstract this method with a function or a class method
442- custom_query = []
443- if "user_id" in conditions :
444- if event_ctx .is_admin :
445- conditions .pop ("owner_id" )
446- custom_query = (
447- []
448- if conditions .get ("user_id" ) == "*"
449- else [
450- create_custom_query_from_str (
451- conditions .get ("user_id" ), "c.owner_id"
452- )
453- ]
454- )
455- conditions .pop ("user_id" )
456- else :
457- abort (
458- HTTPStatus .FORBIDDEN , "You don't have enough permissions."
459- )
449+ custom_query = self .build_custom_query (
450+ is_admin = event_ctx .is_admin , conditions = conditions ,
451+ )
452+
460453 date_range = self .handle_date_filter_args (args = conditions )
461454
462455 length = conditions .get ("length" , None )
0 commit comments