-
Notifications
You must be signed in to change notification settings - Fork 14
refactor: implement team isolation for task assignments #240
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
refactor: implement team isolation for task assignments #240
Conversation
- Added `original_team_id` field to `TaskAssignmentModel` to track original team context - Modified `TaskAssignmentRepository.update_assignment()` to set `original_team_id` when reassigning from team to user - Updated `TaskRepository.list()` and `count()` to include team member tasks with proper team isolation - Team task lists (`/v1/tasks?teamId=...`) now include tasks assigned to team members - Tasks are filtered by `original_team_id` to prevent cross-team contamination - Users in multiple teams only see tasks relevant to each specific team context - Modified `TaskAssignmentDetailView.patch()` to use `update_assignment()` instead of `update_executor()` - This ensures `original_team_id` is properly set when UI calls `PATCH /v1/task-assignments/{task_id}` - Maintains backward compatibility with existing UI workflow - Added support for both ObjectId and string formats in MongoDB queries - Prevents data type mismatches in `original_team_id` filtering
Based on your review schedule, I'll hold off on reviewing this PR until it's marked as ready for review. If you'd like me to take a look now, comment
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 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 Summary by CodeRabbit
WalkthroughA new optional field, Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TaskAssignmentDetailView
participant TaskAssignmentRepository
participant TaskAssignmentModel
Client->>TaskAssignmentDetailView: PATCH /task-assignment/<id>
TaskAssignmentDetailView->>TaskAssignmentRepository: update_assignment(task_id, assignee_id, "user", user_id)
TaskAssignmentRepository->>TaskAssignmentModel: Create new assignment (with original_team_id if reassigned from team)
TaskAssignmentRepository-->>TaskAssignmentDetailView: Return updated assignment or None
TaskAssignmentDetailView-->>Client: Respond with result or error message
sequenceDiagram
participant Client
participant TaskRepository
participant UserTeamDetailsRepository
participant TaskAssignmentRepository
Client->>TaskRepository: list/count tasks (with team_id)
TaskRepository->>UserTeamDetailsRepository: get_users_by_team_id(team_id)
TaskRepository->>TaskAssignmentRepository: get active assignments for team members with original_team_id=team_id
TaskRepository-->>Client: Return filtered tasks/count
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 1
♻️ Duplicate comments (1)
todo/repositories/task_repository.py (1)
145-181
: Consistent team isolation implementation in count method.The count method correctly implements the same team isolation logic as the list method, ensuring consistent behavior across both operations. The duplicate implementation maintains symmetry between listing and counting operations.
This implements the same team isolation logic as in the list method above. Consider the refactoring suggestion from the previous comment to reduce code duplication.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
todo/models/task_assignment.py
(1 hunks)todo/repositories/task_assignment_repository.py
(2 hunks)todo/repositories/task_repository.py
(2 hunks)todo/views/task_assignment.py
(1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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
PR: Real-Dev-Squad/todo-backend#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.
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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
PR: Real-Dev-Squad/todo-backend#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.
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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
PR: Real-Dev-Squad/todo-backend#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.
📚 Learning: in the todo-backend project's taskassignmentrepository, the update_assignment method ensures exclusi...
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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/repositories/task_assignment_repository.py
todo/models/task_assignment.py
todo/views/task_assignment.py
todo/repositories/task_repository.py
📚 Learning: in the todo-backend project, tasks can only be assigned to either a team (user_type = "team") or an ...
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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/repositories/task_assignment_repository.py
todo/models/task_assignment.py
todo/views/task_assignment.py
todo/repositories/task_repository.py
📚 Learning: issue #215 in the real-dev-squad/todo-backend repository addresses the problem where tasks assigned ...
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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/repositories/task_assignment_repository.py
todo/models/task_assignment.py
todo/repositories/task_repository.py
📚 Learning: in the todo-backend project, the get_tasks_for_user method in taskrepository is intentionally design...
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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/repositories/task_assignment_repository.py
todo/repositories/task_repository.py
📚 Learning: in the todo-backend project, per product requirements, tasks marked as deleted (isdeleted=true) shou...
Learnt from: AnujChhikara
PR: Real-Dev-Squad/todo-backend#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/repositories/task_assignment_repository.py
todo/repositories/task_repository.py
📚 Learning: issue #26 tracks the implementation of user authentication in the todo-backend project, which includ...
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#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.
Applied to files:
todo/views/task_assignment.py
📚 Learning: the todo-backend project uses a global exception handler that automatically handles tasknotfoundexce...
Learnt from: Achintya-Chatterjee
PR: Real-Dev-Squad/todo-backend#52
File: todo/views/task.py:98-112
Timestamp: 2025-06-02T17:02:22.424Z
Learning: The todo-backend project uses a global exception handler that automatically handles TaskNotFoundException, BsonInvalidId, ValueError with ApiErrorResponse, and DRFValidationError. Views should avoid try-catch blocks and let exceptions bubble up to the global handler for consistent error formatting and status codes.
Applied to files:
todo/repositories/task_repository.py
🧬 Code Graph Analysis (1)
todo/models/task_assignment.py (1)
todo/models/common/pyobjectid.py (1)
PyObjectId
(4-15)
🔇 Additional comments (5)
todo/models/task_assignment.py (2)
27-27
: Well-implemented team isolation tracking field.The
original_team_id
field is properly typed as optional and clearly documented. This will enable tracking the original team context when tasks are reassigned from teams to individual users, supporting the team isolation functionality described in the PR objectives.
29-29
: Validator correctly updated for the new field.The
original_team_id
field is properly included in the ObjectId validator, ensuring consistent validation behavior with other ObjectId fields in the model.todo/repositories/task_assignment_repository.py (2)
75-80
: Excellent implementation of original team ID tracking.The logic correctly identifies when a task is being reassigned from a team to a user and captures the original team's assignee ID. This preserves the team context information essential for team isolation, ensuring tasks originally assigned to teams remain visible in team views even after individual reassignment.
111-111
: Proper integration of original team ID in new assignment.The
original_team_id
is correctly passed to the new TaskAssignmentModel, completing the chain of team context preservation during reassignment operations.todo/views/task_assignment.py (1)
226-233
: Proper migration to comprehensive assignment update method.The change from
update_executor
toupdate_assignment
ensures that theoriginal_team_id
field is correctly set when tasks are reassigned through the UI. The method call includes the appropriate parameters (executor_id, "user", user_id) and maintains proper error handling.
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Status |
---|---|---|
Misplaced Import Statement ▹ view | ✅ Fix detected | |
Redundant Query Conditions ▹ view | ✅ Fix detected | |
Inefficient List-Set Conversion ▹ view | ✅ Fix detected |
Files scanned
File Path | Reviewed |
---|---|
todo/models/task_assignment.py | ✅ |
todo/repositories/task_assignment_repository.py | ✅ |
todo/views/task_assignment.py | ✅ |
todo/repositories/task_repository.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
…t/PATCH-API-endpoint ncnnc
…at helper method in list and count method
…s and services - Updated CreateTaskAssignmentDTO and TaskAssignmentDTO to replace original_team_id with team_id for clarity. - Adjusted validation methods and repository logic to reflect the new field name. - Ensured consistency across task assignment service and repository for handling team assignments.
Date:
August 3, 2025
Developer Name: @Achintya-Chatterjee
Issue Ticket Number
Description
original_team_id
field toTaskAssignmentModel
to track original team contextTaskAssignmentRepository.update_assignment()
to setoriginal_team_id
when reassigning from team to userTaskRepository.list()
andcount()
to include team member tasks with proper team isolation/v1/tasks?teamId={teamId}
) now include tasks assigned to team membersoriginal_team_id
to prevent cross-team contaminationTaskAssignmentDetailView.patch()
to useupdate_assignment()
instead ofupdate_executor()
original_team_id
is properly set when UI callsPATCH /v1/task-assignments/{task_id}
original_team_id
filteringDocumentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Screen.Recording.2025-08-03.at.01.07.13.mp4
Test Coverage
Screenshot 1
Additional Notes
Description by Korbit AI
What change is being made?
Implement team isolation for task assignments by introducing a
team_id
attribute in the DTOs, models, repositories, services, and views, alongside validators for the new field.Why are these changes being made?
These changes are being made to enhance the functionality of task assignments by accommodating team-based task assignments and reassignment. This approach allows for better tracking of tasks initially assigned to teams, simplifying the process of reallocating tasks between users and organizations, and ensuring correct data integrity and validation throughout the system.