From 5109cd3590804cd534c064ba632c2d05cb142636 Mon Sep 17 00:00:00 2001 From: Luciano Marcos Pierdona Junior <64279791+LucianoPierdona@users.noreply.github.com> Date: Mon, 27 Jun 2022 08:41:52 -0300 Subject: [PATCH 1/5] Regression: Room Endpoint Call Issues (#25928) --- apps/meteor/app/api/server/v1/channels.ts | 8 ++++++-- .../room/contextualBar/Info/RoomInfo/RoomInfoWithData.js | 6 +++--- .../views/teams/contextualBar/channels/RoomActions.js | 6 +++--- .../views/teams/contextualBar/info/TeamsInfoWithData.js | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/meteor/app/api/server/v1/channels.ts b/apps/meteor/app/api/server/v1/channels.ts index 484c2a077081..e77826fd14fc 100644 --- a/apps/meteor/app/api/server/v1/channels.ts +++ b/apps/meteor/app/api/server/v1/channels.ts @@ -20,7 +20,7 @@ import { } from '@rocket.chat/rest-typings'; import { Rooms, Subscriptions, Messages } from '../../../models/server'; -import { hasPermission, hasAllPermission } from '../../../authorization/server'; +import { hasPermission } from '../../../authorization/server'; import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser'; import { API } from '../api'; import { Team } from '../../../../server/sdk'; @@ -454,7 +454,7 @@ API.v1.addRoute( }, { async post() { - if (!hasAllPermission(this.userId, ['create-team', 'edit-room'])) { + if (!hasPermission(this.userId, 'create-team')) { return API.v1.unauthorized(); } @@ -464,6 +464,10 @@ API.v1.addRoute( return API.v1.failure('The parameter "channelId" or "channelName" is required'); } + if (!hasPermission(this.userId, 'edit-room', channelId)) { + return API.v1.unauthorized(); + } + const room = findChannelByIdOrName({ params: { roomId: channelId, diff --git a/apps/meteor/client/views/room/contextualBar/Info/RoomInfo/RoomInfoWithData.js b/apps/meteor/client/views/room/contextualBar/Info/RoomInfo/RoomInfoWithData.js index adf20054512c..55ba60e259cf 100644 --- a/apps/meteor/client/views/room/contextualBar/Info/RoomInfo/RoomInfoWithData.js +++ b/apps/meteor/client/views/room/contextualBar/Info/RoomInfo/RoomInfoWithData.js @@ -56,15 +56,15 @@ const RoomInfoWithData = ({ rid, openEditing, onClickBack, onEnterRoom, resetSta const dispatchToastMessage = useToastMessageDispatch(); const setModal = useSetModal(); const closeModal = useMutableCallback(() => setModal()); - const deleteRoom = useEndpoint('POST', room.t === 'c' ? 'channels.delete' : 'groups.delete'); + const deleteRoom = useEndpoint('POST', room.t === 'c' ? '/v1/channels.delete' : '/v1/groups.delete'); const hideRoom = useMethod('hideRoom'); const leaveRoom = useMethod('leaveRoom'); const router = useRoute('home'); - const moveChannelToTeam = useEndpointActionExperimental('POST', 'teams.addRooms', t('Rooms_added_successfully')); + const moveChannelToTeam = useEndpointActionExperimental('POST', '/v1/teams.addRooms', t('Rooms_added_successfully')); const convertRoomToTeam = useEndpointActionExperimental( 'POST', - type === 'c' ? 'channels.convertToTeam' : 'groups.convertToTeam', + type === 'c' ? '/v1/channels.convertToTeam' : '/v1/groups.convertToTeam', t('Success'), ); diff --git a/apps/meteor/client/views/teams/contextualBar/channels/RoomActions.js b/apps/meteor/client/views/teams/contextualBar/channels/RoomActions.js index c47f2b9bab2f..4f332441ccad 100644 --- a/apps/meteor/client/views/teams/contextualBar/channels/RoomActions.js +++ b/apps/meteor/client/views/teams/contextualBar/channels/RoomActions.js @@ -30,11 +30,11 @@ const RoomActions = ({ room, reload }) => { const canEditTeamChannel = usePermission('edit-team-channel', rid); const canRemoveTeamChannel = usePermission('remove-team-channel', rid); - const updateRoomEndpoint = useEndpointActionExperimental('POST', 'teams.updateRoom'); - const removeRoomEndpoint = useEndpointActionExperimental('POST', 'teams.removeRoom', t('Room_has_been_removed')); + const updateRoomEndpoint = useEndpointActionExperimental('POST', '/v1/teams.updateRoom'); + const removeRoomEndpoint = useEndpointActionExperimental('POST', '/v1/teams.removeRoom', t('Room_has_been_removed')); const deleteRoomEndpoint = useEndpointActionExperimental( 'POST', - room.t === 'c' ? 'channels.delete' : 'groups.delete', + room.t === 'c' ? '/v1/channels.delete' : '/v1/groups.delete', t('Room_has_been_deleted'), ); diff --git a/apps/meteor/client/views/teams/contextualBar/info/TeamsInfoWithData.js b/apps/meteor/client/views/teams/contextualBar/info/TeamsInfoWithData.js index de4d72d14e0e..c49d310543e4 100644 --- a/apps/meteor/client/views/teams/contextualBar/info/TeamsInfoWithData.js +++ b/apps/meteor/client/views/teams/contextualBar/info/TeamsInfoWithData.js @@ -60,9 +60,9 @@ const TeamsInfoWithLogic = ({ room, openEditing }) => { const setModal = useSetModal(); const closeModal = useMutableCallback(() => setModal()); - const deleteTeam = useEndpointActionExperimental('POST', 'teams.delete'); - const leaveTeam = useEndpointActionExperimental('POST', 'teams.leave'); - const convertTeamToChannel = useEndpointActionExperimental('POST', 'teams.convertToChannel'); + const deleteTeam = useEndpointActionExperimental('POST', '/v1/teams.delete'); + const leaveTeam = useEndpointActionExperimental('POST', '/V1/teams.leave'); + const convertTeamToChannel = useEndpointActionExperimental('POST', '/v1/teams.convertToChannel'); const hideTeam = useMethod('hideRoom'); From cf921acc8a48b67f2ad7f1ee9344889a68b9530d Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Mon, 27 Jun 2022 08:50:07 -0300 Subject: [PATCH 2/5] Chore: convert e2e to ts (#25958) Co-authored-by: Guilherme Gazzo --- .../app/api/server/v1/{e2e.js => e2e.ts} | 70 +++++++++++-------- apps/meteor/client/sidebar/RoomMenu.tsx | 2 +- .../client/sidebar/search/SearchList.tsx | 1 + packages/rest-typings/src/index.ts | 4 ++ packages/rest-typings/src/v1/e2e.ts | 4 +- .../e2eGetUsersOfRoomWithoutKeyParamsGET.ts | 24 +++++++ .../src/v1/e2e/e2eSetRoomKeyIDParamsPOST.ts | 26 +++++++ ...2eSetUserPublicAndPrivateKeysParamsPOST.ts | 29 ++++++++ .../src/v1/e2e/e2eUpdateGroupKeyParamsPOST.ts | 30 ++++++++ 9 files changed, 159 insertions(+), 31 deletions(-) rename apps/meteor/app/api/server/v1/{e2e.js => e2e.ts} (75%) create mode 100644 packages/rest-typings/src/v1/e2e/e2eGetUsersOfRoomWithoutKeyParamsGET.ts create mode 100644 packages/rest-typings/src/v1/e2e/e2eSetRoomKeyIDParamsPOST.ts create mode 100644 packages/rest-typings/src/v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST.ts create mode 100644 packages/rest-typings/src/v1/e2e/e2eUpdateGroupKeyParamsPOST.ts diff --git a/apps/meteor/app/api/server/v1/e2e.js b/apps/meteor/app/api/server/v1/e2e.ts similarity index 75% rename from apps/meteor/app/api/server/v1/e2e.js rename to apps/meteor/app/api/server/v1/e2e.ts index f079e75b8119..13939b1caf0d 100644 --- a/apps/meteor/app/api/server/v1/e2e.js +++ b/apps/meteor/app/api/server/v1/e2e.ts @@ -1,16 +1,26 @@ +/* eslint-disable @typescript-eslint/camelcase */ import { Meteor } from 'meteor/meteor'; +import { + ise2eGetUsersOfRoomWithoutKeyParamsGET, + ise2eSetRoomKeyIDParamsPOST, + ise2eSetUserPublicAndPrivateKeysParamsPOST, + ise2eUpdateGroupKeyParamsPOST, +} from '@rocket.chat/rest-typings'; +import { IUser } from '@rocket.chat/core-typings'; import { API } from '../api'; API.v1.addRoute( 'e2e.fetchMyKeys', - { authRequired: true }, + { + authRequired: true, + }, { get() { - let result; - Meteor.runAsUser(this.userId, () => { - result = Meteor.call('e2e.fetchMyKeys'); - }); + const result: { + public_key: string; + private_key: string; + } = Meteor.call('e2e.fetchMyKeys'); return API.v1.success(result); }, @@ -19,15 +29,17 @@ API.v1.addRoute( API.v1.addRoute( 'e2e.getUsersOfRoomWithoutKey', - { authRequired: true }, + { + authRequired: true, + validateParams: ise2eGetUsersOfRoomWithoutKeyParamsGET, + }, { get() { const { rid } = this.queryParams; - let result; - Meteor.runAsUser(this.userId, () => { - result = Meteor.call('e2e.getUsersOfRoomWithoutKey', rid); - }); + const result: { + users: IUser[]; + } = Meteor.call('e2e.getUsersOfRoomWithoutKey', rid); return API.v1.success(result); }, @@ -65,16 +77,18 @@ API.v1.addRoute( * schema: * $ref: '#/components/schemas/ApiFailureV1' */ + API.v1.addRoute( 'e2e.setRoomKeyID', - { authRequired: true }, + { + authRequired: true, + validateParams: ise2eSetRoomKeyIDParamsPOST, + }, { post() { const { rid, keyID } = this.bodyParams; - Meteor.runAsUser(this.userId, () => { - API.v1.success(Meteor.call('e2e.setRoomKeyID', rid, keyID)); - }); + Meteor.call('e2e.setRoomKeyID', rid, keyID); return API.v1.success(); }, @@ -114,18 +128,17 @@ API.v1.addRoute( */ API.v1.addRoute( 'e2e.setUserPublicAndPrivateKeys', - { authRequired: true }, + { + authRequired: true, + validateParams: ise2eSetUserPublicAndPrivateKeysParamsPOST, + }, { post() { - const { public_key, private_key } = this.bodyParams; - - Meteor.runAsUser(this.userId, () => { - API.v1.success( - Meteor.call('e2e.setUserPublicAndPrivateKeys', { - public_key, - private_key, - }), - ); + const { public_key, private_key } = Meteor.call('e2e.fetchMyKeys'); + + Meteor.call('e2e.setUserPublicAndPrivateKeys', { + public_key, + private_key, }); return API.v1.success(); @@ -168,14 +181,15 @@ API.v1.addRoute( */ API.v1.addRoute( 'e2e.updateGroupKey', - { authRequired: true }, + { + authRequired: true, + validateParams: ise2eUpdateGroupKeyParamsPOST, + }, { post() { const { uid, rid, key } = this.bodyParams; - Meteor.runAsUser(this.userId, () => { - API.v1.success(Meteor.call('e2e.updateGroupKey', rid, uid, key)); - }); + Meteor.call('e2e.updateGroupKey', rid, uid, key); return API.v1.success(); }, diff --git a/apps/meteor/client/sidebar/RoomMenu.tsx b/apps/meteor/client/sidebar/RoomMenu.tsx index 0457fb5096b7..b6f493a8dd05 100644 --- a/apps/meteor/client/sidebar/RoomMenu.tsx +++ b/apps/meteor/client/sidebar/RoomMenu.tsx @@ -202,7 +202,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name = aria-keyshortcuts='alt' tabIndex={-1} options={menuOptions} - renderItem={({ label: { label, icon }, ...props }) =>