-
Notifications
You must be signed in to change notification settings - Fork 14
feat(task): add team_id support in task assignment and validation logic #288
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
Conversation
|
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. Summary by CodeRabbit
WalkthroughAdded optional Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Missing help_text in team_id field ▹ view | ||
| 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.
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: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 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:
- Valid team_id is accepted and included in assignee (lines 63-69)
- Invalid team_id triggers validation error (lines 71-76)
- 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:
- Lines 211-260: Verifies task creation with user assignment and team_id, including proper DTO construction with all fields
- Lines 262-298: Confirms team_id is None when not provided, ensuring backward compatibility
- Lines 300-331: Validates team existence check raises ValueError when team not found
- 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.
…eam' to 'assigned_to_member'
574ca5a to
20ef90f
Compare
Date: 29 Oct
Developer Name: @AnujChhikara
Issue Ticket Number
Description
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Screen.Recording.2025-10-29.at.2.22.42.AM.mov
Test Coverage
Screenshot 1
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.