-
Notifications
You must be signed in to change notification settings - Fork 13.7k
chore: migrate five more client DDP callers to new REST endpoints #40724
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
Changes from all commits
11e390a
78d9a22
cdf3c36
f9a53d7
7748b60
c08edfb
f4d49d8
8ec18f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Migrate four client DDP callers to their REST equivalents (the DDP methods stay registered on the server for external SDK/mobile clients, with a deprecation log pointing at the REST route until 9.0.0 removes them): | ||
|
|
||
| - `deleteCustomSound` → `POST /v1/custom-sounds.delete` | ||
| - `blockUser` / `unblockUser` → `POST /v1/im.blockUser` (single toggle with `{ roomId, block: boolean }`) | ||
| - `saveSettings` → `POST /v1/settings` | ||
| - `e2e.requestSubscriptionKeys` → `POST /v1/e2e.requestSubscriptionKeys` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Added `POST /v1/e2e.requestSubscriptionKeys` (replaces the deprecated `e2e.requestSubscriptionKeys` DDP method). Auth-gated, no body. Broadcasts `notify.e2e.keyRequest` for every encrypted room the caller is subscribed to without an E2E key, matching the DDP method's behavior. The legacy DDP method remains registered until 9.0.0 with a deprecation log pointing at the new route. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Added `POST /v1/im.blockUser` (replaces the deprecated `blockUser` / `unblockUser` DDP methods). Body is `{ roomId, block: boolean }` — `block: true` blocks the other DM participant, `block: false` unblocks. Auth-gated and per-room via the `RoomMemberActions.BLOCK` directive (DM-only). Both legacy DDP methods remain registered until 9.0.0 with deprecation logs pointing at the new route. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@rocket.chat/rest-typings': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Added `POST /v1/settings` for batched admin setting updates (replaces the deprecated `saveSettings` DDP method). Body is `{ settings: { _id, value }[] }`. The endpoint requires authentication, enforces 2FA (`twoFactorRequired: true`), and runs the same per-setting permission chain (`edit-privileged-setting` OR `manage-selected-settings` + per-id permission) and audit/notify side effects the DDP method already performed. The legacy DDP method remains registered until 9.0.0 with a deprecation log pointing at the new route. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { handleSuggestedGroupKey } from '../../../e2e/server/functions/handleSug | |||||||||||||||||||||||
| import { provideUsersSuggestedGroupKeys } from '../../../e2e/server/functions/provideUsersSuggestedGroupKeys'; | ||||||||||||||||||||||||
| import { resetRoomKey } from '../../../e2e/server/functions/resetRoomKey'; | ||||||||||||||||||||||||
| import { getUsersOfRoomWithoutKeyMethod } from '../../../e2e/server/methods/getUsersOfRoomWithoutKey'; | ||||||||||||||||||||||||
| import { requestSubscriptionKeysMethod } from '../../../e2e/server/methods/requestSubscriptionKeys'; | ||||||||||||||||||||||||
| import { setRoomKeyIDMethod } from '../../../e2e/server/methods/setRoomKeyID'; | ||||||||||||||||||||||||
| import { setUserPublicAndPrivateKeysMethod } from '../../../e2e/server/methods/setUserPublicAndPrivateKeys'; | ||||||||||||||||||||||||
| import { updateGroupKey } from '../../../e2e/server/methods/updateGroupKey'; | ||||||||||||||||||||||||
|
|
@@ -196,6 +197,24 @@ const e2eEndpoints = API.v1 | |||||||||||||||||||||||
| return API.v1.success(); | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .post( | ||||||||||||||||||||||||
| 'e2e.requestSubscriptionKeys', | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| authRequired: true, | ||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||
| 401: validateUnauthorizedErrorResponse, | ||||||||||||||||||||||||
| 200: ajv.compile<void>({ | ||||||||||||||||||||||||
| type: 'object', | ||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||
|
Comment on lines
+206
to
+208
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally the return type should be correctly enforced.
Suggested change
|
||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| async function action() { | ||||||||||||||||||||||||
| await requestSubscriptionKeysMethod(this.userId); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return API.v1.success(); | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .get( | ||||||||||||||||||||||||
| 'e2e.fetchMyKeys', | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,10 @@ import { | |
| isSettingsUpdatePropsColor, | ||
| isSettingsPublicWithPaginationProps, | ||
| isSettingsGetParams, | ||
| isSettingsBulkProps, | ||
| validateForbiddenErrorResponse, | ||
| validateUnauthorizedErrorResponse, | ||
| validateBadRequestErrorResponse, | ||
| } from '@rocket.chat/rest-typings'; | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import type { FindOptions } from 'mongodb'; | ||
|
|
@@ -25,6 +27,7 @@ import _ from 'underscore'; | |
| import { updateAuditedByUser } from '../../../../server/settings/lib/auditedSettingUpdates'; | ||
| import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; | ||
| import { disableCustomScripts } from '../../../lib/server/functions/disableCustomScripts'; | ||
| import { saveSettingsBulk } from '../../../lib/server/functions/saveSettingsBulk'; | ||
| import { checkSettingValueBounds } from '../../../lib/server/lib/checkSettingValueBonds'; | ||
| import { notifyOnSettingChanged, notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener'; | ||
| import { addOAuthServiceMethod } from '../../../lib/server/methods/addOAuthService'; | ||
|
|
@@ -404,6 +407,31 @@ API.v1.post( | |
| }, | ||
| ); | ||
|
|
||
| API.v1.post( | ||
| 'settings', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Renaming the bulk settings endpoint from Prompt for AI agents |
||
| { | ||
| authRequired: true, | ||
| twoFactorRequired: true, | ||
| twoFactorOptions: { disableRememberMe: true }, | ||
| body: isSettingsBulkProps, | ||
| response: { | ||
| 200: settingByIdPostResponseSchema, | ||
| 400: validateBadRequestErrorResponse, | ||
| 401: validateUnauthorizedErrorResponse, | ||
| 403: validateForbiddenErrorResponse, | ||
| }, | ||
| }, | ||
| async function action() { | ||
| await saveSettingsBulk(this.userId, this.bodyParams.settings, { | ||
| username: this.user.username ?? '', | ||
| ip: this.requestIp ?? '', | ||
| useragent: this.request.headers.get('user-agent') ?? '', | ||
| }); | ||
|
|
||
| return API.v1.success(); | ||
| }, | ||
| ); | ||
|
|
||
| API.v1.get( | ||
| 'service.configurations', | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { Subscriptions, Rooms } from '@rocket.chat/models'; | ||
| import { Meteor } from 'meteor/meteor'; | ||
|
|
||
| import { RoomMemberActions } from '../../../../definition/IRoomTypeConfig'; | ||
| import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator'; | ||
| import { notifyOnSubscriptionChangedByRoomIdAndUserIds } from '../lib/notifyListener'; | ||
|
|
||
| export const blockUserMethod = async (userId: string, { rid, blocked }: { rid: string; blocked: string }): Promise<void> => { | ||
| const room = await Rooms.findOne({ _id: rid }); | ||
|
|
||
| if (!room) { | ||
| throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'blockUser' }); | ||
| } | ||
|
|
||
| if (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.BLOCK, userId))) { | ||
| throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'blockUser' }); | ||
| } | ||
|
|
||
| const [blockedUser, blockerUser] = await Promise.all([ | ||
| Subscriptions.findOneByRoomIdAndUserId(rid, blocked, { projection: { _id: 1 } }), | ||
| Subscriptions.findOneByRoomIdAndUserId(rid, userId, { projection: { _id: 1 } }), | ||
| ]); | ||
|
|
||
| if (!blockedUser || !blockerUser) { | ||
| throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'blockUser' }); | ||
| } | ||
|
|
||
| const [blockedResponse, blockerResponse] = await Subscriptions.setBlockedByRoomId(rid, blocked, userId); | ||
|
|
||
| const listenerUsers = [...(blockedResponse?.modifiedCount ? [blocked] : []), ...(blockerResponse?.modifiedCount ? [userId] : [])]; | ||
|
|
||
| if (listenerUsers.length) { | ||
| void notifyOnSubscriptionChangedByRoomIdAndUserIds(rid, listenerUsers); | ||
| } | ||
| }; |
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.
Version bump and package scope inconsistency.
This changeset declares a
patchbump for@rocket.chat/meteoronly, but the individual endpoint changesets (rest-custom-sounds-delete.md, rest-e2e-request-subscription-keys.md, rest-settings-bulk.md, rest-users-block-unblock.md) all declareminorbumps for both@rocket.chat/rest-typingsand@rocket.chat/meteor. Since this PR adds new REST endpoints (new public API surface) and introduces new types/validators in@rocket.chat/rest-typings(per the stack context), this changeset should match the others.📝 Suggested fix
🤖 Prompt for AI Agents