Skip to content

Conversation

Achintya-Chatterjee
Copy link
Member

@Achintya-Chatterjee Achintya-Chatterjee commented Aug 2, 2025

Date: August 3, 2025

Developer Name: @Achintya-Chatterjee


Issue Ticket Number

Description

  • 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={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}
  • Prevents data type mismatches in original_team_id filtering

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
Screen.Recording.2025-08-03.at.01.07.13.mp4

Test Coverage

Screenshot 1 Screenshot 2025-08-03 at 01 05 05

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.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

- 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
@Achintya-Chatterjee Achintya-Chatterjee self-assigned this Aug 2, 2025
Copy link

korbit-ai bot commented Aug 2, 2025

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 /korbit-review.

Your admin can change your review schedule in the Korbit Console

Copy link

coderabbitai bot commented Aug 2, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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 skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • New Features

    • Added tracking of the original team when a task is reassigned from a team to an individual user.
    • Tasks assigned to individual team members now appear in team task lists if originally assigned to the team, improving visibility and team isolation.
  • Bug Fixes

    • Updated error messages for assignment updates to provide clearer feedback.
  • Chores

    • Removed unnecessary debug statements for cleaner logs.

Walkthrough

A new optional field, original_team_id, was added to the task assignment model to track the originating team when a task is reassigned from a team to a user. Filtering logic in task queries was updated to consider this new field, and assignment update flows now preserve the original team ID when relevant.

Changes

Cohort / File(s) Change Summary
TaskAssignmentModel field & validation
todo/models/task_assignment.py
Added optional original_team_id field to TaskAssignmentModel and updated the validator to include this field when checking for valid ObjectIds.
Assignment update logic
todo/repositories/task_assignment_repository.py
Modified update_assignment to capture the original team ID when reassigning a task from a team to a user, and to store this in the new assignment record.
Task filtering by team
todo/repositories/task_repository.py
Enhanced list and count methods to include tasks assigned to team members with a matching original_team_id, using UserTeamDetailsRepository and TaskAssignmentRepository for user and assignment lookups. Removed debug logging.
Assignment update endpoint
todo/views/task_assignment.py
Updated patch method to use update_assignment with new parameters and error messages, removed debug print statements and traceback imports, and renamed result variable for clarity.

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • shobhan-sundar-goutam
  • iamitprakash

Poem

In the warren of code, a new path appears,
Where tasks remember their teams through the years.
Assignments now track where they once did belong,
So bunnies and teams can all hop along.
With queries improved and logic refined,
This patch leaves no carrot behind! 🥕

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/show-todo-list-assigned-to-team-member

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Achintya-Chatterjee Achintya-Chatterjee marked this pull request as ready for review August 2, 2025 19:49
Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 660c5d7 and 77e831b.

📒 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 to update_assignment ensures that the original_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.

Copy link

@korbit-ai korbit-ai bot left a 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
Readability Misplaced Import Statement ▹ view ✅ Fix detected
Performance Redundant Query Conditions ▹ view ✅ Fix detected
Performance 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.

Loving Korbit!? Share us on LinkedIn Reddit and X

Achintya-Chatterjee and others added 5 commits August 5, 2025 00:08
…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.
@iamitprakash iamitprakash merged commit 02ba88d into develop Aug 6, 2025
3 checks passed
@iamitprakash iamitprakash deleted the fix/show-todo-list-assigned-to-team-member branch August 6, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

show todo in a teams todo list when it is assigned to a team member
5 participants