Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into apps/authenticated…
Browse files Browse the repository at this point in the history
…-endpoints
  • Loading branch information
d-gubert committed Jun 28, 2022
2 parents b638c0c + 957c69d commit 150a684
Show file tree
Hide file tree
Showing 166 changed files with 2,263 additions and 1,723 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
steps:
- uses: ggazzo/gh-action-auto-label@beta-5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RC_AUTOLABEL_TOKEN }}
19 changes: 9 additions & 10 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ env:
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://mongo:27017/local
TOOL_NODE_FLAGS: --max_old_space_size=4096
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

jobs:
Expand Down Expand Up @@ -140,17 +139,17 @@ jobs:
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.RC_TURBO_GH_TOKEN }}
server-token: ${{ secrets.TURBO_SERVER_TOKEN }}

- name: Lint
run: yarn lint --api="http://127.0.0.1:9080"
run: yarn lint --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: Translation check
run: yarn turbo run translation-check --api="http://127.0.0.1:9080"
run: yarn turbo run translation-check --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: TS typecheck
run: yarn turbo run typecheck --api="http://127.0.0.1:9080"
run: yarn turbo run typecheck --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: Reset Meteor
if: startsWith(github.ref, 'refs/tags/') == 'true' || github.ref == 'refs/heads/develop'
Expand Down Expand Up @@ -251,11 +250,11 @@ jobs:
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.RC_TURBO_GH_TOKEN }}
server-token: ${{ secrets.TURBO_SERVER_TOKEN }}

- name: Unit Test
run: yarn testunit --api="http://127.0.0.1:9080"
run: yarn testunit --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: Restore build
uses: actions/download-artifact@v2
Expand Down Expand Up @@ -410,14 +409,14 @@ jobs:
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.RC_TURBO_GH_TOKEN }}
server-token: ${{ secrets.TURBO_SERVER_TOKEN }}

- name: yarn install
run: yarn

- name: Unit Test
run: yarn testunit --api="http://127.0.0.1:9080"
run: yarn testunit --api="http://127.0.0.1:9080" --token="${{ secrets.TURBO_SERVER_TOKEN }}" --team='rc'

- name: Restore build
uses: actions/download-artifact@v2
Expand Down Expand Up @@ -681,7 +680,7 @@ jobs:
docker logs presence --tail=50
cd ./apps/meteor
npm run test:playwright
IS_EE=true npm run test:playwright
- name: Store playwright test trace
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/no-new-js-files.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "JS file preventer"
name: 'JS file preventer'
on:
pull_request:
types: [opened, synchronize]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-title-checker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "PR Title Checker"
name: 'PR Title Checker'
on:
pull_request:
types: [opened, edited]
Expand All @@ -9,4 +9,4 @@ jobs:
steps:
- uses: thehanimo/pr-title-checker@v1.3.4
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RC_TITLE_CHECKER }}
8 changes: 6 additions & 2 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
},
Expand All @@ -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);
},
Expand Down Expand Up @@ -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();
},
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
},
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { API } from '../api';
import { hasPermission } from '../../../authorization/server';
import { Imports } from '../../../models/server';
import { Importers } from '../../../importer/server';
import { executeUploadImportFile } from '../../../importer/server/methods/uploadImportFile';

API.v1.addRoute(
'uploadImportFile',
Expand All @@ -26,7 +27,7 @@ API.v1.addRoute(
post() {
const { binaryContent, contentType, fileName, importerKey } = this.bodyParams;

return API.v1.success(Meteor.call('uploadImportFile', binaryContent, contentType, fileName, importerKey));
return API.v1.success(executeUploadImportFile(this.userId, binaryContent, contentType, fileName, importerKey));
},
},
);
Expand Down
56 changes: 36 additions & 20 deletions apps/meteor/app/api/server/v1/voip/rooms.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
import type { ILivechatAgent } from '@rocket.chat/core-typings';
import type { ILivechatAgent, IVoipRoom } from '@rocket.chat/core-typings';
import { isVoipRoomProps, isVoipRoomsProps, isVoipRoomCloseProps } from '@rocket.chat/rest-typings/dist/v1/voip';
import { VoipRoom, LivechatVisitors, Users } from '@rocket.chat/models';
import { isVoipRoomCloseProps } from '@rocket.chat/rest-typings/dist/v1/voip';

