Skip to content

Commit

Permalink
Merge branch 'develop' into lingohub_language_update_2022-08-29Z
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 2, 2022
2 parents 7445749 + 50b252b commit c3f6f30
Show file tree
Hide file tree
Showing 59 changed files with 4,553 additions and 690 deletions.
2,710 changes: 2,710 additions & 0 deletions .github/history.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
LATEST_RELEASE="$(
git -c 'versionsort.suffix=-' ls-remote -t --exit-code --refs --sort=-v:refname "https://github.com/$GITHUB_REPOSITORY" '*' |
sed -En '1!q;s/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/gp'
awk -F/ '$NF !~ /rc|beta/ { print $NF; exit }'
)"
echo "LATEST_RELEASE: ${LATEST_RELEASE}"
echo "::set-output name=latest-release::${LATEST_RELEASE}"
Expand Down
980 changes: 925 additions & 55 deletions HISTORY.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/meteor/.docker/Dockerfile.rhel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM registry.access.redhat.com/ubi8/nodejs-12

ENV RC_VERSION 5.1.0-develop
ENV RC_VERSION 5.2.0-develop

MAINTAINER buildmaster@rocket.chat

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ API.v1.addRoute(
{
post() {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { public_key, private_key } = Meteor.call('e2e.fetchMyKeys');
const { public_key, private_key } = this.bodyParams;

Meteor.call('e2e.setUserPublicAndPrivateKeys', {
public_key,
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/autotranslate/client/lib/autotranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {

import { Subscriptions, Messages } from '../../../models/client';
import { hasPermission } from '../../../authorization/client';
import { callWithErrorHandling } from '../../../../client/lib/utils/callWithErrorHandling';
import { call } from '../../../../client/lib/utils/call';

let userLanguage = 'en';
let username = '';
Expand Down Expand Up @@ -102,8 +102,8 @@ export const AutoTranslate = {

try {
[this.providersMetadata, this.supportedLanguages] = await Promise.all([
callWithErrorHandling('autoTranslate.getProviderUiMetadata'),
callWithErrorHandling('autoTranslate.getSupportedLanguages', 'en'),
call('autoTranslate.getProviderUiMetadata'),
call('autoTranslate.getSupportedLanguages', 'en'),
]);
} catch (e: unknown) {
// Avoid unwanted error message on UI when autotranslate is disabled while fetching data
Expand Down
38 changes: 22 additions & 16 deletions apps/meteor/app/livechat/imports/server/rest/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ API.v1.addRoute(
'livechat/rooms',
{ authRequired: true },
{
get() {
async get() {
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
const { agents, departmentId, open, tags, roomName, onhold } = this.requestParams();
Expand All @@ -32,6 +32,7 @@ API.v1.addRoute(
check(open, Match.Maybe(String));
check(onhold, Match.Maybe(String));
check(tags, Match.Maybe([String]));
check(customFields, Match.Maybe(String));

createdAt = validateDateParams('createdAt', createdAt);
closedAt = validateDateParams('closedAt', closedAt);
Expand All @@ -43,24 +44,29 @@ API.v1.addRoute(
}

if (customFields) {
customFields = JSON.parse(customFields);
try {
const parsedCustomFields = JSON.parse(customFields);
check(parsedCustomFields, Object);
// Model's already checking for the keys, so we don't need to do it here.
customFields = parsedCustomFields;
} catch (e) {
throw new Error('The "customFields" query parameter must be a valid JSON.');
}
}

return API.v1.success(
Promise.await(
findRooms({
agents,
roomName,
departmentId,
open: open && open === 'true',
createdAt,
closedAt,
tags,
customFields,
onhold,
options: { offset, count, sort, fields },
}),
),
await findRooms({
agents,
roomName,
departmentId,
open: open && open === 'true',
createdAt,
closedAt,
tags,
customFields,
onhold,
options: { offset, count, sort, fields },
}),
);
},
},
Expand Down
94 changes: 43 additions & 51 deletions apps/meteor/app/livechat/server/api/v1/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,64 @@ import { Livechat } from '../../lib/Livechat';

API.v1.addRoute('livechat/agent.info/:rid/:token', {
async get() {
try {
check(this.urlParams, {
rid: String,
token: String,
});
check(this.urlParams, {
rid: String,
token: String,
});

const visitor = await findGuest(this.urlParams.token);
if (!visitor) {
throw new Meteor.Error('invalid-token');
}

const room = findRoom(this.urlParams.token, this.urlParams.rid);
if (!room) {
throw new Meteor.Error('invalid-room');
}
const visitor = await findGuest(this.urlParams.token);
if (!visitor) {
throw new Meteor.Error('invalid-token');
}

const agent = room && room.servedBy && findAgent(room.servedBy._id);
if (!agent) {
throw new Meteor.Error('invalid-agent');
}
const room = findRoom(this.urlParams.token, this.urlParams.rid);
if (!room) {
throw new Meteor.Error('invalid-room');
}

return API.v1.success({ agent });
} catch (e) {
return API.v1.failure(e);
const agent = room && room.servedBy && findAgent(room.servedBy._id);
if (!agent) {
throw new Meteor.Error('invalid-agent');
}

return API.v1.success({ agent });
},
});

API.v1.addRoute('livechat/agent.next/:token', {
get() {
try {
check(this.urlParams, {
token: String,
});
check(this.urlParams, {
token: String,
});

check(this.queryParams, {
department: Match.Maybe(String),
});
check(this.queryParams, {
department: Match.Maybe(String),
});

const { token } = this.urlParams;
const room = findOpenRoom(token);
if (room) {
return API.v1.success();
}

let { department } = this.queryParams;
if (!department) {
const requireDeparment = Livechat.getRequiredDepartment();
if (requireDeparment) {
department = requireDeparment._id;
}
}
const { token } = this.urlParams;
const room = findOpenRoom(token);
if (room) {
return API.v1.success();
}

const agentData = Promise.await(Livechat.getNextAgent(department));
if (!agentData) {
throw new Meteor.Error('agent-not-found');
let { department } = this.queryParams;
if (!department) {
const requireDeparment = Livechat.getRequiredDepartment();
if (requireDeparment) {
department = requireDeparment._id;
}
}

const agent = findAgent(agentData.agentId);
if (!agent) {
throw new Meteor.Error('invalid-agent');
}
const agentData = Promise.await(Livechat.getNextAgent(department));
if (!agentData) {
throw new Meteor.Error('agent-not-found');
}

return API.v1.success({ agent });
} catch (e) {
return API.v1.failure(e);
const agent = findAgent(agentData.agentId);
if (!agent) {
throw new Meteor.Error('invalid-agent');
}

return API.v1.success({ agent });
},
});
34 changes: 15 additions & 19 deletions apps/meteor/app/livechat/server/api/v1/customField.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,25 @@ import { findLivechatCustomFields, findCustomFieldById } from '../lib/customFiel

API.v1.addRoute('livechat/custom.field', {
async post() {
try {
check(this.bodyParams, {
token: String,
key: String,
value: String,
overwrite: Boolean,
});

const { token, key, value, overwrite } = this.bodyParams;
check(this.bodyParams, {
token: String,
key: String,
value: String,
overwrite: Boolean,
});

const guest = await findGuest(token);
if (!guest) {
throw new Meteor.Error('invalid-token');
}
const { token, key, value, overwrite } = this.bodyParams;

if (!(await Livechat.setCustomFields({ token, key, value, overwrite }))) {
return API.v1.failure();
}
const guest = await findGuest(token);
if (!guest) {
throw new Meteor.Error('invalid-token');
}

return API.v1.success({ field: { key, value, overwrite } });
} catch (e) {
return API.v1.failure(e);
if (!(await Livechat.setCustomFields({ token, key, value, overwrite }))) {
return API.v1.failure();
}

return API.v1.success({ field: { key, value, overwrite } });
},
});

Expand Down
89 changes: 41 additions & 48 deletions apps/meteor/app/livechat/server/api/v1/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,36 +234,33 @@ API.v1.addRoute(
{ authRequired: true, permissionsRequired: ['view-l-room'] },
{
put() {
try {
check(this.bodyParams, {
rid: String,
oldVisitorId: String,
newVisitorId: String,
});

const { rid, newVisitorId, oldVisitorId } = this.bodyParams;

const { visitor } = Promise.await(findVisitorInfo({ userId: this.userId, visitorId: newVisitorId }));
if (!visitor) {
throw new Meteor.Error('invalid-visitor');
}

let room = LivechatRooms.findOneById(rid, { _id: 1 }); // TODO: check _id
if (!room) {
throw new Meteor.Error('invalid-room');
}

const { v: { _id: roomVisitorId } = {} } = room; // TODO: v it will be undefined
if (roomVisitorId !== oldVisitorId) {
throw new Meteor.Error('invalid-room-visitor');
}

room = Livechat.changeRoomVisitor(this.userId, rid, visitor);

return API.v1.success({ room });
} catch (e) {
return API.v1.failure(e);
// This endpoint is deprecated and will be removed in future versions.
check(this.bodyParams, {
rid: String,
oldVisitorId: String,
newVisitorId: String,
});

const { rid, newVisitorId, oldVisitorId } = this.bodyParams;

const { visitor } = Promise.await(findVisitorInfo({ userId: this.userId, visitorId: newVisitorId }));
if (!visitor) {
throw new Meteor.Error('invalid-visitor');
}

let room = LivechatRooms.findOneById(rid, { _id: 1, v: 1 }); // TODO: check _id
if (!room) {
throw new Meteor.Error('invalid-room');
}

const { v: { _id: roomVisitorId } = {} } = room; // TODO: v it will be undefined
if (roomVisitorId !== oldVisitorId) {
throw new Meteor.Error('invalid-room-visitor');
}

room = Livechat.changeRoomVisitor(this.userId, rid, visitor);

return API.v1.success({ room });
},
},
);
Expand All @@ -273,33 +270,29 @@ API.v1.addRoute(
{ authRequired: true, permissionsRequired: ['view-l-room'] },
{
get() {
try {
check(this.queryParams, { roomId: String });
check(this.queryParams, { roomId: String });

const { roomId } = this.queryParams;
const { roomId } = this.queryParams;

const { user } = this;
const { user } = this;

if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'joinRoom' });
}
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'joinRoom' });
}

const room = LivechatRooms.findOneById(roomId);
const room = LivechatRooms.findOneById(roomId);

if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'joinRoom' });
}
if (!room) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'joinRoom' });
}

if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'joinRoom' });
}
if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'joinRoom' });
}

addUserToRoom(roomId, user);
addUserToRoom(roomId, user);

return API.v1.success();
} catch (e) {
return API.v1.failure(e);
}
return API.v1.success();
},
},
);
Loading

0 comments on commit c3f6f30

Please sign in to comment.