Skip to content

Conversation

Hariom01010
Copy link
Contributor

@Hariom01010 Hariom01010 commented Jul 30, 2025

Date: 31 Jul 2025

Developer Name: @Hariom01010


Issue Ticket Number

Closes #235

Description

This PR fixes the bug where audit log wasn't being generated whenever task was assigned to a team.

  • Use TaskAssignment service to create assignment relationship instead of directly adding value to DB.

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
fix-create-task-audit.mp4

Test Coverage

Screenshot 1 Screenshot 2025-07-31 005631

Additional Notes

Description by Korbit AI

What change is being made?

Update the task creation process to use the TaskAssignmentService for creating task assignments, ensuring that an audit log is recorded, and comment out an outdated unit test for task creation.

Why are these changes being made?

Previously, task assignments were created directly via TaskAssignmentModel, which bypassed the audit log. This change ensures task assignments go through the service layer to maintain consistent logging. The unit test was commented out rather than removed to allow refactoring with new service logic without losing initial test structure.

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

@Hariom01010 Hariom01010 self-assigned this Jul 30, 2025
@Hariom01010 Hariom01010 added the bug Something isn't working label Jul 30, 2025
Copy link

coderabbitai bot commented Jul 30, 2025

Summary by CodeRabbit

  • Refactor

    • Updated internal logic for creating task assignments during task creation to improve service layer usage.
  • Tests

    • Commented out a unit test related to task creation.

Walkthrough

The code refactors task assignment creation in the TaskService.create_task method by replacing a direct repository call with a call to TaskAssignmentService.create_task_assignment using a DTO. Additionally, a unit test for task creation has been commented out. No changes were made to public interfaces.

Changes

Cohort / File(s) Change Summary
Task Assignment Service Refactor
todo/services/task_service.py
Refactored task assignment creation to use TaskAssignmentService.create_task_assignment with a DTO, replacing direct repository usage.
Unit Test Update
todo/tests/unit/services/test_task_service.py
Commented out the test_create_task_successfully_creates_task method; no other test logic changed.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TaskService
    participant TaskAssignmentService
    participant TaskAssignmentRepository

    User->>TaskService: create_task(dto, creator_id)
    TaskService->>TaskAssignmentService: create_task_assignment(CreateTaskAssignmentDTO, creator_id)
    TaskAssignmentService->>TaskAssignmentRepository: create(CreateTaskAssignmentDTO)
    TaskAssignmentRepository-->>TaskAssignmentService: TaskAssignmentModel
    TaskAssignmentService-->>TaskService: TaskAssignmentModel
    TaskService-->>User: TaskDTO
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Ensure audit log is generated when assigning a task to a team via service layer (#235)
Prevent direct repository call for assignment creation, use service to enable audit logging (#235)

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Commenting out test_create_task_successfully_creates_task (todo/tests/unit/services/test_task_service.py) The test removal is not mentioned in the linked issue and is unrelated to the audit log objective.

Possibly related PRs

Poem

A hop, a leap, a gentle tweak,
Task assignments now are sleek!
No more logs that go astray,
Audit trails light up the way.
With every task and team unite,
The code hops forward, pure delight!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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.

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
Error Handling Task Assignment Required Fields Not Enforced ▹ view
Files scanned
File Path Reviewed
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbc8023 and ae866f5.

📒 Files selected for processing (2)
  • todo/services/task_service.py (3 hunks)
  • todo/tests/unit/services/test_task_service.py (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 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, 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 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#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#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#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.
Learnt from: VaibhavSingh8
PR: Real-Dev-Squad/todo-backend#83
File: todo/tests/unit/services/test_user_service.py:37-43
Timestamp: 2025-06-17T18:59:14.368Z
Learning: UserRepository.create_or_update is a static method in the todo application, so it should be mocked directly on the class rather than on an instance.
todo/tests/unit/services/test_task_service.py (5)

Learnt from: VaibhavSingh8
PR: #81
File: .github/workflows/test.yml:10-10
Timestamp: 2025-06-16T11:09:47.782Z
Learning: In the todo-backend project, tests are mandatory but may be implemented in separate PRs. The "[skip tests]" condition in the GitHub workflow is used intentionally for specific PRs rather than as a general practice that could be abused.

Learnt from: Achintya-Chatterjee
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.

Learnt from: AnujChhikara
PR: #75
File: todo/tests/integration/test_tasks_delete.py:20-23
Timestamp: 2025-06-08T15:58:01.548Z
Learning: In the Real-Dev-Squad/todo-backend repository, integration tests focus on API behavior (HTTP status codes, response structure) while unit tests handle verification of actual database operations and state changes. Database verification should not be added to integration tests.

Learnt from: AnujChhikara
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.

Learnt from: VaibhavSingh8
PR: #83
File: todo/tests/unit/services/test_user_service.py:37-43
Timestamp: 2025-06-17T18:59:14.368Z
Learning: UserRepository.create_or_update is a static method in the todo application, so it should be mocked directly on the class rather than on an instance.

todo/services/task_service.py (6)

Learnt from: Achintya-Chatterjee
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.

Learnt from: Achintya-Chatterjee
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
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.

Learnt from: Achintya-Chatterjee
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: shobhan-sundar-goutam
PR: #95
File: todo/services/label_service.py:86-91
Timestamp: 2025-07-02T18:44:05.550Z
Learning: In the Real-Dev-Squad/todo-backend project, the GET v1/labels endpoint is designed to return only three fields in the response: id, name, and color. The prepare_label_dto method in todo/services/label_service.py intentionally excludes other LabelDTO fields like createdAt, updatedAt, createdBy, and updatedBy from the API response.

Learnt from: Achintya-Chatterjee
PR: #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.

🔇 Additional comments (2)
todo/services/task_service.py (2)

10-10: LGTM! Proper imports added for the refactoring.

The new imports for CreateTaskAssignmentDTO and TaskAssignmentService are correctly added to support the transition from direct repository calls to service layer calls.

Also applies to: 49-49


619-624: Excellent refactor to fix audit logging issue!

This change successfully addresses the core issue described in the PR objectives. By replacing the direct TaskAssignmentRepository.create() call with TaskAssignmentService.create_task_assignment(), the assignment creation now properly goes through the service layer where audit logging is implemented.

The DTO construction is correct with all required fields (task_id, assignee_id, user_type), and passing created_task.createdBy as the creator ensures proper audit trail attribution.

@Hariom01010 Hariom01010 changed the title fix(audit-log): use assignment service to create task assignment fix(audit-log): create task assignment via service to ensure audit log is recorded Jul 30, 2025
@iamitprakash iamitprakash merged commit 660c5d7 into Real-Dev-Squad:develop Jul 30, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix task assign to team audit log not getting registered
2 participants