Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

feat: Implement moderation audit log feature

Open muditjain2204 opened this issue 6 months ago • 4 comments

feat: Adding a Moderation Audit log how i achieve this : - do model registration in db in models.ts -> hooked the 4 feat that have to add ( deactivate , flag, dismiss, mute)
deactivate = make active user throws in to audit log mute = it logs when an admin /moderator mutes an user dismiss = logs when admin dismiss the report against user flag = if a user is report to other user then it gets validation of it

for report the moderator/user cant do to itself , so i have login to the test id and i runs perfectly on clicking three dots we can see report user option if we click on that we can find the user in the moderation/report user path

Proposed changes (including videos or screenshots)

Screenshot 2026-06-03 025842 Screenshot 2026-06-03 025855 Screenshot 2026-06-03 025910 Screenshot 2026-06-03 025918 image

Issue(s)

#40003

Steps to test or reproduce

you can make a test user and do the following steps in the above screen shots u can see how i have made a new user and toggle the deactivate button and then i have checked the audit log

Further comments

Summary by CodeRabbit

  • New Features
    • Added moderation audit logging for key actions (dismiss, deactivate, flag, mute), capturing timestamps, moderator identity, target user details, account age, and an optional reason.
    • Added an admin “Audit” tab in the moderation console with a searchable/sortable audit logs table and pagination.
    • Introduced a secured API endpoint to retrieve moderation audit logs via count/offset pagination and optional sorting.
  • Bug Fixes
    • Improved audit event timestamp consistency when recording report-related actions.

muditjain2204 avatar Jun 02 '26 22:06 muditjain2204

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

dionisio-bot[bot] avatar Jun 02 '26 22:06 dionisio-bot[bot]

⚠️ No Changeset found

Latest commit: bf355cd6dd0ce61ab2784e788b1d8e87bcef7bc0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jun 02 '26 22:06 changeset-bot[bot]

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Jun 02 '26 22:06 CLAassistant

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bd461d05-871c-4a67-b108-dc6135f70c5c

📥 Commits

Reviewing files that changed from the base of the PR and between d01a71241ae7252b7cac7ed1b816fa921e2718bb and bf355cd6dd0ce61ab2784e788b1d8e87bcef7bc0.

📒 Files selected for processing (1)
  • apps/meteor/app/api/server/v1/users.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/api/server/v1/users.ts

Walkthrough

This PR implements a comprehensive moderation audit logging system for Rocket.Chat. It adds a new database model to persist moderation actions (mute, deactivate, flag, dismiss), integrates logging into existing moderation endpoints, provides a paginated REST API to query audit logs, and delivers a client-side React component with sorting and pagination for viewing moderation events.

Changes

Moderation Audit Logging System

Layer / File(s) Summary
Data Model and MongoDB Integration
packages/core-typings/src/IModerationAuditLogs.ts, packages/core-typings/src/index.ts, packages/model-typings/src/models/IModerationAuditLogsModel.ts, packages/model-typings/src/index.ts, packages/models/src/models/ModerationAuditLogs.ts, packages/models/src/modelClasses.ts, packages/models/src/index.ts, apps/meteor/server/models.ts
Defines IModerationAuditLog interface with moderator/target user identities, action type ('mute' | 'deactivate' | 'flag' | 'dismiss'), target account age in seconds, and optional reason; implements ModerationAuditLogsRaw MongoDB model with indexes on timestamp, moderator ID, target user ID, and action; wires model through typing packages and server models registry.
Moderation Action Logging Service
apps/meteor/server/lib/moderation/logModerationAction.ts
Implements logModerationAction async function that accepts moderator/target user IDs, action type, and optional reason; fetches user records with projections, computes target account age from createdAt, and inserts audit log entry to ModerationAuditLogs collection.
Logging Integration into Existing Endpoints
apps/meteor/app/api/server/v1/moderation.ts, apps/meteor/app/api/server/v1/users.ts, apps/meteor/server/methods/muteUserInRoom.ts
Integrates logModerationAction calls into dismissReports, dismissUserReports, reportUser endpoints and users.setActiveStatus handler; also logs mute actions in muteUserInRoom with room context; each call supplies moderator/target IDs and contextual reason strings.
Audit Logs Query Endpoint
apps/meteor/app/api/server/v1/moderation.ts, packages/rest-typings/src/v1/moderation/moderation.ts
Adds new GET /v1/moderation.auditLogs endpoint that queries paginated moderation audit logs from ModerationAuditLogs collection; supports count, offset, and sort query parameters with default sort descending by timestamp; returns validated PaginatedResult<{ logs: IModerationAuditLog[] }> response.
Client Audit Logs UI and Routing
apps/meteor/client/views/admin/moderation/ModerationConsoleRoute.tsx, apps/meteor/client/views/admin/moderation/ModerationConsolePage.tsx, apps/meteor/client/views/admin/moderation/ModerationAuditLogsTable.tsx
Expands moderation console routing to include new "audit" tab; updates moderation page to render ModerationAuditLogsTable for audit tab; implements table component that fetches logs via useQuery, displays sortable columns (timestamp, action, target user, account age, moderator, reason), maps action types to translated labels, formats account age in compact time units, and provides pagination controls.
End-to-End Tests
apps/meteor/tests/end-to-end/api/moderation.ts
Adds test coverage for GET /v1/moderation.auditLogs endpoint, asserting successful response with JSON validation and paginated logs array.

Sequence Diagrams

sequenceDiagram
  participant Moderator as Moderator
  participant Endpoint as Moderation/User Endpoint
  participant Logger as logModerationAction
  participant DB as MongoDB<br/>moderation_audit_logs
  Moderator->>Endpoint: API call (dismissReports/<br/>reportUser/muteUser/setActiveStatus)
  Endpoint->>Logger: logModerationAction(moderatorId,<br/>targetUserId, action, reason)
  Logger->>DB: fetch users, compute age,<br/>insert audit log
  DB-->>Logger: success
  Logger-->>Endpoint: void
  Endpoint-->>Moderator: action response
sequenceDiagram
  participant Admin as Admin User
  participant Page as ModerationConsolePage
  participant Table as ModerationAuditLogsTable
  participant API as GET /v1/moderation.auditLogs
  Admin->>Page: navigate to audit tab
  Page->>Table: render with tab=audit
  Table->>API: useQuery({sort, count, offset})
  API-->>Table: {logs, count, offset, total}
  Table-->>Admin: render table + pagination
  Admin->>Table: click sort column header
  Table->>Table: update sort state
  Table->>API: useQuery({new sort, count, offset})
  API-->>Table: re-sorted logs
  Table-->>Admin: updated table display

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Implement moderation audit log feature' directly and clearly describes the main change—adding a complete moderation audit log feature across the codebase with logging, UI, and API endpoints.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

[!WARNING]

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (2)
  • C1921AC8-5616: Request failed with status code 401
  • FEATURE-1: Request failed with status code 401

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[bot] avatar Jun 02 '26 22:06 coderabbitai[bot]