Skip to content

Commit

Permalink
Merge branch 'develop' into fix/room-custom-field-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Mar 1, 2023
2 parents 8a73061 + d4b3cb8 commit 1102bab
Show file tree
Hide file tree
Showing 147 changed files with 1,758 additions and 1,060 deletions.
28 changes: 26 additions & 2 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ name: 'Setup Node'

inputs:
node-version:
# default: '14.21.2'
required: true
type: string
cache-modules:
required: false
type: boolean
install:
required: false
type: boolean

outputs:
node-version:
Expand All @@ -14,9 +19,28 @@ runs:
using: composite

steps:
# - name: Cache Node Modules
# if: inputs.cache-modules
# id: cache-node-modules
# uses: actions/cache@v3
# with:
# path: |
# node_modules
# **/node_modules
# key: node-modules-${{ hashFiles('yarn.lock') }}
#
# Could use this command to list all paths to save:
# find . -name 'node_modules' -prune | grep -v "/\.meteor/" | grep -v "/meteor/packages/"

- name: Use Node.js ${{ inputs.node-version }}
id: node-version
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
cache: 'yarn'
cache: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' && 'yarn' || '' }}

- name: yarn install
# if: inputs.install && steps.cache-node-modules.outputs.cache-hit != 'true'
if: inputs.install
shell: bash
run: yarn
14 changes: 3 additions & 11 deletions .github/workflows/ci-code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,18 @@ jobs:
uses: ./.github/actions/setup-node
with:
node-version: ${{ inputs.node-version }}
cache-modules: true
install: true

# - name: Free disk space
# run: |
# sudo apt clean
# docker rmi $(docker image ls -aq)
# df -h

# - name: Versions
# run: |
# npm --versions
# yarn -v
# node -v
# git version

- name: yarn install
run: yarn

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: TS typecheck
- name: TS TypeCheck
if: matrix.check == 'ts'
run: yarn turbo run typecheck

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
RC_DOCKER_TAG: ${{ matrix.mongodb-version == '6.0' && inputs.rc-docker-tag-alpine || inputs.rc-docker-tag }}

strategy:
fail-fast: false
matrix:
mongodb-version: ${{ fromJSON(inputs.mongodb-version) }}
shard: ${{ fromJSON(inputs.shard) }}
Expand All @@ -90,17 +91,16 @@ jobs:
uses: ./.github/actions/setup-node
with:
node-version: ${{ inputs.node-version }}
cache-modules: true
install: true

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: yarn install
run: yarn

- name: yarn build
run: yarn build

- name: Restore build
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: /tmp/build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
mongodb-version: ${{ fromJSON(inputs.mongodb-version) }}

Expand All @@ -38,9 +39,8 @@ jobs:
uses: ./.github/actions/setup-node
with:
node-version: ${{ inputs.node-version }}

- name: yarn install
run: yarn
cache-modules: true
install: true

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ jobs:
uses: ./.github/actions/setup-node
with:
node-version: ${{ needs.release-versions.outputs.node-version }}
cache-modules: true
install: true

# - name: Free disk space
# run: |
Expand Down Expand Up @@ -158,9 +160,6 @@ jobs:
meteor node -v
git version
- name: yarn install
run: yarn

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: Translation check
Expand All @@ -175,15 +174,15 @@ jobs:
if: startsWith(github.ref, 'refs/pull/') == true
env:
METEOR_PROFILE: 1000
run: yarn build:ci -- --debug --directory dist
run: yarn build:ci -- --directory /tmp/dist

- name: Build Rocket.Chat
if: startsWith(github.ref, 'refs/pull/') != true
run: yarn build:ci -- --directory dist
run: yarn build:ci -- --directory /tmp/dist

- name: Prepare build
run: |
cd apps/meteor/dist
cd /tmp/dist
tar czf /tmp/Rocket.Chat.tar.gz bundle
- name: Store build
Expand Down Expand Up @@ -310,7 +309,7 @@ jobs:
- uses: actions/checkout@v3

- name: Restore build
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: /tmp/build
Expand Down Expand Up @@ -389,7 +388,7 @@ jobs:
- uses: actions/checkout@v3

- name: Restore build
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: build
path: /tmp/build
Expand Down
19 changes: 12 additions & 7 deletions .houston/metadata.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const { execSync } = require('child_process');

