-
Notifications
You must be signed in to change notification settings - Fork 13.7k
feat: audit.settings endpoint
#35258
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 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5387bba
crate endpoint for auditing setting changes
gabriellsh 176dfe6
add cs
gabriellsh a9ad228
refactor: adds minor improvements to logic and endpoint query params
lucas-a-pelegrino b87a99e
tests: adds e2e tests for settings audit endpoint
lucas-a-pelegrino 91e7b08
test: improves audit.settings e2e tests
lucas-a-pelegrino 0d5094f
test: adds e2e test for invalid dates sent to the api
lucas-a-pelegrino 8bd0cc8
chore: uncomments permission required for accessing the endpoint
lucas-a-pelegrino 1695b82
fix: merge conflicts
lucas-a-pelegrino 67b7955
Merge branch 'develop' into new/auditSettingsEndpoint
gabriellsh e533958
Convert to new registering of api
gabriellsh 2c87d62
fix failure response
gabriellsh 704679b
Merge branch 'develop' into new/auditSettingsEndpoint
gabriellsh 6154c2e
Merge branch 'develop' into new/auditSettingsEndpoint
gabriellsh 315684f
Fix openAPI docs
gabriellsh eccabd7
Merge branch 'develop' into new/auditSettingsEndpoint
MartinSchoeler 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,6 @@ | ||
| --- | ||
| "@rocket.chat/meteor": minor | ||
| "@rocket.chat/rest-typings": minor | ||
| --- | ||
|
|
||
| Introduces `/v1/audit.settings` endpoint for querying changed settings audit events |
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { ServerEvents } from '@rocket.chat/models'; | ||
| import { isServerEventsAuditSettingsProps } from '@rocket.chat/rest-typings'; | ||
|
|
||
| import { API } from '../api'; | ||
| import { getPaginationItems } from '../helpers/getPaginationItems'; | ||
|
|
||
| API.v1.addRoute( | ||
| 'audit.settings', | ||
| { authRequired: true, validateParams: isServerEventsAuditSettingsProps /* , permissionsRequired: ['can-audit'] */ }, | ||
| { | ||
| async get() { | ||
| const { start, end, sort, settingId, actor } = this.queryParams; | ||
|
|
||
| if (start && isNaN(Date.parse(start))) { | ||
| return API.v1.failure('The "start" query parameter must be a valid date.'); | ||
| } | ||
|
|
||
| if (end && isNaN(Date.parse(end))) { | ||
| return API.v1.failure('The "end" query parameter must be a valid date.'); | ||
| } | ||
|
|
||
| const { offset, count } = await getPaginationItems(this.queryParams); | ||
| const _sort = { ts: sort?.ts ? sort.ts : -1 }; | ||
|
|
||
| const { cursor, totalCount } = ServerEvents.findPaginated( | ||
| { | ||
| ...(settingId && { 'data.key': 'id', 'data.value': settingId }), | ||
| ...(actor && { actor }), | ||
| ts: { | ||
| $gte: start ? new Date(start) : new Date(0), | ||
| $lte: end ? new Date(end) : new Date(), | ||
| }, | ||
| t: 'settings.changed', | ||
| }, | ||
| { | ||
| sort: _sort, | ||
| skip: offset, | ||
| limit: count, | ||
| allowDiskUse: true, | ||
| }, | ||
| ); | ||
|
|
||
| const [events, total] = await Promise.all([cursor.toArray(), totalCount]); | ||
|
|
||
| return API.v1.success({ | ||
| events, | ||
| count: events.length, | ||
| offset, | ||
| total, | ||
| }); | ||
| }, | ||
| }, | ||
| ); | ||
|
gabriellsh marked this conversation as resolved.
|
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
78 changes: 78 additions & 0 deletions
78
packages/rest-typings/src/v1/server-events/ServerEventsAuditSettingsParamsGET.ts
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,78 @@ | ||
| import type { IAuditServerActor } from '@rocket.chat/core-typings'; | ||
| import Ajv from 'ajv'; | ||
|
|
||
| import type { PaginatedRequest } from '../../helpers/PaginatedRequest'; | ||
|
|
||
| const ajv = new Ajv({ | ||
| coerceTypes: true, | ||
| }); | ||
|
|
||
| export type ServerEventsAuditSettingsParamsGET = PaginatedRequest<{ | ||
| start?: string; | ||
| end?: string; | ||
| settingId?: string; | ||
| actor?: IAuditServerActor; | ||
| }>; | ||
|
|
||
| const ServerEventsAuditSettingsParamsGetSchema = { | ||
| type: 'object', | ||
| properties: { | ||
| sort: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| count: { | ||
| type: 'number', | ||
| nullable: true, | ||
| }, | ||
| offset: { | ||
| type: 'number', | ||
| nullable: true, | ||
| }, | ||
| start: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| end: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| settingId: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| actor: { | ||
| type: 'object', | ||
| nullable: true, | ||
| properties: { | ||
| type: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| _id: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| username: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| ip: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| useragent: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| reason: { | ||
| type: 'string', | ||
| nullable: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| additionalProperties: false, | ||
| }; | ||
|
|
||
| export const isServerEventsAuditSettingsProps = ajv.compile<ServerEventsAuditSettingsParamsGET>(ServerEventsAuditSettingsParamsGetSchema); |
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,2 @@ | ||
| export * from './ServerEventsAuditSettingsParamsGET'; | ||
| export * from './server-events'; |
12 changes: 12 additions & 0 deletions
12
packages/rest-typings/src/v1/server-events/server-events.ts
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,12 @@ | ||
| import type { IServerEvents } from '@rocket.chat/core-typings'; | ||
|
|
||
| import type { ServerEventsAuditSettingsParamsGET } from './ServerEventsAuditSettingsParamsGET'; | ||
| import type { PaginatedResult } from '../../helpers/PaginatedResult'; | ||
|
|
||
| export type ServerEventsEndpoints = { | ||
| '/v1/audit.settings': { | ||
| GET: (params: ServerEventsAuditSettingsParamsGET) => PaginatedResult<{ | ||
| events: IServerEvents['settings.changed'][]; | ||
| }>; | ||
| }; | ||
| }; |
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.