import { API } from '../../api';
import { LivechatVoip } from '../../../../../server/sdk';
Expand All @@ -25,6 +24,7 @@ const validateDateParams = (property: string, date: DateParam = {}): DateParam =
const parseAndValidate = (property: string, date?: string): DateParam => {
return validateDateParams(property, parseDateParams(date));
};

/**
* @openapi
* /voip/server/api/v1/voip/room
Expand Down Expand Up @@ -81,23 +81,38 @@ const parseAndValidate = (property: string, date?: string): DateParam => {
* $ref: '#/components/schemas/ApiFailureV1'
*/

const isRoomSearchProps = (props: any): props is { rid: string; token: string } => {
return 'rid' in props && 'token' in props;
};

const isRoomCreationProps = (props: any): props is { agentId: string; direction: IVoipRoom['direction'] } => {
return 'agentId' in props && 'direction' in props;
};

API.v1.addRoute(
'voip/room',
{
authRequired: true,
rateLimiterOptions: { numRequestsAllowed: 5, intervalTimeInMS: 60000 },
permissionsRequired: ['inbound-voip-calls'],
validateParams: isVoipRoomProps,
},
{
async get() {
const defaultCheckParams = {
token: String,
agentId: Match.Maybe(String),
rid: Match.Maybe(String),
};
check(this.queryParams, defaultCheckParams);

const { token, rid, agentId } = this.queryParams;
const { token } = this.queryParams;
let agentId: string | undefined = undefined;
let direction: IVoipRoom['direction'] = 'inbound';
let rid: string | undefined = undefined;

if (isRoomCreationProps(this.queryParams)) {
agentId = this.queryParams.agentId;
direction = this.queryParams.direction;
}

if (isRoomSearchProps(this.queryParams)) {
rid = this.queryParams.rid;
}

const guest = await LivechatVisitors.getVisitorByToken(token, {});
if (!guest) {
return API.v1.failure('invalid-token');
Expand All @@ -123,7 +138,11 @@ API.v1.addRoute(
const agent = { agentId: _id, username };
const rid = Random.id();

return API.v1.success(await LivechatVoip.getNewRoom(guest, agent, rid, { projection: API.v1.defaultFieldsToExclude }));
return API.v1.success(
await LivechatVoip.getNewRoom(guest, agent, rid, direction, {
projection: API.v1.defaultFieldsToExclude,
}),
);
}

const room = await VoipRoom.findOneByIdAndVisitorToken(rid, token, { projection: API.v1.defaultFieldsToExclude });
Expand All @@ -137,20 +156,15 @@ API.v1.addRoute(

API.v1.addRoute(
'voip/rooms',
{ authRequired: true },
{ authRequired: true, validateParams: isVoipRoomsProps },
{
async get() {
const { offset, count } = this.getPaginationItems();

const { sort, fields } = this.parseJsonQuery();
const { agents, open, tags, queue, visitorId } = this.requestParams();
const { agents, open, tags, queue, visitorId, direction, roomName } = this.requestParams();
const { createdAt: createdAtParam, closedAt: closedAtParam } = this.requestParams();

check(agents, Match.Maybe([String]));
check(open, Match.Maybe(String));
check(tags, Match.Maybe([String]));
check(queue, Match.Maybe(String));
check(visitorId, Match.Maybe(String));

// Reusing same L room permissions for simplicity
const hasAdminAccess = hasPermission(this.userId, 'view-livechat-rooms');
const hasAgentAccess = hasPermission(this.userId, 'view-l-room') && agents?.includes(this.userId) && agents?.length === 1;
Expand All @@ -170,6 +184,8 @@ API.v1.addRoute(
visitorId,
createdAt,
closedAt,
direction,
roomName,
options: { sort, offset, count, fields },
}),
);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/emoji/client/emojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Template.emojiPicker.events({
'click .add-custom'(event) {
event.stopPropagation();
event.preventDefault();
FlowRouter.go('/admin/emoji-custom');
FlowRouter.go('/admin/emoji-custom/new');
EmojiPicker.close();
},
'click .category-link'(event) {
Expand Down
Loading

0 comments on commit 150a684

Please sign in to comment.