Skip to content

Commit

Permalink
Merge branch 'develop' into chore/status-bullet-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored May 24, 2023
2 parents cec65cb + c95cda4 commit f6d5b4f
Show file tree
Hide file tree
Showing 27 changed files with 80 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-years-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: getActiveLocalUserCount query always returning 0
5 changes: 5 additions & 0 deletions .changeset/heavy-years-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fix: Admins unable to create new users if new users require manual approval
5 changes: 5 additions & 0 deletions .changeset/late-carrots-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

fix: Hide roomLeader padding
5 changes: 5 additions & 0 deletions .changeset/quick-cows-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Editing a room in the admin menu breaks that room's integration
5 changes: 5 additions & 0 deletions .changeset/quiet-rules-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Add missing awaits to .count() calls
5 changes: 5 additions & 0 deletions .changeset/wild-lizards-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

fix: Analytics page crash
1 change: 1 addition & 0 deletions .github/workflows/ci-test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ jobs:
if: inputs.type == 'api'
working-directory: ./apps/meteor
env:
WEBHOOK_TEST_URL: 'http://host.docker.internal:10000'
IS_EE: ${{ inputs.release == 'ee' && 'true' || '' }}
run: |
for i in $(seq 1 2); do
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/authentication/server/startup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const onCreateUserAsync = async function (options, user = {}) {
if (!user.active) {
const destinations = [];
const usersInRole = await Roles.findUsersInRole('admin');
await usersInRole.toArray().forEach((adminUser) => {
await usersInRole.forEach((adminUser) => {
if (Array.isArray(adminUser.emails)) {
adminUser.emails.forEach((email) => {
destinations.push(`${adminUser.name}<${email.address}>`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const updateFName = async (rid: string, displayName: string): Promise<(UpdateRes
return Promise.all([Rooms.setFnameById(rid, displayName), Subscriptions.updateFnameByRoomId(rid, displayName)]);
};

const updateRoomName = async (rid: string, displayName: string) => {
const slugifiedRoomName = await getValidRoomName(displayName, rid);

const updateRoomName = async (rid: string, displayName: string, slugifiedRoomName: string) => {
// Check if the username is available
if (!(await checkUsernameAvailability(slugifiedRoomName))) {
throw new Meteor.Error('error-duplicate-handle', `A room, team or user with name '${slugifiedRoomName}' already exists`, {
Expand Down Expand Up @@ -52,24 +50,27 @@ export async function saveRoomName(
if (displayName === room.name) {
return;
}
const isDiscussion = Boolean(room?.prid);
let update;

if (!displayName?.trim()) {
return;
}

const slugifiedRoomName = await getValidRoomName(displayName, rid);
const isDiscussion = Boolean(room?.prid);

let update;

if (isDiscussion || isRoomFederated(room)) {
update = await updateFName(rid, displayName);
} else {
update = await updateRoomName(rid, displayName);
update = await updateRoomName(rid, displayName, slugifiedRoomName);
}

if (!update) {
return;
}

room.name && (await Integrations.updateRoomName(room.name, displayName));
room.name && (await Integrations.updateRoomName(room.name, slugifiedRoomName));
if (sendMessage) {
await Message.saveSystemMessage('r', rid, displayName, user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class PendingAvatarImporter extends Base {
await super.updateProgress(ProgressStep.PREPARING_STARTED);

const users = await Users.findAllUsersWithPendingAvatar();
const fileCount = users.count();
const fileCount = await users.count();

if (fileCount === 0) {
await super.updateProgress(ProgressStep.DONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Meteor.startup(() => {
return;
}

const subs = Subscriptions.find({ t: 'l', ls: { $exists: 0 }, open: true }).count();
const subs = await Subscriptions.find({ t: 'l', ls: { $exists: 0 }, open: true }).count();
if (subs === 0) {
audio && audio.pause();
return;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export const dispatchInquiryQueued = async (inquiry, agent) => {
return;
}

logger.debug(`Notifying ${onlineAgents.count()} agents of new inquiry`);
logger.debug(`Notifying ${await onlineAgents.count()} agents of new inquiry`);
const notificationUserName = v && (v.name || v.username);

for await (let agent of onlineAgents) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const Livechat = {
if (settings.get('Livechat_assign_new_conversation_to_bot')) {
Livechat.logger.debug(`Fetching online bot agents for department ${department}`);
const botAgents = await Livechat.getBotAgents(department);
const onlineBots = botAgents.count();
const onlineBots = await botAgents.count();
Livechat.logger.debug(`Found ${onlineBots} online`);
if (onlineBots > 0) {
return true;
Expand Down
10 changes: 7 additions & 3 deletions apps/meteor/app/notifications/client/lib/Presence.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Meteor } from 'meteor/meteor';
import type { StreamerEvents } from '@rocket.chat/ui-contexts';

import { Presence, STATUS_MAP } from '../../../../client/lib/presence';

// TODO implement API on Streamer to be able to listen to all streamed data
// this is a hacky way to listen to all streamed data from user-presence Streamer
(Meteor as any).StreamerCentral.on('stream-user-presence', (uid: string, args: unknown) => {

new Meteor.Streamer('user-presence');

(Meteor as any).StreamerCentral.on('stream-user-presence', (uid: string, ...args: StreamerEvents['user-presence'][number]['args']) => {
if (!Array.isArray(args)) {
throw new Error('Presence event must be an array');
}
const [username, status, statusText] = args as [string, number, string | undefined];
Presence.notify({ _id: uid, username, status: STATUS_MAP[status], statusText });
const [[username, status, statusText]] = args;
Presence.notify({ _id: uid, username, status: STATUS_MAP[status ?? 0], statusText });
});
5 changes: 3 additions & 2 deletions apps/meteor/app/notifications/server/lib/Presence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Emitter } from '@rocket.chat/emitter';
import type { IPublication, IStreamerConstructor, Connection, IStreamer } from 'meteor/rocketchat:streamer';
import type { IUser } from '@rocket.chat/core-typings';
import type { StreamerEvents } from '@rocket.chat/ui-contexts';

type UserPresenceStreamProps = {
added: IUser['_id'][];
Expand All @@ -9,7 +10,7 @@ type UserPresenceStreamProps = {

type UserPresenceStreamArgs = {
uid: string;
args: unknown;
args: StreamerEvents['user-presence'][number]['args'];
};

const e = new Emitter<{
Expand Down Expand Up @@ -97,6 +98,6 @@ export class StreamPresence {
}
}

export const emit = (uid: string, args: UserPresenceStreamArgs): void => {
export const emit = (uid: string, args: UserPresenceStreamArgs['args']): void => {
e.emit(uid, { uid, args });
};
4 changes: 2 additions & 2 deletions apps/meteor/app/slashcommands-inviteall/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function inviteAll<T extends string>(type: T): SlashCommand<T>['callback'] {
});

try {
const APIsettings = settings.get('API_User_Limit');
const APIsettings = settings.get<number>('API_User_Limit');
if (!APIsettings) {
return;
}
if (cursor.count() > APIsettings) {
if ((await cursor.count()) > APIsettings) {
throw new Meteor.Error('error-user-limit-exceeded', 'User Limit Exceeded', {
method: 'addAllToRoom',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const AppDetailsPage = ({ id }: { id: App['id'] }): ReactElement => {
context && router.push({ context, page: 'list' });
});

const { installed, settings, privacyPolicySummary, permissions, tosLink, privacyLink, marketplace, name } = appData || {};
const { installed, settings, privacyPolicySummary, permissions, tosLink, privacyLink, name } = appData || {};

const isSecurityVisible = Boolean(privacyPolicySummary || permissions || tosLink || privacyLink);

const saveAppSettings = useCallback(async () => {
Expand Down Expand Up @@ -94,12 +95,11 @@ const AppDetailsPage = ({ id }: { id: App['id'] }): ReactElement => {
<>
<AppDetailsPageHeader app={appData} />
<AppDetailsPageTabs
context={context || ''}
installed={installed}
isSecurityVisible={isSecurityVisible}
marketplace={marketplace}
settings={settings}
tab={tab}
context={context || ''}
/>
{Boolean(!tab || tab === 'details') && <AppDetails app={appData} />}
{tab === 'requests' && <AppRequests id={id} isAdminUser={isAdminUser} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@ import React from 'react';
import type { ISettings } from '../../../../ee/client/apps/@types/IOrchestrator';

type AppDetailsPageTabsProps = {
context: string;
installed: boolean | undefined;
isSecurityVisible: boolean;
marketplace: unknown;
settings: ISettings | undefined;
tab: string | undefined;
context: string;
};

const AppDetailsPageTabs = ({
installed,
isSecurityVisible,
marketplace,
settings,
tab,
context,
}: AppDetailsPageTabsProps): ReactElement => {
const AppDetailsPageTabs = ({ context, installed, isSecurityVisible, settings, tab }: AppDetailsPageTabsProps): ReactElement => {
const t = useTranslation();
const isAdminUser = usePermission('manage-apps');

Expand Down Expand Up @@ -51,7 +43,7 @@ const AppDetailsPageTabs = ({
{t('Security')}
</Tabs.Item>
)}
{marketplace !== false && (
{context !== 'private' && (
<Tabs.Item onClick={(): void => handleTabClick('releases')} selected={tab === 'releases'}>
{t('Releases')}
</Tabs.Item>
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/client/views/room/components/body/RoomBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,10 @@ const RoomBody = (): ReactElement => {
/>
))}
</div>
<div ref={messagesBoxRef} className={['messages-box', roomLeader && 'has-leader'].filter(isTruthy).join(' ')}>
<div
ref={messagesBoxRef}
className={['messages-box', roomLeader && !hideLeaderHeader && 'has-leader'].filter(isTruthy).join(' ')}
>
<JumpToRecentMessageButton visible={hasNewMessages} onClick={handleNewMessageButtonClick} text={t('New_messages')} />
<JumpToRecentMessageButton
visible={hasMoreNextMessages}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@username": "@username",
"@username_message": "@username <message>",
"#channel": "#channel",
"%_of_conversations": "% of Conversations",
"%_of_conversations": "%% of Conversations",
"0_Errors_Only": "0 - Errors Only",
"1_Errors_and_Information": "1 - Errors and Information",
"2_Erros_Information_and_Debug": "2 - Errors, Information and Debug",
Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/server/models/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2819,7 +2819,11 @@ export class UsersRaw extends BaseRaw {

// here
getActiveLocalUserCount() {
return this.col.countDocuments({ active: true, federated: false, isRemote: false });
return Promise.all([
this.col.countDocuments({ active: true }),
this.col.countDocuments({ federated: true }),
this.col.countDocuments({ isRemote: true }),
]).then((results) => results.reduce((a, b) => a - b));
}

getActiveLocalGuestCount(idExceptions = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,8 @@ export class NotificationsModule {
}

sendPresence(uid: string, ...args: [username: string, statusChanged: 0 | 1 | 2 | 3, statusText: string | undefined]): void {
// if (this.debug === true) {
// console.log('notifyUserAndBroadcast', [userId, eventName, ...args]);
// }
emit(uid, args as any);
return this.streamPresence.emitWithoutBroadcast(uid, ...args);
emit(uid, [args]);
return this.streamPresence.emitWithoutBroadcast(uid, args);
}

progressUpdated(progress: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('LIVECHAT - Integrations', function () {

describe('Livechat - Webhooks', () => {
const webhookUrl = process.env.WEBHOOK_TEST_URL || 'https://httpbin.org';

describe('livechat/webhook.test', () => {
it('should fail when user doesnt have view-livechat-webhooks permission', async () => {
await updatePermission('view-livechat-webhooks', []);
Expand Down
1 change: 0 additions & 1 deletion docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ services:
- 'TRANSPORTER=${TRANSPORTER}'
- MOLECULER_LOG_LEVEL=info
- 'ROCKETCHAT_LICENSE=${ENTERPRISE_LICENSE}'
- 'WEBHOOK_TEST_URL=host.docker.internal:10000'
extra_hosts:
- 'host.docker.internal:host-gateway'
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/__tests__/2fahandling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test('if the 2fa handler is not provided, it should throw an error', async () =>

expect(error.status).toBe(400);

const body = error.body && (await JSON.parse(error.body.toString()));
const body = error.json();

expect(body).toMatchObject({
errorType: 'totp-required',
Expand Down
4 changes: 3 additions & 1 deletion packages/api-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ export class RestClient implements RestClientInterface {
return Promise.reject(response);
}

const error = await response.json();
const clone = response.clone();

const error = await clone.json();

if ((isTotpRequiredError(error) || isTotpInvalidError(error)) && hasRequiredTwoFactorMethod(error) && this.twoFactorHandler) {
const method2fa = 'details' in error ? error.details.method : 'password';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-contexts/src/ServerContext/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export interface StreamerEvents {
},
];

'user-presence': [{ key: string; args: [username: string, statusChanged?: 0 | 1 | 2 | 3, statusText?: string] }];
'user-presence': [{ key: string; args: [[username: string, statusChanged?: 0 | 1 | 2 | 3, statusText?: string]] }];

// TODO: rename to 'integration-history'
'integrationHistory': [
Expand Down

0 comments on commit f6d5b4f

Please sign in to comment.