-
Notifications
You must be signed in to change notification settings - Fork 14
feat: enhance audit logging for team management actions #233
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
- Updated AuditLogModel to include additional action types: "team_created", "member_joined_team", "member_added_to_team", "member_removed_from_team", and "team_updated". - Implemented audit logging in TeamService for team creation, member joining, member addition, member removal, and team updates to improve tracking of team activities. - Modified RemoveTeamMemberView to pass the user performing the removal for better audit trail. These changes improve accountability and traceability of team management actions.
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
WalkthroughThis change enhances audit logging for team-related actions. It updates documentation for possible audit log actions, adds audit log entries to key team lifecycle and membership methods, and modifies the method for removing team members to record the user performing the removal. The API view is updated to pass the correct user ID for audit logging. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant RemoveTeamMemberView
participant TeamService
participant AuditLogRepository
User->>RemoveTeamMemberView: DELETE /team/:team_id/member/:user_id
RemoveTeamMemberView->>TeamService: remove_member_from_team(user_id, team_id, removed_by_user_id=request.user_id)
TeamService->>AuditLogRepository: create(AuditLogModel(..., action="member_removed_from_team", performed_by=removed_by_user_id))
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
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. 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)
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Status |
---|---|---|
Incomplete Member Addition Audit Log ▹ view | ✅ Fix detected |
Files scanned
File Path | Reviewed |
---|---|
todo/models/audit_log.py | ✅ |
todo/services/team_service.py | ✅ |
todo/views/team.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.
- Removed the unused datetime and timezone import from team_service.py to streamline the code and improve maintainability. This change contributes to a cleaner and more organized codebase.
- Removed unnecessary blank lines in the team_service.py file to improve code readability and maintainability. This change contributes to a cleaner and more organized codebase.
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 (3)
todo/models/audit_log.py
(1 hunks)todo/services/team_service.py
(6 hunks)todo/views/team.py
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
todo/views/team.py (1)
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.
todo/services/team_service.py (1)
Learnt from: VaibhavSingh8
PR: #81
File: todo/repositories/user_repository.py:47-55
Timestamp: 2025-06-16T19:35:44.948Z
Learning: The constant RepositoryErrors.USER_OPERATION_FAILED in todo/constants/messages.py is defined as "User operation failed" without any placeholder formatting like {0}.
🧬 Code Graph Analysis (1)
todo/services/team_service.py (4)
todo/models/audit_log.py (1)
AuditLogModel
(8-25)todo/repositories/audit_log_repository.py (1)
AuditLogRepository
(6-22)todo/models/common/pyobjectid.py (1)
PyObjectId
(4-15)todo/repositories/user_team_details_repository.py (2)
remove_member_from_team
(9-31)UserTeamDetailsRepository
(5-31)
🪛 GitHub Actions: Tests
todo/services/team_service.py
[error] 11-11: ESLint: 'datetime.datetime' imported but unused. (F401) Remove unused import.
[error] 11-11: ESLint: 'datetime.timezone' imported but unused. (F401) Remove unused import.
🔇 Additional comments (7)
todo/models/audit_log.py (1)
16-16
: LGTM! Documentation properly updated for new team audit actions.The comment accurately reflects the new team-related audit action types that are being implemented in the service layer.
todo/views/team.py (1)
476-477
: LGTM! Correctly integrates with updated service method for audit logging.The change properly passes the current user's ID to track who performed the team member removal action, supporting the new audit logging functionality.
todo/services/team_service.py (5)
96-103
: LGTM! Audit logging correctly implemented for team creation.The audit log entry properly records the team creation event with the correct team_id, action type, and performer.
241-248
: LGTM! Audit logging correctly implemented for team join.The audit log entry properly records when a user joins a team via invite code, with the correct team_id, action type, and the joining user as the performer.
307-314
: LGTM! Audit logging correctly implemented for team updates.The audit log entry properly records team update events with the correct team_id, action type, and performer.
427-427
: LGTM! Method signature correctly updated to support audit logging.The addition of the optional
removed_by_user_id
parameter enables proper tracking of who performed the removal action, which aligns with the audit logging requirements.
434-441
: LGTM! Audit logging correctly implemented for member removal.The audit log entry properly handles the removal action, with a sensible fallback to use the removed user's ID if no remover is specified (though this should rarely happen given the view layer now passes the current user).
- Updated the audit logging in TeamService to include the added member's ID in the details of the "member_added_to_team" action. This change improves the traceability of team member additions, enhancing accountability in team management activities.
- Added a missing comma in the details dictionary of the "member_added_to_team" action in TeamService. This minor fix ensures proper syntax and prevents potential issues in the logging functionality.
Description by Korbit AI
What change is being made?
Enhance audit logging to track key actions in team management, including team creation, joining a team, updating a team, adding members, and removing members, by updating the
AuditLogModel
and implementing logging within service functions.Why are these changes being made?
These changes provide a comprehensive audit trail for all significant team management activities, improving accountability and traceability within the application. By logging each action with associated user involvement, we enhance the ability to monitor actions and ensure compliance with governance standards.