@@ -46,7 +46,8 @@ def list(
46
46
47
47
if team_id :
48
48
logger .debug (f"TaskRepository.list: team_id={ team_id } " )
49
- team_task_ids = cls ._get_assigned_task_ids_for_team (team_id )
49
+ team_assignments = TaskAssignmentRepository .get_by_assignee_id (team_id , "team" )
50
+ team_task_ids = [assignment .task_id for assignment in team_assignments ]
50
51
logger .debug (f"TaskRepository.list: team_task_ids={ team_task_ids } " )
51
52
query_filter = {"$and" : [base_filter , {"_id" : {"$in" : team_task_ids }}]}
52
53
logger .debug (f"TaskRepository.list: query_filter={ query_filter } " )
@@ -77,45 +78,38 @@ def _get_assigned_task_ids_for_user(cls, user_id: str) -> List[ObjectId]:
77
78
direct_task_ids = [assignment .task_id for assignment in direct_assignments ]
78
79
79
80
# Get teams where user is a member
80
- from todo .repositories .team_repository import UserTeamDetailsRepository
81
+ from todo .repositories .team_repository import UserTeamDetailsRepository , TeamRepository
81
82
82
83
user_teams = UserTeamDetailsRepository .get_by_user_id (user_id )
83
84
team_ids = [str (team .team_id ) for team in user_teams ]
84
85
85
- # Get tasks assigned to those teams
86
+ # Get tasks assigned to those teams (only if user is POC)
86
87
team_task_ids = []
87
- for team_id in team_ids :
88
- team_assignments = TaskAssignmentRepository .get_by_assignee_id (team_id , "team" )
89
- team_task_ids .extend ([assignment .task_id for assignment in team_assignments ])
88
+ if team_ids :
89
+ # Get teams where user is POC
90
+ poc_teams = TeamRepository .get_collection ().find (
91
+ {"_id" : {"$in" : [ObjectId (team_id ) for team_id in team_ids ]}, "is_deleted" : False , "poc_id" : user_id }
92
+ )
93
+ poc_team_ids = [str (team ["_id" ]) for team in poc_teams ]
94
+
95
+ # Get team assignments for POC teams
96
+ if poc_team_ids :
97
+ team_assignments = TaskAssignmentRepository .get_collection ().find (
98
+ {"assignee_id" : {"$in" : poc_team_ids }, "user_type" : "team" , "is_active" : True }
99
+ )
100
+ team_task_ids = [ObjectId (assignment ["task_id" ]) for assignment in team_assignments ]
90
101
91
102
return direct_task_ids + team_task_ids
92
103
93
- @classmethod
94
- def _get_assigned_task_ids_for_team (cls , team_id : str ) -> List [ObjectId ]:
95
- """Get task IDs where team is assigned (either directly or via team members)."""
96
-
97
- direct_team_assignments = TaskAssignmentRepository .get_by_assignee_id (team_id , "team" )
98
- direct_team_task_ids = [assignment .task_id for assignment in direct_team_assignments ]
99
-
100
- from todo .repositories .team_repository import UserTeamDetailsRepository
101
-
102
- team_member_ids = UserTeamDetailsRepository .get_users_by_team_id (team_id )
103
-
104
- member_task_ids = []
105
- for member_id in team_member_ids :
106
- member_assignments = TaskAssignmentRepository .get_by_assignee_id (member_id , "user" )
107
- member_task_ids .extend ([assignment .task_id for assignment in member_assignments ])
108
-
109
- return direct_team_task_ids + member_task_ids
110
-
111
104
@classmethod
112
105
def count (cls , user_id : str = None , team_id : str = None , status_filter : str = None ) -> int :
113
106
tasks_collection = cls .get_collection ()
114
107
115
108
base_filter = cls ._build_status_filter (status_filter )
116
109
117
110
if team_id :
118
- team_task_ids = cls ._get_assigned_task_ids_for_team (team_id )
111
+ team_assignments = TaskAssignmentRepository .get_by_assignee_id (team_id , "team" )
112
+ team_task_ids = [assignment .task_id for assignment in team_assignments ]
119
113
query_filter = {"$and" : [base_filter , {"_id" : {"$in" : team_task_ids }}]}
120
114
elif user_id :
121
115
assigned_task_ids = cls ._get_assigned_task_ids_for_user (user_id )
0 commit comments