Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
Browse files Browse the repository at this point in the history
…/mentionBot

* 'develop' of github.com:RocketChat/Rocket.Chat:
  chore: move Omnichannel toolbox section from sidebar room list (#30502)
  fix: RTL lang crashes Moderation Console  (#30393)
  feat: New records page analytics tab (#30373)
  chore: Changing some key translations - Setup Wizard (#30462)
  feat: use isolated-vm to run integration scripts (#30229)
  fix: do not broadcast events from the local node to the local service (duplicated event) (#30446)
  fix: Microsoft autotranslate not working (#30390)
  chore: `ResetPasswordPage` a11y improvements (#30479)
  chore: `ResetPasswordForm` a11y improvements (#30476)
  chore: Move bad words filter callback to service (#30241)
  fix: Message disappears from room after deletion even if "Show Deleted Status" is enabled (#30452)
  chore: add tooltip to mentions (#30445)
  • Loading branch information
gabriellsh committed Sep 28, 2023
2 parents 06a3ebb + 2872428 commit 507c808
Show file tree
Hide file tree
Showing 76 changed files with 1,810 additions and 856 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-snakes-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed an issue where broadcasted events were published twice within the same instance
5 changes: 5 additions & 0 deletions .changeset/fluffy-monkeys-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Changed the name of the administration Logs page to "Records", implemented a tab layout in this page and added a new tab called "Analytic reports" that shows the most recent result of the statistics endpoint.
5 changes: 5 additions & 0 deletions .changeset/kind-books-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed message disappearing from room after erased even if "Show Deleted Status" is enabled
8 changes: 8 additions & 0 deletions .changeset/thirty-pumpkins-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rocket.chat/core-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/tools': minor
'@rocket.chat/meteor': minor
---

Added option to select between two script engine options for the integrations
5 changes: 5 additions & 0 deletions apps/meteor/.docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ RUN set -x \
&& npm install [email protected] \
&& mv node_modules/sharp npm/node_modules/sharp \
# End hack for sharp
# Start hack for isolated-vm...
&& rm -rf npm/node_modules/isolated-vm \
&& npm install [email protected] \
&& mv node_modules/isolated-vm npm/node_modules/isolated-vm \
# End hack for isolated-vm
&& cd npm \
&& npm rebuild bcrypt --build-from-source \
&& npm cache clear --force \
Expand Down
5 changes: 2 additions & 3 deletions apps/meteor/app/api/server/v1/channels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Team } from '@rocket.chat/core-services';
import { Team, Room } from '@rocket.chat/core-services';
import type { IRoom, ISubscription, IUser, RoomType } from '@rocket.chat/core-typings';
import { Integrations, Messages, Rooms, Subscriptions, Uploads, Users } from '@rocket.chat/models';
import {
Expand Down Expand Up @@ -31,7 +31,6 @@ import { saveRoomSettings } from '../../../channel-settings/server/methods/saveR
import { mountIntegrationQueryBasedOnPermissions } from '../../../integrations/server/lib/mountQueriesBasedOnPermission';
import { addUsersToRoomMethod } from '../../../lib/server/methods/addUsersToRoom';
import { createChannelMethod } from '../../../lib/server/methods/createChannel';
import { joinRoomMethod } from '../../../lib/server/methods/joinRoom';
import { leaveRoomMethod } from '../../../lib/server/methods/leaveRoom';
import { settings } from '../../../settings/server';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';
Expand Down Expand Up @@ -209,7 +208,7 @@ API.v1.addRoute(
const { joinCode, ...params } = this.bodyParams;
const findResult = await findChannelByIdOrName({ params });

await joinRoomMethod(this.userId, findResult._id, joinCode);
await Room.join({ room: findResult, user: this.user, joinCode });

return API.v1.success({
channel: await findChannelByIdOrName({ params, userId: this.userId }),
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/autotranslate/server/msTranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MsAutoTranslate extends AutoTranslate {
if (this.supportedLanguages[target]) {
return this.supportedLanguages[target];
}
const request = await fetch(this.apiEndPointUrl);
const request = await fetch(this.apiGetLanguages);
if (!request.ok) {
throw new Error(request.statusText);
}
Expand Down
29 changes: 0 additions & 29 deletions apps/meteor/app/discussion/server/hooks/joinDiscussionOnMessage.ts

This file was deleted.

155 changes: 13 additions & 142 deletions apps/meteor/app/integrations/server/api/api.js
Original file line number Diff line number Diff line change
@@ -1,114 +1,21 @@
import { Integrations, Users } from '@rocket.chat/models';
import * as Models from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import { Livechat } from 'meteor/rocketchat:livechat';
import moment from 'moment';
import _ from 'underscore';
import { VM, VMScript } from 'vm2';

import * as s from '../../../../lib/utils/stringUtils';
import { deasyncPromise } from '../../../../server/deasync/deasync';
import { httpCall } from '../../../../server/lib/http/call';
import { API, APIClass, defaultRateLimiterOptions } from '../../../api/server';
import { processWebhookMessage } from '../../../lib/server/functions/processWebhookMessage';
import { settings } from '../../../settings/server';
import { IsolatedVMScriptEngine } from '../lib/isolated-vm/isolated-vm';
import { VM2ScriptEngine } from '../lib/vm2/vm2';
import { incomingLogger } from '../logger';
import { addOutgoingIntegration } from '../methods/outgoing/addOutgoingIntegration';
import { deleteOutgoingIntegration } from '../methods/outgoing/deleteOutgoingIntegration';

const DISABLE_INTEGRATION_SCRIPTS = ['yes', 'true'].includes(String(process.env.DISABLE_INTEGRATION_SCRIPTS).toLowerCase());
const vm2Engine = new VM2ScriptEngine(true);
const ivmEngine = new IsolatedVMScriptEngine(true);

export const forbiddenModelMethods = ['registerModel', 'getCollectionName'];

const compiledScripts = {};
function buildSandbox(store = {}) {
const httpAsync = async (method, url, options) => {
try {
return {
result: await httpCall(method, url, options),
};
} catch (error) {
return { error };
}
};

const sandbox = {
scriptTimeout(reject) {
return setTimeout(() => reject('timed out'), 3000);
},
_,
s,
console,
moment,
Promise,
Livechat,
Store: {
set(key, val) {
store[key] = val;
return val;
},
get(key) {
return store[key];
},
},
HTTP: (method, url, options) => {
// TODO: deprecate, track and alert
return deasyncPromise(httpAsync(method, url, options));
},
// TODO: Export fetch as the non deprecated method
};
Object.keys(Models)
.filter((k) => !forbiddenModelMethods.includes(k))
.forEach((k) => {
sandbox[k] = Models[k];
});
return { store, sandbox };
}

function getIntegrationScript(integration) {
if (DISABLE_INTEGRATION_SCRIPTS) {
throw API.v1.failure('integration-scripts-disabled');
}

const compiledScript = compiledScripts[integration._id];
if (compiledScript && +compiledScript._updatedAt === +integration._updatedAt) {
return compiledScript.script;
}

const script = integration.scriptCompiled;
const { sandbox, store } = buildSandbox();
try {
incomingLogger.info({ msg: 'Will evaluate script of Trigger', integration: integration.name });
incomingLogger.debug(script);

const vmScript = new VMScript(`${script}; Script;`, 'script.js');
const vm = new VM({
sandbox,
});

const ScriptClass = vm.run(vmScript);

if (ScriptClass) {
compiledScripts[integration._id] = {
script: new ScriptClass(),
store,
_updatedAt: integration._updatedAt,
};

return compiledScripts[integration._id].script;
}
} catch (err) {
incomingLogger.error({
msg: 'Error evaluating Script in Trigger',
integration: integration.name,
script,
err,
});
throw API.v1.failure('error-evaluating-script');
}

incomingLogger.error({ msg: 'Class "Script" not in Trigger', integration: integration.name });
throw API.v1.failure('class-script-not-found');
function getEngine(integration) {
return integration.scriptEngine === 'isolated-vm' ? ivmEngine : vm2Engine;
}

async function createIntegration(options, user) {
Expand Down Expand Up @@ -178,20 +85,9 @@ async function executeIntegrationRest() {
emoji: this.integration.emoji,
};

if (
!DISABLE_INTEGRATION_SCRIPTS &&
this.integration.scriptEnabled &&
this.integration.scriptCompiled &&
this.integration.scriptCompiled.trim() !== ''
) {
let script;
try {
script = getIntegrationScript(this.integration);
} catch (e) {
incomingLogger.error(e);
return API.v1.failure(e.message);
}
const scriptEngine = getEngine(this.integration);

if (scriptEngine.integrationHasValidScript(this.integration)) {
this.request.setEncoding('utf8');
const content_raw = this.request.read();

Expand All @@ -216,37 +112,12 @@ async function executeIntegrationRest() {
},
};

try {
const { sandbox } = buildSandbox(compiledScripts[this.integration._id].store);
sandbox.script = script;
sandbox.request = request;

const vm = new VM({
timeout: 3000,
sandbox,
});

const result = await new Promise((resolve, reject) => {
process.nextTick(async () => {
try {
const scriptResult = await vm.run(`
new Promise((resolve, reject) => {
scriptTimeout(reject);
try {
resolve(script.process_incoming_request({ request: request }));
} catch(e) {
reject(e);
}
}).catch((error) => { throw new Error(error); });
`);

resolve(scriptResult);
} catch (e) {
reject(e);
}
});
});
const result = await scriptEngine.processIncomingRequest({
integration: this.integration,
request,
});

try {
if (!result) {
incomingLogger.debug({
msg: 'Process Incoming Request result of Trigger has no data',
Expand Down
Loading

0 comments on commit 507c808

Please sign in to comment.