Skip to content

Commit

Permalink
Merge branch 'develop' into fix/register-guest
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Apr 1, 2024
2 parents 8256028 + d1fd9da commit 5416b54
Show file tree
Hide file tree
Showing 72 changed files with 695 additions and 421 deletions.
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ API.v1.addRoute(
{
async post() {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { prid, pmid, reply, t_name, users, encrypted } = this.bodyParams;
const { prid, pmid, reply, t_name, users, encrypted, topic } = this.bodyParams;
if (!prid) {
return API.v1.failure('Body parameter "prid" is required.');
}
Expand All @@ -344,6 +344,7 @@ API.v1.addRoute(
reply,
users: users?.filter(isTruthy) || [],
encrypted,
topic,
});

return API.v1.success({ discussion });
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/app/authentication/server/startup/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { Roles, Settings, Users } from '@rocket.chat/models';
import { escapeRegExp, escapeHTML } from '@rocket.chat/string-helpers';
import { Accounts } from 'meteor/accounts-base';
import { Match } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { AppEvents, Apps } from '../../../../ee/server/apps/orchestrator';
import { callbacks } from '../../../../lib/callbacks';
import { beforeCreateUserCallback } from '../../../../lib/callbacks/beforeCreateUserCallback';
import { parseCSV } from '../../../../lib/utils/parseCSV';
Expand Down Expand Up @@ -350,8 +350,8 @@ const insertUserDocAsync = async function (options, user) {

if (!options.skipAppsEngineEvent) {
// `post` triggered events don't need to wait for the promise to resolve
Apps.triggerEvent(AppEvents.IPostUserCreated, { user, performedBy: await safeGetMeteorUser() }).catch((e) => {
Apps.getRocketChatLogger().error('Error while executing post user created event:', e);
Apps?.triggerEvent(AppEvents.IPostUserCreated, { user, performedBy: await safeGetMeteorUser() }).catch((e) => {
Apps?.getRocketChatLogger().error('Error while executing post user created event:', e);
});
}

Expand Down Expand Up @@ -424,7 +424,7 @@ const validateLoginAttemptAsync = async function (login) {
*/
if (login.type !== 'resume') {
// App IPostUserLoggedIn event hook
await Apps.triggerEvent(AppEvents.IPostUserLoggedIn, login.user);
await Apps?.triggerEvent(AppEvents.IPostUserLoggedIn, login.user);
}

return true;
Expand Down
10 changes: 6 additions & 4 deletions apps/meteor/app/discussion/server/methods/createDiscussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type CreateDiscussionProperties = {
users: Array<Exclude<IUser['username'], undefined>>;
user: IUser;
encrypted?: boolean;
topic?: string;
};

const create = async ({
Expand All @@ -72,6 +73,7 @@ const create = async ({
users,
user,
encrypted,
topic,
}: CreateDiscussionProperties): Promise<IRoom & { rid: string }> => {
// if you set both, prid and pmid, and the rooms dont match... should throw an error)
let message: null | IMessage = null;
Expand Down Expand Up @@ -145,7 +147,7 @@ const create = async ({

const type = await roomCoordinator.getRoomDirectives(parentRoom.t).getDiscussionType(parentRoom);
const description = parentRoom.encrypted ? '' : message?.msg;
const topic = parentRoom.name;
const discussionTopic = topic || parentRoom.name;

if (!type) {
throw new Meteor.Error('error-invalid-type', 'Cannot define discussion room type', {
Expand All @@ -163,7 +165,7 @@ const create = async ({
{
fname: discussionName,
description, // TODO discussions remove
topic, // TODO discussions remove
topic: discussionTopic,
prid,
encrypted,
},
Expand Down Expand Up @@ -203,7 +205,7 @@ declare module '@rocket.chat/ui-contexts' {

export const createDiscussion = async (
userId: string,
{ prid, pmid, t_name: discussionName, reply, users, encrypted }: Omit<CreateDiscussionProperties, 'user'>,
{ prid, pmid, t_name: discussionName, reply, users, encrypted, topic }: Omit<CreateDiscussionProperties, 'user'>,
): Promise<
IRoom & {
rid: string;
Expand All @@ -229,7 +231,7 @@ export const createDiscussion = async (
});
}

return create({ prid, pmid, t_name: discussionName, reply, users, user, encrypted });
return create({ prid, pmid, t_name: discussionName, reply, users, user, encrypted, topic });
};

Meteor.methods<ServerMethods>({
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/file-upload/server/lib/FileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import stream from 'stream';
import URL from 'url';

import { hashLoginToken } from '@rocket.chat/account-utils';
import { Apps, AppEvents } from '@rocket.chat/apps';
import { AppsEngineException } from '@rocket.chat/apps-engine/definition/exceptions';
import type { IUpload } from '@rocket.chat/core-typings';
import { Users, Avatars, UserDataFiles, Uploads, Settings, Subscriptions, Messages, Rooms } from '@rocket.chat/models';
Expand All @@ -21,7 +22,6 @@ import sharp from 'sharp';
import type { WritableStreamBuffer } from 'stream-buffers';
import streamBuffers from 'stream-buffers';

import { AppEvents, Apps } from '../../../../ee/server/apps';
import { i18n } from '../../../../server/lib/i18n';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator';
Expand Down Expand Up @@ -177,7 +177,7 @@ export const FileUpload = {

// App IPreFileUpload event hook
try {
await Apps.triggerEvent(AppEvents.IPreFileUpload, { file, content: content || Buffer.from([]) });
await Apps?.triggerEvent(AppEvents.IPreFileUpload, { file, content: content || Buffer.from([]) });
} catch (error: any) {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/lib/server/functions/addUserToRoom.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { AppsEngineException } from '@rocket.chat/apps-engine/definition/exceptions';
import { Message, Team } from '@rocket.chat/core-services';
import type { IUser } from '@rocket.chat/core-typings';
import { Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { RoomMemberActions } from '../../../../definition/IRoomTypeConfig';
import { AppEvents, Apps } from '../../../../ee/server/apps';
import { callbacks } from '../../../../lib/callbacks';
import { getSubscriptionAutotranslateDefaultConfig } from '../../../../server/lib/getSubscriptionAutotranslateDefaultConfig';
import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator';
Expand Down Expand Up @@ -54,7 +54,7 @@ export const addUserToRoom = async function (
}

try {
await Apps.triggerEvent(AppEvents.IPreRoomUserJoined, room, userToBeAdded, inviter);
await Apps?.triggerEvent(AppEvents.IPreRoomUserJoined, room, userToBeAdded, inviter);
} catch (error: any) {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
Expand Down Expand Up @@ -118,7 +118,7 @@ export const addUserToRoom = async function (
// Keep the current event
await callbacks.run('afterJoinRoom', userToBeAdded, room);

void Apps.triggerEvent(AppEvents.IPostRoomUserJoined, room, userToBeAdded, inviter);
void Apps?.triggerEvent(AppEvents.IPostRoomUserJoined, room, userToBeAdded, inviter);
});
}

Expand Down
11 changes: 7 additions & 4 deletions apps/meteor/app/lib/server/functions/createDirectRoom.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AppEvents, Apps } from '@rocket.chat/apps';
import { AppsEngineException } from '@rocket.chat/apps-engine/definition/exceptions';
import type { ISubscriptionExtraData } from '@rocket.chat/core-services';
import type { ICreatedRoom, IRoom, ISubscription, IUser } from '@rocket.chat/core-typings';
Expand All @@ -6,7 +7,6 @@ import { Random } from '@rocket.chat/random';
import { Meteor } from 'meteor/meteor';
import type { MatchKeysAndValues } from 'mongodb';

import { Apps } from '../../../../ee/server/apps';
import { callbacks } from '../../../../lib/callbacks';
import { isTruthy } from '../../../../lib/isTruthy';
import { settings } from '../../../settings/server';
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function createDirectRoom(
_USERNAMES: usernames,
};

const prevent = await Apps.triggerEvent('IPreRoomCreatePrevent', tmpRoom).catch((error) => {
const prevent = await Apps?.triggerEvent(AppEvents.IPreRoomCreatePrevent, tmpRoom).catch((error) => {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
}
Expand All @@ -115,7 +115,10 @@ export async function createDirectRoom(
throw new Meteor.Error('error-app-prevented', 'A Rocket.Chat App prevented the room creation.');
}

const result = await Apps.triggerEvent('IPreRoomCreateModify', await Apps.triggerEvent('IPreRoomCreateExtend', tmpRoom));
const result = await Apps?.triggerEvent(
AppEvents.IPreRoomCreateModify,
await Apps?.triggerEvent(AppEvents.IPreRoomCreateExtend, tmpRoom),
);

if (typeof result === 'object') {
Object.assign(roomInfo, result);
Expand Down Expand Up @@ -169,7 +172,7 @@ export async function createDirectRoom(

await callbacks.run('afterCreateDirectRoom', insertedRoom, { members: roomMembers, creatorId: options?.creator });

void Apps.triggerEvent('IPostRoomCreate', insertedRoom);
void Apps?.triggerEvent(AppEvents.IPostRoomCreate, insertedRoom);
}

return {
Expand Down
11 changes: 7 additions & 4 deletions apps/meteor/app/lib/server/functions/createRoom.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable complexity */
import { AppEvents, Apps } from '@rocket.chat/apps';
import { AppsEngineException } from '@rocket.chat/apps-engine/definition/exceptions';
import { Message, Team } from '@rocket.chat/core-services';
import type { ICreateRoomParams, ISubscriptionExtraData } from '@rocket.chat/core-services';
import type { ICreatedRoom, IUser, IRoom, RoomType } from '@rocket.chat/core-typings';
import { Rooms, Subscriptions, Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { Apps } from '../../../../ee/server/apps/orchestrator';
import { callbacks } from '../../../../lib/callbacks';
import { beforeCreateRoomCallback } from '../../../../lib/callbacks/beforeCreateRoomCallback';
import { getSubscriptionAutotranslateDefaultConfig } from '../../../../server/lib/getSubscriptionAutotranslateDefaultConfig';
Expand Down Expand Up @@ -198,7 +198,7 @@ export const createRoom = async <T extends RoomType>(
_USERNAMES: members,
};

const prevent = await Apps.triggerEvent('IPreRoomCreatePrevent', tmp).catch((error) => {
const prevent = await Apps?.triggerEvent(AppEvents.IPreRoomCreatePrevent, tmp).catch((error) => {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
}
Expand All @@ -210,7 +210,10 @@ export const createRoom = async <T extends RoomType>(
throw new Meteor.Error('error-app-prevented', 'A Rocket.Chat App prevented the room creation.');
}

const eventResult = await Apps.triggerEvent('IPreRoomCreateModify', await Apps.triggerEvent('IPreRoomCreateExtend', tmp));
const eventResult = await Apps?.triggerEvent(
AppEvents.IPreRoomCreateModify,
await Apps.triggerEvent(AppEvents.IPreRoomCreateExtend, tmp),
);

if (eventResult && typeof eventResult === 'object' && delete eventResult._USERNAMES) {
Object.assign(roomProps, eventResult);
Expand Down Expand Up @@ -242,7 +245,7 @@ export const createRoom = async <T extends RoomType>(
callbacks.runAsync('federation.afterCreateFederatedRoom', room, { owner, originalMemberList: members });
}

void Apps.triggerEvent('IPostRoomCreate', room);
void Apps?.triggerEvent(AppEvents.IPostRoomCreate, room);
return {
rid: room._id, // backwards compatible
inserted: true,
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/app/lib/server/functions/deleteMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AppEvents, Apps } from '@rocket.chat/apps';
import { api } from '@rocket.chat/core-services';
import type { AtLeast, IMessage, IUser } from '@rocket.chat/core-typings';
import { Messages, Rooms, Uploads, Users, ReadReceipts } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { Apps } from '../../../../ee/server/apps';
import { callbacks } from '../../../../lib/callbacks';
import { broadcastMessageFromData } from '../../../../server/modules/watchers/lib/messages';
import { canDeleteMessageAsync } from '../../../authorization/server/functions/canDeleteMessage';
Expand All @@ -29,14 +29,14 @@ export const deleteMessageValidatingPermission = async (message: AtLeast<IMessag
};

export async function deleteMessage(message: IMessage, user: IUser): Promise<void> {
const deletedMsg = await Messages.findOneById(message._id);
const deletedMsg: IMessage | null = await Messages.findOneById(message._id);
const isThread = (deletedMsg?.tcount || 0) > 0;
const keepHistory = settings.get('Message_KeepHistory') || isThread;
const showDeletedStatus = settings.get('Message_ShowDeletedStatus') || isThread;
const bridges = Apps?.isLoaded() && Apps.getBridges();

if (deletedMsg && bridges) {
const prevent = await bridges.getListenerBridge().messageEvent('IPreMessageDeletePrevent', deletedMsg);
const prevent = await bridges.getListenerBridge().messageEvent(AppEvents.IPreMessageDeletePrevent, deletedMsg);
if (prevent) {
throw new Meteor.Error('error-app-prevented-deleting', 'A Rocket.Chat App prevented the message deleting.');
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export async function deleteMessage(message: IMessage, user: IUser): Promise<voi
});
}

if (bridges) {
void bridges.getListenerBridge().messageEvent('IPostMessageDeleted', deletedMsg, user);
if (bridges && deletedMsg) {
void bridges.getListenerBridge().messageEvent(AppEvents.IPostMessageDeleted, deletedMsg, user);
}
}
6 changes: 3 additions & 3 deletions apps/meteor/app/lib/server/functions/removeUserFromRoom.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { AppsEngineException } from '@rocket.chat/apps-engine/definition/exceptions';
import { Message, Team } from '@rocket.chat/core-services';
import type { IUser } from '@rocket.chat/core-typings';
import { Subscriptions, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { AppEvents, Apps } from '../../../../ee/server/apps/orchestrator';
import { afterLeaveRoomCallback } from '../../../../lib/callbacks/afterLeaveRoomCallback';
import { beforeLeaveRoomCallback } from '../../../../lib/callbacks/beforeLeaveRoomCallback';

Expand All @@ -20,7 +20,7 @@ export const removeUserFromRoom = async function (
}

try {
await Apps.triggerEvent(AppEvents.IPreRoomUserLeave, room, user);
await Apps?.triggerEvent(AppEvents.IPreRoomUserLeave, room, user);
} catch (error: any) {
if (error.name === AppsEngineException.name) {
throw new Meteor.Error('error-app-prevented', error.message);
Expand Down Expand Up @@ -67,5 +67,5 @@ export const removeUserFromRoom = async function (
// TODO: CACHE: maybe a queue?
await afterLeaveRoomCallback.run(user, room);

await Apps.triggerEvent(AppEvents.IPostRoomUserLeave, room, user);
await Apps?.triggerEvent(AppEvents.IPostRoomUserLeave, room, user);
};
4 changes: 2 additions & 2 deletions apps/meteor/app/lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { isUserFederated } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';
import Gravatar from 'gravatar';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { AppEvents, Apps } from '../../../../ee/server/apps/orchestrator';
import { callbacks } from '../../../../lib/callbacks';
import { trim } from '../../../../lib/utils/stringUtils';
import { getNewUserRoles } from '../../../../server/services/user/lib/getNewUserRoles';
Expand Down Expand Up @@ -434,7 +434,7 @@ export const saveUser = async function (userId, userData) {
oldUser: oldUserData,
});

await Apps.triggerEvent(AppEvents.IPostUserUpdated, {
await Apps?.triggerEvent(AppEvents.IPostUserUpdated, {
user: userUpdated,
previousUser: oldUserData,
performedBy: await safeGetMeteorUser(),
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/functions/sendMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Apps } from '@rocket.chat/apps';
import { Message } from '@rocket.chat/core-services';
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import { Messages } from '@rocket.chat/models';
import { Match, check } from 'meteor/check';

import { Apps } from '../../../../ee/server/apps';
import { callbacks } from '../../../../lib/callbacks';
import { isRelativeURL } from '../../../../lib/utils/isRelativeURL';
import { isURL } from '../../../../lib/utils/isURL';
Expand Down
Loading

0 comments on commit 5416b54

Please sign in to comment.