const getMongoVersion = async function({ version, git }) {
try {
const workflows = await git.show([`${ version }:.github/workflows/build_and_test.yml`]);
const workflows = await git.show([`${ version }:.github/workflows/ci.yml`]);

const mongoMatch = workflows.match(/mongodb\-version: \[([^\]]+)\]/);
const mongoMatch = workflows.match(/compatibleMongoVersions\\": \[([^\]]+)\]/);
if (!mongoMatch) {
return [];
}

return mongoMatch[1].replace(/["' ]/g, '').split(',');
return mongoMatch[1].replace(/["'\\ ]/g, '').split(',');
} catch (e) {
console.error(e);
}
Expand Down Expand Up @@ -38,11 +40,14 @@ const getNodeNpmVersions = async function({ version, git, request }) {

const getAppsEngineVersion = async function({ version, git }) {
try {
const packageJson = await git.show([`${ version }:apps/meteor/package-lock.json`]);
const { dependencies } = JSON.parse(packageJson);
const { version: appsEngineVersion } = dependencies['@rocket.chat/apps-engine'];
const result = execSync('yarn why @rocket.chat/apps-engine --json');

const resultString = result.toString();

return appsEngineVersion;
const match = resultString.match(/"@rocket.chat\/meteor@workspace:apps\/meteor".*"@rocket\.chat\/apps\-engine@npm:([^"]+)"/);
if (match) {
return match[1];
}
} catch (e) {
console.error(e);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/.eslintcache

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions apps/meteor/app/federation-v2/server/Federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const allowedActionsInFederatedRooms: ValueOf<typeof RoomMemberActions>[] = [
RoomMemberActions.LEAVE,
];

const allowedActionsForModerators = allowedActionsInFederatedRooms.filter((action) => action !== RoomMemberActions.SET_AS_OWNER);

const allowedRoomSettingsChangesInFederatedRooms: ValueOf<typeof RoomSettingsEnum>[] = [RoomSettingsEnum.NAME, RoomSettingsEnum.TOPIC];

export class Federation {
Expand All @@ -33,10 +35,19 @@ export class Federation {
return true;
}

return Boolean(
(userSubscription.roles?.includes('owner') || userSubscription.roles?.includes('moderator')) &&
allowedActionsInFederatedRooms.includes(action),
);
if (action === RoomMemberActions.LEAVE) {
return true;
}

if (userSubscription.roles?.includes('owner')) {
return allowedActionsInFederatedRooms.includes(action);
}

if (userSubscription.roles?.includes('moderator')) {
return allowedActionsForModerators.includes(action);
}

return false;
}

public static isAFederatedUsername(username: string): boolean {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/livechat/server/api/v1/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { isPOSTLivechatTranscriptParams } from '@rocket.chat/rest-typings';

import { API } from '../../../../api/server';
import { Livechat } from '../../lib/Livechat';
import { Livechat } from '../../lib/LivechatTyped';

API.v1.addRoute(
'livechat/transcript',
{ validateParams: isPOSTLivechatTranscriptParams },
{
async post() {
const { token, rid, email } = this.bodyParams;
// @ts-expect-error -- typings on sendtranscript are wrong
if (!(await Livechat.sendTranscript({ token, rid, email }))) {
return API.v1.failure({ message: TAPi18n.__('Error_sending_livechat_transcript') });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { LivechatRooms } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { Livechat } from '../lib/Livechat';
import { Livechat } from '../lib/LivechatTyped';
import type { CloseRoomParams } from '../lib/LivechatTyped.d';

type LivechatCloseCallbackParams = {
Expand Down
86 changes: 0 additions & 86 deletions apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Match, check } from 'meteor/check';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { HTTP } from 'meteor/http';
import moment from 'moment-timezone';
import UAParser from 'ua-parser-js';
import {
Users as UsersRaw,
Expand All @@ -27,7 +26,6 @@ import { QueueManager } from './QueueManager';
import { RoutingManager } from './RoutingManager';
import { Analytics } from './Analytics';
import { settings } from '../../../settings/server';
import { getTimezone } from '../../../utils/server/lib/getTimezone';
import { callbacks } from '../../../../lib/callbacks';
import {
Users,
Expand Down Expand Up @@ -1096,90 +1094,6 @@ export const Livechat = {
});
},

async sendTranscript({ token, rid, email, subject, user }) {
check(rid, String);
check(email, String);
Livechat.logger.debug(`Sending conversation transcript of room ${rid} to user with token ${token}`);

const room = LivechatRooms.findOneById(rid);

const visitor = await LivechatVisitors.getVisitorByToken(token, {
projection: { _id: 1, token: 1, language: 1, username: 1, name: 1 },
});

if (!visitor) {
throw new Meteor.Error('error-invalid-token', 'Invalid token');
}

const userLanguage = (visitor && visitor.language) || settings.get('Language') || 'en';
const timezone = getTimezone(user);
Livechat.logger.debug(`Transcript will be sent using ${timezone} as timezone`);

// allow to only user to send transcripts from their own chats
if (!room || room.t !== 'l' || !room.v || room.v.token !== token) {
throw new Meteor.Error('error-invalid-room', 'Invalid room');
}

const showAgentInfo = settings.get('Livechat_show_agent_info');
const ignoredMessageTypes = [
'livechat_navigation_history',
'livechat_transcript_history',
'command',
'livechat-close',
'livechat-started',
'livechat_video_call',
];
const messages = Messages.findVisibleByRoomIdNotContainingTypes(rid, ignoredMessageTypes, {
sort: { ts: 1 },
});

let html = '<div> <hr>';
messages.forEach((message) => {
let author;
if (message.u._id === visitor._id) {
author = TAPi18n.__('You', { lng: userLanguage });
} else {
author = showAgentInfo ? message.u.name || message.u.username : TAPi18n.__('Agent', { lng: userLanguage });
}

const datetime = moment.tz(message.ts, timezone).locale(userLanguage).format('LLL');
const singleMessage = `
<p><strong>${author}</strong> <em>${datetime}</em></p>
<p>${message.msg}</p>
`;
html += singleMessage;
});

html = `${html}</div>`;

let fromEmail = settings.get('From_Email').match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i);

if (fromEmail) {
fromEmail = fromEmail[0];
} else {
fromEmail = settings.get('From_Email');
}

const mailSubject = subject || TAPi18n.__('Transcript_of_your_livechat_conversation', { lng: userLanguage });

this.sendEmail(fromEmail, email, fromEmail, mailSubject, html);

Meteor.defer(() => {
callbacks.run('livechat.sendTranscript', messages, email);
});

let type = 'user';
if (!user) {
user = Users.findOneById('rocket.cat', { fields: { _id: 1, username: 1, name: 1 } });
type = 'visitor';
}

Messages.createTranscriptHistoryWithRoomIdMessageAndUser(room._id, '', user, {
requestData: { type, visitor, user },
});
return true;
},

getRoomMessages({ rid }) {
check(rid, String);

Expand Down

0 comments on commit 1102bab

Please sign in to comment.