Skip to content

Conversation

@AnujChhikara
Copy link
Contributor

@AnujChhikara AnujChhikara commented Oct 28, 2025

Date: 29 Oct

Developer Name: @AnujChhikara


Issue Ticket Number

Description

  • Introduced team_id field in CreateTaskSerializer to allow optional team assignment for user tasks.
  • Updated validation to ensure team_id is valid when provided.
  • Enhanced TaskAssignmentService to log assignments involving users from teams.
  • Added unit tests to verify team_id handling in task creation and assignment scenarios.

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-10-29.at.2.22.42.AM.mov

Test Coverage

Screenshot 1 image

Additional Notes

Description by Korbit AI

What change is being made?

Enable optional team_id support in task assignment and validation flow across serializers, services, and tests; validate team_id when provided, pass it through to the assignee structure, audit team-related assignments, and update tests to cover valid/invalid/empty team_id scenarios.

Why are these changes being made?

To allow tasks to be assigned to a user within a specific team, with proper validation and auditing, while preserving existing behavior for assignments without a team context. This adds team-scoped assignment support and accompanying test coverage.

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

@AnujChhikara AnujChhikara self-assigned this Oct 28, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 28, 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.

Summary by CodeRabbit

  • New Features

    • Tasks can now be assigned to users within a specific team context. When assigning a task to a user, you can optionally specify the team they belong to.
    • Team validation ensures specified teams exist when provided.
    • Audit logging tracks team-based assignments for accountability.
  • Tests

    • Added comprehensive unit tests covering team-based task assignment scenarios, including validation and edge cases.

Walkthrough

Added optional team_id field to task assignment workflow. When creating a task with user assignment, team_id can now be specified alongside assignee_id and validated for existence. Updated serializer, services, and DTOs to accept and propagate team association through the assignment pipeline.

Changes

Cohort / File(s) Summary
Serializer Updates
todo/serializers/create_task_serializer.py
Added optional team_id field to CreateTaskSerializer; conditionally includes team_id in assignee dictionary when provided and non-empty; validates team_id as ObjectId when supplied.
Service Logic
todo/services/task_service.py, todo/services/task_assignment_service.py
Extended task_service.py to validate team_id existence when provided with user-type assignments and derive team_id flexibly based on assignment type; updated CreateTaskAssignmentDTO to include optional team_id field; added audit logging in task_assignment_service.py for user assignments with team_id.
Serializer Tests
todo/tests/unit/serializers/test_create_task_serializer.py
Added three test methods covering valid team_id acceptance, invalid team_id rejection, and empty team_id handling.
Service Tests
todo/tests/unit/services/test_task_service.py
Added comprehensive test coverage for task creation with user assignments including team_id, validation of team existence, and DTO field propagation.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Serializer as CreateTaskSerializer
    participant TaskService
    participant TeamRepo as TeamRepository
    participant TaskAssignmentService
    
    Client->>Serializer: POST task with assignee_id, user_type, team_id
    Serializer->>Serializer: Validate team_id as ObjectId
    Serializer-->>Client: validated_data with assignee (includes team_id)
    
    Client->>TaskService: create_task(validated_data)
    TaskService->>TaskService: Extract assignee, team_id
    alt user_type = "user" AND team_id provided
        TaskService->>TeamRepo: get_by_id(team_id)
        alt Team exists
            TeamRepo-->>TaskService: Team
            TaskService->>TaskService: Create task with team_id in assignment
        else Team not found
            TeamRepo-->>TaskService: None
            TaskService-->>Client: ValueError
        end
    end
    
    TaskService->>TaskAssignmentService: create_task_assignment(DTO with team_id)
    TaskAssignmentService->>TaskAssignmentService: Log "assigned_to_user_from_team" if applicable
    TaskAssignmentService-->>TaskService: Assignment created
    TaskService-->>Client: Task with assignment
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Focus areas requiring attention:
    • Validation logic in CreateTaskSerializer for conditional team_id inclusion in assignee dictionary
    • Team existence validation in TaskService.create_task and error handling path
    • Correct propagation of team_id through CreateTaskAssignmentDTO to assignment service
    • Test coverage comprehensiveness for edge cases (empty string, invalid ObjectId, missing team)

Possibly related PRs

Suggested labels

tests

Suggested reviewers

  • iamitprakash
  • Hariom01010
  • shobhan-sundar-goutam

Poem

