-
Notifications
You must be signed in to change notification settings - Fork 13.8k
chore: migrate audit DDP methods to /v1/audit.* REST endpoints (EE) #40736
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
982fbeb
chore: migrate audit DDP methods to REST endpoints
ggazzo 87e48ef
fix: address TS errors in audit batch
ggazzo 4fac9a7
chore(api): rename audit.omnichannel.messages to audit.omnichannelMes…
ggazzo 141af29
chore: restore hasPermissionAsync import path after Phase 5 rebase
ggazzo f91deb4
chore: fix audit functions import order
ggazzo 92fdcf5
test(api): cover audit.auditions/messages/omnichannelMessages REST en…
ggazzo a4d721d
fix(api): correct audit import paths after develop reorg (statistics,…
ggazzo ecd381b
chore: fix import order and prettier formatting
ggazzo aa451b6
fix(api): restore parseDateOrFail helper dropped during rebase
ggazzo bc8c6c8
docs(audit): document why omnichannel audit skips livechat room restr…
ggazzo 680f2c1
chore(audit): drop stale DDP deprecation warning from shared audit logic
ggazzo 21d508b
test(audit): cover invalid dates + assert audit log entry is persisted
ggazzo 3d3d56f
fix(audit): deserialize audit REST payload instead of force-casting
ggazzo dbe94cb
fix(audit): keep omnichannel audit rids an array to avoid $in: undefined
ggazzo ed0c1be
chore(audit): TODO for dropped omnichannel visitor/agent filters
ggazzo fc2bf62
test(audit): grant can-audit-log to auditor for audit.auditions cases
ggazzo 926531f
chore(api): declare 401/403 response validators on audit endpoints
ggazzo 899bce5
chore(api): tighten audit.auditions response schema (IAuditLog)
ggazzo dc76e17
fix(api): allow null in audit.auditions fields schema
ggazzo 22b3f3d
fix(audit): stop persisting undefined audit fields as null
ggazzo 29ff63a
fix input schema
sampaiodiego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Migrated the audit panel (`AuditLogTable`, `useAuditMutation`) from the three `auditGet*` DDP methods to the new `/v1/audit.*` REST endpoints. DDP methods stay registered with deprecation logs pointing at the new routes until 9.0.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Added three new REST endpoints under `/v1/audit.*` (EE-only, requires the `auditing` license) covering the audit flows that previously only existed as DDP methods: | ||
|
|
||
| - `GET /v1/audit.auditions?startDate=&endDate=` → `{ auditions: IAuditLog[] }` (replaces `auditGetAuditions`, `can-audit-log`) | ||
| - `POST /v1/audit.messages` body `{ rid?, startDate, endDate, users, msg, type, visitor?, agent? }` → `{ messages: IMessage[] }` (replaces `auditGetMessages`, `can-audit`) | ||
| - `POST /v1/audit.omnichannelMessages` body `{ startDate, endDate, users, msg, type, visitor?, agent? }` → `{ messages: IMessage[] }` (replaces `auditGetOmnichannelMessages`, `can-audit`) | ||
|
|
||
| Each endpoint is rate-limited at 10 requests / 60s (matching the DDP `DDPRateLimiter` rules) and writes the same `AuditLog` entry the DDP methods produced. Dates are serialized as ISO strings on the wire. The DDP methods remain registered with deprecation logs pointing at the new routes until 9.0.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,48 @@ | ||
| import type { IAuditLog } from '@rocket.chat/core-typings'; | ||
| import { useMethod } from '@rocket.chat/ui-contexts'; | ||
| import type { IAuditLog, IMessage } from '@rocket.chat/core-typings'; | ||
| import { useEndpoint } from '@rocket.chat/ui-contexts'; | ||
| import { useMutation } from '@tanstack/react-query'; | ||
|
|
||
| import type { AuditFields } from './useAuditForm'; | ||
| import { mapMessageFromApi } from '../../../lib/utils/mapMessageFromApi'; | ||
|
|
||
| export const useAuditMutation = (type: IAuditLog['fields']['type']) => { | ||
| const getAuditMessages = useMethod('auditGetMessages'); | ||
| const getOmnichannelAuditMessages = useMethod('auditGetOmnichannelMessages'); | ||
| const getAuditMessages = useEndpoint('POST', '/v1/audit.messages'); | ||
| const getOmnichannelAuditMessages = useEndpoint('POST', '/v1/audit.omnichannelMessages'); | ||
|
|
||
| return useMutation({ | ||
| mutationKey: ['audit'] as const, | ||
|
|
||
| mutationFn: async ({ msg, dateRange, rid, users, visitor, agent }: AuditFields) => { | ||
| mutationFn: async ({ msg, dateRange, rid, users, visitor, agent }: AuditFields): Promise<IMessage[]> => { | ||
| const startDate = (dateRange.start ?? new Date(0)).toISOString(); | ||
| const endDate = (dateRange.end ?? new Date()).toISOString(); | ||
|
|
||
| if (type === 'l') { | ||
| return getOmnichannelAuditMessages({ | ||
| const { messages } = await getOmnichannelAuditMessages({ | ||
| type, | ||
| msg, | ||
| startDate: dateRange.start ?? new Date(0), | ||
| endDate: dateRange.end ?? new Date(), | ||
| startDate, | ||
| endDate, | ||
| users, | ||
| // TODO: the Omnichannel audit form collects visitor/agent (required fields) but they are | ||
| // dropped here — carried over from the original DDP flow. Forwarding them would let the | ||
| // omnichannel audit filter by the selected visitor/agent. Left for investigation. | ||
| visitor: '', | ||
| agent: '', | ||
| }); | ||
| return messages.map((message) => mapMessageFromApi(message)); | ||
| } | ||
|
|
||
| return getAuditMessages({ | ||
| const { messages } = await getAuditMessages({ | ||
| type, | ||
| msg, | ||
| startDate: dateRange.start ?? new Date(0), | ||
| endDate: dateRange.end ?? new Date(), | ||
| startDate, | ||
| endDate, | ||
| rid, | ||
| users, | ||
| visitor, | ||
| agent, | ||
| }); | ||
| return messages.map((message) => mapMessageFromApi(message)); | ||
| }, | ||
| }); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.