-
Notifications
You must be signed in to change notification settings - Fork 14
feat(tasks): support assignee filtering in team task listings #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
feat(tasks): support assignee filtering in team task listings #293
Conversation
- extend fetch serializer and OpenAPI docs to accept repeated assigneeId parameters - validate assignee membership in TaskListView and forward normalized IDs to TaskService - teach TaskRepository list/count to intersect team and assignee scopes correctly while honoring creator visibility - add unit coverage across serializer, view, service, and repository for new filtering paths - document curl verification of /v1/tasks with team-scoped assignee filters
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis PR implements assignee filtering for the Changes
Sequence DiagramsequenceDiagram
participant Client
participant TaskListView
participant UserTeamDetailsRepository
participant TaskService
participant TaskRepository
participant TaskAssignmentRepository
participant MongoDB
Client->>TaskListView: GET /tasks?teamId=X&assigneeId=Y
TaskListView->>UserTeamDetailsRepository: get_users_by_team_id(teamId=X)
UserTeamDetailsRepository-->>TaskListView: team members list
TaskListView->>TaskListView: validate assigneeId in team members
alt assigneeId not in team
TaskListView-->>Client: 400 USER_NOT_TEAM_MEMBER
else valid
TaskListView->>TaskService: get_tasks(..., assignee_ids=[Y])
TaskService->>TaskRepository: list(..., assignee_ids=[Y])
TaskRepository->>TaskAssignmentRepository: _get_task_ids_for_assignees([Y], team_id=X)
TaskAssignmentRepository->>MongoDB: query task_assignments by assignee_id & team_id
MongoDB-->>TaskAssignmentRepository: task IDs
TaskAssignmentRepository-->>TaskRepository: resolved task IDs
TaskRepository->>MongoDB: query tasks where _id in [task_ids]
MongoDB-->>TaskRepository: filtered tasks
TaskRepository-->>TaskService: task list
TaskService->>TaskRepository: count(..., assignee_ids=[Y])
TaskRepository-->>TaskService: count (same filter logic)
TaskService-->>TaskListView: GetTasksResponse
TaskListView-->>Client: 200 tasks with pagination
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
todo/services/task_service.py (1)
67-78: Remove the redundant inner TeamRepository import for clarity and easier mockingThe module-level import of
TeamRepositoryat line 29 already makes the class available throughout the file. The inner import at line 84 is unnecessary and complicates test mocking. Remove it and rely on the top-level import:if team_id: - from todo.repositories.team_repository import TeamRepository - if not TeamRepository.is_user_team_member(team_id, user_id):This keeps behavior identical but allows tests to cleanly patch
todo.services.task_service.TeamRepository.is_user_team_memberwithout dealing with runtime imports. Theassignee_idsparameter threading throughTaskRepository.listandcountis correct and maintains backward compatibility whenNone.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (8)
todo/repositories/task_repository.py(3 hunks)todo/serializers/get_tasks_serializer.py(3 hunks)todo/services/task_service.py(2 hunks)todo/tests/unit/repositories/test_task_repository.py(2 hunks)todo/tests/unit/serializers/test_get_tasks_serializer.py(2 hunks)todo/tests/unit/services/test_task_service.py(8 hunks)todo/tests/unit/views/test_task.py(12 hunks)todo/views/task.py(4 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 231
File: todo/repositories/task_repository.py:93-109
Timestamp: 2025-07-25T20:12:36.483Z
Learning: Issue #215 in the Real-Dev-Squad/todo-backend repository addresses the problem where tasks assigned to team members disappear from the team's todo list. The expected behavior is that tasks assigned to individual team members should still be visible in the team's todo list, which is implemented by aggregating both direct team assignments and member assignments in the _get_assigned_task_ids_for_team method.
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 231
File: todo/repositories/task_repository.py:93-109
Timestamp: 2025-07-25T20:12:36.483Z
Learning: In the todo-backend project, tasks can only be assigned to either a team (user_type = "team") or an individual user (user_type = "user"), never both simultaneously. When a POC reassigns a task from a team to an individual team member, the old team assignment is deactivated and a new user assignment is created, ensuring no overlapping assignments exist.
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 52
File: todo/views/task.py:106-106
Timestamp: 2025-05-29T21:36:27.694Z
Learning: Issue #26 in the Real-Dev-Squad/todo-backend repository comprehensively tracks user authentication implementation including registration, login, JWT tokens, and making task APIs require authentication. This covers replacing hardcoded user ID placeholders like "system_patch_user" with actual user ID extraction from authenticated requests.
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 52
File: todo/views/task.py:106-106
Timestamp: 2025-05-29T21:36:27.694Z
Learning: Issue #26 tracks the implementation of user authentication in the todo-backend project, which includes extracting user ID from request context to replace hardcoded placeholders like "system_patch_user" in todo/views/task.py.
📚 Learning: 2025-07-25T20:12:36.483Z
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 231
File: todo/repositories/task_repository.py:93-109
Timestamp: 2025-07-25T20:12:36.483Z
Learning: Issue #215 in the Real-Dev-Squad/todo-backend repository addresses the problem where tasks assigned to team members disappear from the team's todo list. The expected behavior is that tasks assigned to individual team members should still be visible in the team's todo list, which is implemented by aggregating both direct team assignments and member assignments in the _get_assigned_task_ids_for_team method.
Applied to files:
todo/services/task_service.pytodo/views/task.pytodo/tests/unit/views/test_task.pytodo/tests/unit/repositories/test_task_repository.pytodo/repositories/task_repository.pytodo/tests/unit/services/test_task_service.py
📚 Learning: 2025-07-23T19:26:43.747Z
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 227
File: todo/repositories/task_repository.py:0-0
Timestamp: 2025-07-23T19:26:43.747Z
Learning: In the todo-backend project, the get_tasks_for_user method in TaskRepository is intentionally designed to return only tasks assigned to the user (not tasks created by them), while the count method includes both tasks created by and assigned to the user. This behavioral difference is by design to serve different use cases.
Applied to files:
todo/services/task_service.pytodo/views/task.pytodo/tests/unit/repositories/test_task_repository.pytodo/repositories/task_repository.pytodo/tests/unit/services/test_task_service.py
📚 Learning: 2025-07-09T19:59:31.694Z
Learnt from: AnujChhikara
Repo: Real-Dev-Squad/todo-backend PR: 119
File: todo/repositories/task_repository.py:149-154
Timestamp: 2025-07-09T19:59:31.694Z
Learning: In the todo-backend project, per product requirements, tasks marked as deleted (isDeleted=True) should still be returned in user task queries. The get_tasks_for_user method in TaskRepository should not filter out deleted tasks, unlike typical soft deletion patterns.
Applied to files:
todo/services/task_service.pytodo/views/task.pytodo/tests/unit/repositories/test_task_repository.pytodo/repositories/task_repository.pytodo/tests/unit/services/test_task_service.py
📚 Learning: 2025-07-25T20:12:36.483Z
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 231
File: todo/repositories/task_repository.py:93-109
Timestamp: 2025-07-25T20:12:36.483Z
Learning: In the todo-backend project, tasks can only be assigned to either a team (user_type = "team") or an individual user (user_type = "user"), never both simultaneously. When a POC reassigns a task from a team to an individual team member, the old team assignment is deactivated and a new user assignment is created, ensuring no overlapping assignments exist.
Applied to files:
todo/views/task.pytodo/repositories/task_repository.py
📚 Learning: 2025-09-22T15:34:24.054Z
Learnt from: Hariom01010
Repo: Real-Dev-Squad/todo-backend PR: 279
File: todo/management/commands/migrate_add_roles_to_teams.py:3-3
Timestamp: 2025-09-22T15:34:24.054Z
Learning: In the todo-backend repository, UserTeamDetailsRepository is defined in todo/repositories/team_repository.py and should be imported from there, not from a separate module.
Applied to files:
todo/views/task.pytodo/repositories/task_repository.py
📚 Learning: 2025-07-25T20:12:36.483Z
Learnt from: Achintya-Chatterjee
Repo: Real-Dev-Squad/todo-backend PR: 231
File: todo/repositories/task_repository.py:93-109
Timestamp: 2025-07-25T20:12:36.483Z
Learning: In the todo-backend project's TaskAssignmentRepository, the update_assignment method ensures exclusive task assignments by deactivating all current active assignments for a task before creating a new assignment. This prevents any task from being simultaneously assigned to both a team and individual team members.
Applied to files:
todo/views/task.pytodo/tests/unit/repositories/test_task_repository.pytodo/repositories/task_repository.py
🧬 Code graph analysis (7)
todo/services/task_service.py (1)
todo/repositories/task_repository.py (1)
count(219-260)
todo/tests/unit/serializers/test_get_tasks_serializer.py (1)
todo/serializers/get_tasks_serializer.py (1)
GetTaskQueryParamsSerializer(27-88)
todo/views/task.py (2)
todo/repositories/team_repository.py (2)
UserTeamDetailsRepository(126-387)get_users_by_team_id(223-232)todo/constants/messages.py (1)
ValidationErrors(62-88)
todo/tests/unit/views/test_task.py (3)
todo/views/task.py (2)
get(83-140)get(242-248)todo/constants/messages.py (1)
ValidationErrors(62-88)todo/dto/responses/get_tasks_response.py (1)
GetTasksResponse(7-8)
todo/tests/unit/repositories/test_task_repository.py (1)
todo/repositories/task_repository.py (2)
_get_task_ids_for_assignees(33-75)count(219-260)
todo/repositories/task_repository.py (5)
todo/repositories/task_assignment_repository.py (1)
TaskAssignmentRepository(14-523)todo/repositories/common/mongo_repository.py (1)
get_collection(17-20)todo/models/task.py (1)
TaskModel(23-43)todo/repositories/abstract_repository.py (1)
count(40-42)todo/repositories/postgres_repository.py (1)
count(74-81)
todo/tests/unit/services/test_task_service.py (1)
todo/services/task_service.py (1)
get_tasks(68-134)
🪛 GitHub Actions: Tests
todo/tests/unit/services/test_task_service.py
[error] 151-151: AssertionError: Expected 'list' to be called once. Called 0 times.
[error] 1-1: Test suite failing due to mocks not being invoked as expected (get_tasks/list calls).
🔇 Additional comments (4)
todo/tests/unit/serializers/test_get_tasks_serializer.py (1)
3-4: Serializer assigneeId tests accurately cover QueryDict + dedup behaviorThe new tests correctly verify that
assigneeIdis pulled from aQueryDictintovalidated_data["assignee_ids"]and that duplicates are removed while preserving order; using DRF’sValidationErrorhere is also appropriate for the existing assertions.Also applies to: 75-89
todo/tests/unit/views/test_task.py (1)
48-57: View tests correctly exercise assignee filtering, validation, and default wiringThe updated assertions that
TaskService.get_tasksis always called withassignee_ids=Nonein the non-filtered paths keep the contract tight, and the three new tests aroundassigneeId(missingteamId, non‑member rejection, and successful pass‑through of IDs) match the view logic and error‑handling expectations. PatchingUserTeamDetailsRepository.get_users_by_team_idand verifying both error sources and the finalassignee_idsargument gives solid coverage for the new behavior.Also applies to: 106-147, 223-251, 292-348, 363-444
todo/repositories/task_repository.py (1)
32-76: Assignee‑based filtering in list/count is consistent and efficient
_get_task_ids_for_assigneescorrectly resolves active user assignments (optionally scoped byteam_id), handling both string andObjectIdrepresentations of IDs, and returning a unique set ofObjectIdtask IDs. The updates tolistandcountsensibly:
- Start from the existing status filter.
- Constrain by assignee IDs (with early return when there are no matching assignments).
- Fall back to team‑wide task IDs when only
team_idis provided.- Preserve the “createdBy OR assigned to user” semantics when no team scope is active, while skipping that user filter once a team scope (either via
team_idorassignee_ids+team_id) is applied.This matches the documented behavior around team vs user visibility and avoids unnecessary collection operations when filters produce an empty task set.
Also applies to: 110-155, 219-260
todo/tests/unit/repositories/test_task_repository.py (1)
94-204: Repository tests thoroughly cover new assignee and team scoping logicThe added unit tests for
TaskRepository.list/countand_get_task_ids_for_assigneesdo a good job of pinning down the new behavior:
- Verifying early exits when assignee filters yield no task IDs.
- Asserting that
_id$infilters appear inside the$andquery for both list and count.- Ensuring team+assignee combinations rely exclusively on
_get_task_ids_for_assignees(team_id=...)and skip_get_team_task_ids, and that team scoping suppresses the usercreatedBy/assigned OR clause.The helper tests that inspect the generated assignment filter (including mixed string/ObjectId forms for
assignee_idandteam_id) are especially useful for catching regressions in how assignments are resolved.Also applies to: 236-317
- accept repeated assigneeId query params and normalize them - require valid team membership before passing assignee filters downstream - thread assignee_ids through TaskService and TaskRepository list/count - add coverage for team-scoped filtering paths across view/service/repo - centralize the teamId missing validation message for consistency
- ensure GetTaskQueryParamsSerializer surfaces invalid assigneeId values - rename repository helper set to assignee_lookup_values for readability
* test(tasks): cover team + assignee filtering scenarios - add serializer, view, service, and repository specs for multi-assignee queries - exercise team-scoped assignee resolution and list/count symmetry - protect regressions where team filters should bypass user-level fallbacks * test(tasks): cover team + assignee filtering scenarios - add serializer, view, service, and repository specs for multi-assignee queries - exercise team-scoped assignee resolution and list/count symmetry - protect regressions where team filters should bypass user-level fallbacks * test(tasks): cover team + assignee filtering scenarios - add serializer, view, service, and repository specs for multi-assignee queries - exercise team-scoped assignee resolution and list/count symmetry - protect regressions where team filters should bypass user-level fallbacks * fix: By stubbing is_user_team_member before asserting the repository calls, the test no longer bails out with a “FORBIDDEN” response; the mocked list/count methods are hit, and the assertions succeed. * fix:failing test * fix: formatting * test(tasks): update assignee filtering tests for objectid validation - use valid ObjectId strings in serializer and view tests - ensure team membership mock aligns with validated assignee ids
Date:
10th December, 2025Developer Name: @Achintya-Chatterjee
Issue Ticket Number
GET /tasksEndpoint #291Description
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Screen.Recording.2025-12-10.at.02.24.38.mp4
Screen.Recording.2025-12-10.at.03.00.51.mov
Test Coverage
Screenshot 1
Additional Notes