🐰 A team's context now travels through tasks so true,
From serializer to service, the team_id shines through!
Validation checks carefully, assignments align,
With tests catching edge cases—a feature divine! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "feat(task): add team_id support in task assignment and validation logic" directly and accurately summarizes the main changes in the changeset. The PR introduces team_id support across multiple components—the serializer, services, and tests—with associated validation and audit logging enhancements. The title captures the primary objective without being vague or misleading, and it is sufficiently specific for teammates scanning PR history to understand the core change.
Description Check ✅ Passed The pull request description clearly relates to the changeset and provides specific, meaningful information about the changes being made. The author describes adding a team_id field to CreateTaskSerializer with validation, enhancing TaskAssignmentService for logging team-related assignments, and adding unit tests for team_id handling. These descriptions align well with the actual code modifications across the serializer, services, DTO, and test files documented in the raw summary. The description is neither vague nor off-topic, and provides sufficient detail about the intent and scope of the changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch anuj/add-team_id

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added the tests Adds or updates tests label Oct 28, 2025
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 Missing help_text in team_id field ▹ view
Functionality Duplicate audit logs for user-team assignments on updates ▹ view
Files scanned
File Path Reviewed
todo/serializers/create_task_serializer.py
todo/services/task_assignment_service.py
todo/services/task_service.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

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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cecdf9 and 574ca5a.

📒 Files selected for processing (5)
  • todo/serializers/create_task_serializer.py (2 hunks)
  • todo/services/task_assignment_service.py (1 hunks)
  • todo/services/task_service.py (2 hunks)
  • todo/tests/unit/serializers/test_create_task_serializer.py (1 hunks)
  • todo/tests/unit/services/test_task_service.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-25T20:12:36.483Z
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/services/task_service.py
🧬 Code graph analysis (5)
todo/serializers/create_task_serializer.py (1)
todo/constants/messages.py (1)
  • ValidationErrors (62-88)
todo/tests/unit/services/test_task_service.py (2)
todo/dto/task_dto.py (2)
  • CreateTaskDTO (37-63)
  • TaskDTO (14-34)
todo/services/task_service.py (1)
  • create_task (594-684)
todo/services/task_service.py (2)
todo/repositories/team_repository.py (1)
  • get_by_id (53-64)
todo/exceptions/user_exceptions.py (1)
  • UserNotFoundException (4-13)
todo/tests/unit/serializers/test_create_task_serializer.py (1)
todo/serializers/create_task_serializer.py (1)
  • CreateTaskSerializer (9-98)
todo/services/task_assignment_service.py (3)
todo/repositories/audit_log_repository.py (2)
  • AuditLogRepository (7-50)
  • create (11-44)
todo/models/audit_log.py (1)
  • AuditLogModel (8-25)
todo/models/common/pyobjectid.py (1)
  • PyObjectId (4-15)
🔇 Additional comments (4)
todo/serializers/create_task_serializer.py (1)

45-49: LGTM! Clean handling of optional team_id.

The implementation correctly:

  • Allows empty, null, and blank values (lines 45-49)
  • Strips whitespace before validation (line 74)
  • Validates non-empty values as ObjectId (lines 75-76)
  • Excludes empty team_id from assignee payload (line 79)

This defensive approach prevents invalid or empty team_id values from propagating downstream.

Also applies to: 66-66, 74-79

todo/services/task_service.py (1)

608-611: LGTM! Proper team validation for user assignments.

The validation correctly ensures that when a team_id is provided for a user assignment, the team exists before proceeding with task creation. This prevents orphaned references.

todo/tests/unit/serializers/test_create_task_serializer.py (1)

63-84: LGTM! Comprehensive test coverage for team_id handling.

The three tests thoroughly validate serializer behavior:

  1. Valid team_id is accepted and included in assignee (lines 63-69)
  2. Invalid team_id triggers validation error (lines 71-76)
  3. Empty team_id is properly excluded from assignee (lines 78-84)

All key scenarios are covered with appropriate assertions.

todo/tests/unit/services/test_task_service.py (1)

211-379: LGTM! Thorough test coverage for team_id integration.

The four new tests comprehensively validate the team_id feature:

  1. Lines 211-260: Verifies task creation with user assignment and team_id, including proper DTO construction with all fields
  2. Lines 262-298: Confirms team_id is None when not provided, ensuring backward compatibility
  3. Lines 300-331: Validates team existence check raises ValueError when team not found
  4. Lines 333-379: Confirms team_id propagates correctly to TaskAssignmentService

All critical paths are covered with appropriate mocks and assertions. The tests verify both the happy path and error conditions.

@iamitprakash iamitprakash merged commit 92ad665 into develop Nov 1, 2025
2 checks passed
@iamitprakash iamitprakash deleted the anuj/add-team_id branch November 1, 2025 19:32
@korbit-ai
Copy link

korbit-ai bot commented Nov 1, 2025

I was unable to write a description for this pull request. This could be because I only found files I can't scan.

@AnujChhikara AnujChhikara mentioned this pull request Nov 3, 2025
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Adds or updates tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task created on team page not appearing on team dashboard

4 participants