From 93f9828b5e1c8ee327fbbcc9986d98d878c8a548 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 26 Apr 2023 10:38:20 -0600 Subject: [PATCH] refactor: Separate isomorphic imports on utils - 1 (#29052) --- apps/meteor/app/api/server/v1/misc.ts | 2 +- apps/meteor/app/assets/server/assets.ts | 4 +- apps/meteor/app/authorization/index.js | 8 --- apps/meteor/app/e2e/client/rocketchat.e2e.ts | 9 +++- .../app/file-upload/server/lib/FileUpload.ts | 4 +- .../app/importer-slack/server/importer.js | 2 +- .../server/functions/findOrCreateInvite.js | 16 +++--- .../app/lib/server/functions/attachMessage.ts | 4 +- .../server/functions/notifications/email.js | 20 ++++--- .../app/message-pin/server/pinMessage.ts | 2 +- .../meteor/app/oembed/server/jumpToMessage.ts | 5 +- .../app/slackbridge/server/SlackAdapter.js | 2 +- .../app/ui/client/lib/KonchatNotification.ts | 4 +- .../app/utils/{lib => client}/getAvatarURL.ts | 0 apps/meteor/app/utils/client/getURL.ts | 13 +++++ .../app/utils/client/getUserAvatarURL.ts | 14 +++++ apps/meteor/app/utils/client/index.ts | 6 +-- apps/meteor/app/utils/client/restrictions.ts | 9 ++++ .../app/utils/lib/{getURL.js => getURL.ts} | 54 +++++++++++++------ apps/meteor/app/utils/lib/getUserAvatarURL.js | 14 ----- ...eUploadRestrictions.js => restrictions.ts} | 24 +++------ .../functions/normalizeMessageFileUpload.ts | 2 +- apps/meteor/app/utils/server/getAvatarURL.ts | 10 ++++ apps/meteor/app/utils/server/getURL.ts | 13 +++++ .../app/utils/server/getUserAvatarURL.ts | 14 +++++ apps/meteor/app/utils/server/index.ts | 4 +- apps/meteor/app/utils/server/restrictions.ts | 9 ++++ apps/meteor/app/webdav/client/actionButton.ts | 2 +- .../components/avatar/RoomAvatarEditor.tsx | 2 +- .../components/voip/room/VoipRoomForeword.tsx | 2 +- .../client/lib/rooms/roomTypes/direct.ts | 6 +-- .../client/lib/rooms/roomTypes/livechat.ts | 2 +- .../client/lib/rooms/roomTypes/private.ts | 2 +- .../client/lib/rooms/roomTypes/public.ts | 2 +- .../meteor/client/lib/rooms/roomTypes/voip.ts | 2 +- .../meteor/client/lib/utils/getAvatarAsPng.ts | 4 +- .../client/providers/AvatarUrlProvider.tsx | 2 +- .../templateHelpers/avatarUrlFromUsername.ts | 2 +- .../client/views/modal/uikit/ModalBlock.tsx | 2 +- .../views/room/contextualBar/Apps/Apps.tsx | 2 +- .../ee/client/apps/RealAppsEngineUIHost.js | 4 +- apps/meteor/lib/createQuoteAttachment.ts | 10 ++-- .../lib/dataExport/processDataDownloads.ts | 2 +- apps/meteor/server/lib/dataExport/sendFile.ts | 2 +- .../providers/twilio.ts | 6 +-- .../providers/voxtelesys.ts | 6 +-- .../tests/unit/app/utils/lib/getURL.tests.js | 29 +++++----- 47 files changed, 225 insertions(+), 134 deletions(-) delete mode 100644 apps/meteor/app/authorization/index.js rename apps/meteor/app/utils/{lib => client}/getAvatarURL.ts (100%) create mode 100644 apps/meteor/app/utils/client/getURL.ts create mode 100644 apps/meteor/app/utils/client/getUserAvatarURL.ts create mode 100644 apps/meteor/app/utils/client/restrictions.ts rename apps/meteor/app/utils/lib/{getURL.js => getURL.ts} (53%) delete mode 100644 apps/meteor/app/utils/lib/getUserAvatarURL.js rename apps/meteor/app/utils/lib/{fileUploadRestrictions.js => restrictions.ts} (57%) create mode 100644 apps/meteor/app/utils/server/getAvatarURL.ts create mode 100644 apps/meteor/app/utils/server/getURL.ts create mode 100644 apps/meteor/app/utils/server/getUserAvatarURL.ts create mode 100644 apps/meteor/app/utils/server/restrictions.ts diff --git a/apps/meteor/app/api/server/v1/misc.ts b/apps/meteor/app/api/server/v1/misc.ts index 7293db374b0..03ffeb2dee9 100644 --- a/apps/meteor/app/api/server/v1/misc.ts +++ b/apps/meteor/app/api/server/v1/misc.ts @@ -22,7 +22,7 @@ import { hasPermissionAsync } from '../../../authorization/server/functions/hasP import { settings } from '../../../settings/server'; import { API } from '../api'; import { getDefaultUserFields } from '../../../utils/server/functions/getDefaultUserFields'; -import { getURL } from '../../../utils/lib/getURL'; +import { getURL } from '../../../utils/server/getURL'; import { getLogs } from '../../../../server/stream/stdout'; import { SystemLogger } from '../../../../server/lib/logger/system'; import { passwordPolicy } from '../../../lib/server'; diff --git a/apps/meteor/app/assets/server/assets.ts b/apps/meteor/app/assets/server/assets.ts index d5d198e091f..153d2790c9e 100644 --- a/apps/meteor/app/assets/server/assets.ts +++ b/apps/meteor/app/assets/server/assets.ts @@ -13,7 +13,7 @@ import type { IRocketChatAssets, IRocketChatAsset, IRocketChatAssetCache } from import { Settings } from '@rocket.chat/models'; import { settings, settingsRegistry } from '../../settings/server'; -import { getURL } from '../../utils/lib/getURL'; +import { getURL } from '../../utils/server/getURL'; import { getExtension } from '../../utils/lib/mimeTypes'; import { hasPermissionAsync } from '../../authorization/server/functions/hasPermission'; import { RocketChatFile } from '../../file/server'; @@ -323,7 +323,7 @@ class RocketChatAssetsClass { const asset = settings.get(assetName); const url = asset.url || asset.defaultUrl; - return getURL(url, options); + return getURL(url as string, options); } } diff --git a/apps/meteor/app/authorization/index.js b/apps/meteor/app/authorization/index.js deleted file mode 100644 index c20f7ea6070..00000000000 --- a/apps/meteor/app/authorization/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -if (Meteor.isClient) { - module.exports = require('./client/'); -} -if (Meteor.isServer) { - module.exports = require('./server/index.js'); -} diff --git a/apps/meteor/app/e2e/client/rocketchat.e2e.ts b/apps/meteor/app/e2e/client/rocketchat.e2e.ts index 6567a95b971..74f0a88f285 100644 --- a/apps/meteor/app/e2e/client/rocketchat.e2e.ts +++ b/apps/meteor/app/e2e/client/rocketchat.e2e.ts @@ -39,7 +39,7 @@ import { imperativeModal } from '../../../client/lib/imperativeModal'; import SaveE2EPasswordModal from '../../../client/views/e2e/SaveE2EPasswordModal'; import EnterE2EPasswordModal from '../../../client/views/e2e/EnterE2EPasswordModal'; import { call } from '../../../client/lib/utils/call'; -import { APIClient } from '../../utils/client'; +import { APIClient, getUserAvatarURL } from '../../utils/client'; import { createQuoteAttachment } from '../../../lib/createQuoteAttachment'; import { mapMessageFromApi } from '../../../client/lib/utils/mapMessageFromApi'; @@ -501,7 +501,12 @@ class E2E extends Emitter { message.attachments = message.attachments || []; const useRealName = settings.get('UI_Use_Real_Name'); - const quoteAttachment = createQuoteAttachment(decryptedQuoteMessage, url, useRealName); + const quoteAttachment = createQuoteAttachment( + decryptedQuoteMessage, + url, + useRealName, + getUserAvatarURL(decryptedQuoteMessage.u.username || '') as string, + ); message.attachments.push(quoteAttachment); }), diff --git a/apps/meteor/app/file-upload/server/lib/FileUpload.ts b/apps/meteor/app/file-upload/server/lib/FileUpload.ts index dd67b3e5275..a6c5c4e7d12 100644 --- a/apps/meteor/app/file-upload/server/lib/FileUpload.ts +++ b/apps/meteor/app/file-upload/server/lib/FileUpload.ts @@ -26,7 +26,7 @@ import { UploadFS } from '../../../../server/ufs'; import { settings } from '../../../settings/server'; import { mime } from '../../../utils/lib/mimeTypes'; import { canAccessRoomAsync } from '../../../authorization/server/functions/canAccessRoom'; -import { fileUploadIsValidContentType } from '../../../utils/lib/fileUploadRestrictions'; +import { fileUploadIsValidContentType } from '../../../utils/server/restrictions'; import { isValidJWT, generateJWT } from '../../../utils/server/lib/JWTHelper'; import { AppEvents, Apps } from '../../../../ee/server/apps'; import { streamToBuffer } from './streamToBuffer'; @@ -173,7 +173,7 @@ export const FileUpload = { throw new Meteor.Error('error-file-too-large', reason); } - if (!fileUploadIsValidContentType(file.type)) { + if (!fileUploadIsValidContentType(file.type as string, '')) { const reason = TAPi18n.__('File_type_is_not_accepted', { lng: language }); throw new Meteor.Error('error-invalid-file-type', reason); } diff --git a/apps/meteor/app/importer-slack/server/importer.js b/apps/meteor/app/importer-slack/server/importer.js index 5bec6254972..e0fa27c3a25 100644 --- a/apps/meteor/app/importer-slack/server/importer.js +++ b/apps/meteor/app/importer-slack/server/importer.js @@ -4,7 +4,7 @@ import { Messages, Settings, ImportData } from '@rocket.chat/models'; import { Base, ProgressStep, ImporterWebsocket } from '../../importer/server'; import { settings } from '../../settings/server'; import { MentionsParser } from '../../mentions/lib/MentionsParser'; -import { getUserAvatarURL } from '../../utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../utils/server/getUserAvatarURL'; export class SlackImporter extends Base { parseData(data) { diff --git a/apps/meteor/app/invites/server/functions/findOrCreateInvite.js b/apps/meteor/app/invites/server/functions/findOrCreateInvite.js index 5f9d5dcb994..761a98a1bfd 100644 --- a/apps/meteor/app/invites/server/functions/findOrCreateInvite.js +++ b/apps/meteor/app/invites/server/functions/findOrCreateInvite.js @@ -5,7 +5,7 @@ import { api } from '@rocket.chat/core-services'; import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { settings } from '../../../settings/server'; -import { getURL } from '../../../utils/lib/getURL'; +import { getURL } from '../../../utils/server/getURL'; import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator'; import { RoomMemberActions } from '../../../../definition/IRoomTypeConfig'; @@ -14,11 +14,15 @@ function getInviteUrl(invite) { const useDirectLink = settings.get('Accounts_Registration_InviteUrlType') === 'direct'; - return getURL(`invite/${_id}`, { - full: useDirectLink, - cloud: !useDirectLink, - cloud_route: 'invite', - }); + return getURL( + `invite/${_id}`, + { + full: useDirectLink, + cloud: !useDirectLink, + cloud_route: 'invite', + }, + settings.get('DeepLink_Url'), + ); } const possibleDays = [0, 1, 7, 15, 30]; diff --git a/apps/meteor/app/lib/server/functions/attachMessage.ts b/apps/meteor/app/lib/server/functions/attachMessage.ts index 9bf83525ad7..105c2c638c4 100644 --- a/apps/meteor/app/lib/server/functions/attachMessage.ts +++ b/apps/meteor/app/lib/server/functions/attachMessage.ts @@ -1,6 +1,6 @@ import type { IMessage, IRoom, MessageAttachment } from '@rocket.chat/core-typings'; -import { getUserAvatarURL } from '../../../utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../../utils/server/getUserAvatarURL'; import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator'; import { getUserDisplayName } from '../../../../lib/getUserDisplayName'; import { settings } from '../../../settings/server/cached'; @@ -27,7 +27,7 @@ export const attachMessage = function ( return { text: msg, author_name: getUserDisplayName(name, username, useRealName), - author_icon: getUserAvatarURL(username), + author_icon: getUserAvatarURL(username) as string, message_link: `${roomCoordinator.getRouteLink(room.t, room)}?msg=${_id}`, attachments, ts, diff --git a/apps/meteor/app/lib/server/functions/notifications/email.js b/apps/meteor/app/lib/server/functions/notifications/email.js index 2352f18866b..139c5717648 100644 --- a/apps/meteor/app/lib/server/functions/notifications/email.js +++ b/apps/meteor/app/lib/server/functions/notifications/email.js @@ -102,15 +102,19 @@ const getButtonUrl = (room, subscription, message) => { const basePath = roomCoordinator.getRouteLink(room.t, subscription).replace(Meteor.absoluteUrl(), ''); const path = `${ltrim(basePath, '/')}?msg=${message._id}`; - return getURL(path, { - full: true, - cloud: settings.get('Offline_Message_Use_DeepLink'), - cloud_route: 'room', - cloud_params: { - rid: room._id, - mid: message._id, + return getURL( + path, + { + full: true, + cloud: settings.get('Offline_Message_Use_DeepLink'), + cloud_route: 'room', + cloud_params: { + rid: room._id, + mid: message._id, + }, }, - }); + settings.get('DeepLink_Url'), + ); }; function generateNameEmail(name, email) { diff --git a/apps/meteor/app/message-pin/server/pinMessage.ts b/apps/meteor/app/message-pin/server/pinMessage.ts index 83fb2cae2fd..2b741974147 100644 --- a/apps/meteor/app/message-pin/server/pinMessage.ts +++ b/apps/meteor/app/message-pin/server/pinMessage.ts @@ -9,7 +9,7 @@ import { Messages, Rooms, Subscriptions, Users } from '@rocket.chat/models'; import { settings } from '../../settings/server'; import { callbacks } from '../../../lib/callbacks'; import { isTheLastMessage } from '../../lib/server'; -import { getUserAvatarURL } from '../../utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../utils/server/getUserAvatarURL'; import { canAccessRoomAsync, roomAccessAttributes } from '../../authorization/server'; import { hasPermissionAsync } from '../../authorization/server/functions/hasPermission'; import { Apps, AppEvents } from '../../../ee/server/apps/orchestrator'; diff --git a/apps/meteor/app/oembed/server/jumpToMessage.ts b/apps/meteor/app/oembed/server/jumpToMessage.ts index 92023945d46..45d3b27b321 100644 --- a/apps/meteor/app/oembed/server/jumpToMessage.ts +++ b/apps/meteor/app/oembed/server/jumpToMessage.ts @@ -10,6 +10,7 @@ import { createQuoteAttachment } from '../../../lib/createQuoteAttachment'; import { settings } from '../../settings/server'; import { callbacks } from '../../../lib/callbacks'; import { canAccessRoomAsync } from '../../authorization/server/functions/canAccessRoom'; +import { getUserAvatarURL } from '../../utils/server/getUserAvatarURL'; const recursiveRemoveAttachments = (attachments: MessageAttachment, deep = 1, quoteChainLimit: number): MessageAttachment => { if (attachments && isQuoteAttachment(attachments)) { @@ -98,7 +99,9 @@ callbacks.add( const useRealName = Boolean(settings.get('UI_Use_Real_Name')); - msg.attachments.push(createQuoteAttachment(jumpToMessage, item.url, useRealName)); + msg.attachments.push( + createQuoteAttachment(jumpToMessage, item.url, useRealName, getUserAvatarURL(jumpToMessage.u.username || '') as string), + ); item.ignoreParse = true; } diff --git a/apps/meteor/app/slackbridge/server/SlackAdapter.js b/apps/meteor/app/slackbridge/server/SlackAdapter.js index ca8aff16067..dfeaef4bbc0 100644 --- a/apps/meteor/app/slackbridge/server/SlackAdapter.js +++ b/apps/meteor/app/slackbridge/server/SlackAdapter.js @@ -9,7 +9,7 @@ import { Message } from '@rocket.chat/core-services'; import { slackLogger } from './logger'; import { SlackAPI } from './SlackAPI'; -import { getUserAvatarURL } from '../../utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../utils/server/getUserAvatarURL'; import { settings } from '../../settings/server'; import { deleteMessage, updateMessage, addUserToRoom, removeUserFromRoom, unarchiveRoom, sendMessage } from '../../lib/server'; import { archiveRoom } from '../../lib/server/functions/archiveRoom'; diff --git a/apps/meteor/app/ui/client/lib/KonchatNotification.ts b/apps/meteor/app/ui/client/lib/KonchatNotification.ts index 72a3de8aef6..e6adc15c486 100644 --- a/apps/meteor/app/ui/client/lib/KonchatNotification.ts +++ b/apps/meteor/app/ui/client/lib/KonchatNotification.ts @@ -6,7 +6,7 @@ import { Meteor } from 'meteor/meteor'; import { onClientMessageReceived } from '../../../../client/lib/onClientMessageReceived'; import { getUserPreference } from '../../../utils/client'; -import { getUserAvatarURL } from '../../../utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../../utils/client/getUserAvatarURL'; import { e2e } from '../../../e2e/client'; import { ChatSubscription } from '../../../models/client'; import { CustomSounds } from '../../../custom-sounds/client/lib/CustomSounds'; @@ -70,7 +70,7 @@ class KonchatNotification { const requireInteraction = getUserPreference(Meteor.userId(), 'desktopNotificationRequireInteraction'); const n = new Notification(notification.title, { - icon: notification.icon || getUserAvatarURL(notification.payload.sender?.username), + icon: notification.icon || getUserAvatarURL(notification.payload.sender?.username as string), body: stripTags(message.msg), tag: notification.payload._id, canReply: true, diff --git a/apps/meteor/app/utils/lib/getAvatarURL.ts b/apps/meteor/app/utils/client/getAvatarURL.ts similarity index 100% rename from apps/meteor/app/utils/lib/getAvatarURL.ts rename to apps/meteor/app/utils/client/getAvatarURL.ts diff --git a/apps/meteor/app/utils/client/getURL.ts b/apps/meteor/app/utils/client/getURL.ts new file mode 100644 index 00000000000..91ef0989bd1 --- /dev/null +++ b/apps/meteor/app/utils/client/getURL.ts @@ -0,0 +1,13 @@ +import { settings } from '../../settings/client'; +import { getURLWithoutSettings } from '../lib/getURL'; + +export const getURL = function ( + path: string, // eslint-disable-next-line @typescript-eslint/naming-convention + params: Record = {}, + cloudDeepLinkUrl?: string, +): string { + const cdnPrefix = settings.get('CDN_PREFIX') || ''; + const siteUrl = settings.get('Site_Url') || ''; + + return getURLWithoutSettings(path, params, cdnPrefix, siteUrl, cloudDeepLinkUrl); +}; diff --git a/apps/meteor/app/utils/client/getUserAvatarURL.ts b/apps/meteor/app/utils/client/getUserAvatarURL.ts new file mode 100644 index 00000000000..e154145a1ec --- /dev/null +++ b/apps/meteor/app/utils/client/getUserAvatarURL.ts @@ -0,0 +1,14 @@ +import { getAvatarURL } from './getAvatarURL'; +import { settings } from '../../settings/client'; + +export const getUserAvatarURL = function (username: string, cache = ''): string | undefined { + const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); + if (externalSource !== '') { + return externalSource.replace('{username}', username); + } + if (username == null) { + return; + } + + return getAvatarURL({ username, cache }); +}; diff --git a/apps/meteor/app/utils/client/index.ts b/apps/meteor/app/utils/client/index.ts index 5cf9fc86f9a..122ebe05f99 100644 --- a/apps/meteor/app/utils/client/index.ts +++ b/apps/meteor/app/utils/client/index.ts @@ -1,8 +1,8 @@ export { t } from '../lib/tapi18n'; export { Info } from '../rocketchat.info'; export { getUserPreference } from './lib/getUserPreference'; -export { fileUploadIsValidContentType } from '../lib/fileUploadRestrictions'; -export { getUserAvatarURL } from '../lib/getUserAvatarURL'; +export { fileUploadIsValidContentType } from './restrictions'; +export { getUserAvatarURL } from './getUserAvatarURL'; export { slashCommands } from '../lib/slashCommand'; -export { getURL } from '../lib/getURL'; +export { getURL } from './getURL'; export { APIClient } from './lib/RestApiClient'; diff --git a/apps/meteor/app/utils/client/restrictions.ts b/apps/meteor/app/utils/client/restrictions.ts new file mode 100644 index 00000000000..8d57091891e --- /dev/null +++ b/apps/meteor/app/utils/client/restrictions.ts @@ -0,0 +1,9 @@ +import { fileUploadIsValidContentTypeFromSettings } from '../lib/restrictions'; +import { settings } from '../../settings/client'; + +export const fileUploadIsValidContentType = function (type: string, customWhiteList?: string): boolean { + const blackList = settings.get('FileUpload_MediaTypeBlackList'); + const whiteList = customWhiteList || settings.get('FileUpload_MediaTypeWhiteList'); + + return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList); +}; diff --git a/apps/meteor/app/utils/lib/getURL.js b/apps/meteor/app/utils/lib/getURL.ts similarity index 53% rename from apps/meteor/app/utils/lib/getURL.js rename to apps/meteor/app/utils/lib/getURL.ts index a5472ff525d..fae79d65b1d 100644 --- a/apps/meteor/app/utils/lib/getURL.js +++ b/apps/meteor/app/utils/lib/getURL.ts @@ -2,10 +2,16 @@ import { escapeRegExp } from '@rocket.chat/string-helpers'; import { isURL } from '../../../lib/utils/isURL'; import { ltrim, rtrim, trim } from '../../../lib/utils/stringUtils'; -import { settings } from '../../settings'; -function getCloudUrl(path, _site_url, cloudRoute, cloudParams = {}) { - const cloudBaseUrl = (settings.get('DeepLink_Url') || '').replace(/\/+$/, ''); +function getCloudUrl( + path: string, + // eslint-disable-next-line @typescript-eslint/naming-convention + _site_url: string, + cloudRoute: string, + cloudParams: Record = {}, + deeplinkUrl = '', +): string { + const cloudBaseUrl = deeplinkUrl.replace(/\/+$/, ''); const siteUrl = rtrim(_site_url, '/'); @@ -29,7 +35,12 @@ function getCloudUrl(path, _site_url, cloudRoute, cloudParams = {}) { return `${cloudBaseUrl}/${cloudRoute}?${params}`; } -export const _getURL = (path, { cdn, full, cloud, cloud_route, cloud_params, _cdn_prefix, _root_url_path_prefix, _site_url }) => { +export const _getURL = ( + path: string, + // eslint-disable-next-line @typescript-eslint/naming-convention + { cdn, full, cloud, cloud_route, cloud_params, _cdn_prefix, _root_url_path_prefix, _site_url }: Record, + deeplinkUrl?: string, +): string => { if (isURL(path)) { return path; } @@ -49,7 +60,7 @@ export const _getURL = (path, { cdn, full, cloud, cloud_route, cloud_params, _cd if (cloud) { const cloudParams = cloud_params || {}; - return getCloudUrl(url, siteUrl, cloudRoute, cloudParams); + return getCloudUrl(url, siteUrl, cloudRoute, cloudParams, deeplinkUrl); } if (cdn && cdnPrefix !== '') { @@ -63,14 +74,25 @@ export const _getURL = (path, { cdn, full, cloud, cloud_route, cloud_params, _cd return url; }; -export const getURL = (path, { cdn = true, full = false, cloud = false, cloud_route = '', cloud_params = {} } = {}) => - _getURL(path, { - cdn, - full, - cloud, - cloud_route, - cloud_params, - _cdn_prefix: settings.get('CDN_PREFIX'), - _root_url_path_prefix: __meteor_runtime_config__.ROOT_URL_PATH_PREFIX, - _site_url: settings.get('Site_Url'), - }); +export const getURLWithoutSettings = ( + path: string, + // eslint-disable-next-line @typescript-eslint/naming-convention + { cdn = true, full = false, cloud = false, cloud_route = '', cloud_params = {} }: Record = {}, + cdnPrefix: string, + siteUrl: string, + cloudDeepLinkUrl?: string, +): string => + _getURL( + path, + { + cdn, + full, + cloud, + cloud_route, + cloud_params, + _cdn_prefix: cdnPrefix, + _root_url_path_prefix: __meteor_runtime_config__.ROOT_URL_PATH_PREFIX, + _site_url: siteUrl, + }, + cloudDeepLinkUrl, + ); diff --git a/apps/meteor/app/utils/lib/getUserAvatarURL.js b/apps/meteor/app/utils/lib/getUserAvatarURL.js deleted file mode 100644 index 528184c2564..00000000000 --- a/apps/meteor/app/utils/lib/getUserAvatarURL.js +++ /dev/null @@ -1,14 +0,0 @@ -import { getAvatarURL } from './getAvatarURL'; -import { settings } from '../../settings'; - -export const getUserAvatarURL = function (username, cache = '') { - const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); - if (externalSource !== '') { - return externalSource.replace('{username}', username); - } - if (username == null) { - return; - } - - return getAvatarURL({ username, cache }); -}; diff --git a/apps/meteor/app/utils/lib/fileUploadRestrictions.js b/apps/meteor/app/utils/lib/restrictions.ts similarity index 57% rename from apps/meteor/app/utils/lib/fileUploadRestrictions.js rename to apps/meteor/app/utils/lib/restrictions.ts index 403f5503cf7..29263e5b825 100644 --- a/apps/meteor/app/utils/lib/fileUploadRestrictions.js +++ b/apps/meteor/app/utils/lib/restrictions.ts @@ -1,15 +1,7 @@ -import { Meteor } from 'meteor/meteor'; import _ from 'underscore'; -let settings; -if (Meteor.isClient) { - settings = require('../../settings/client').settings; -} else { - settings = require('../../settings/server').settings; -} - -export const fileUploadMediaWhiteList = function (customWhiteList) { - const mediaTypeWhiteList = customWhiteList || settings.get('FileUpload_MediaTypeWhiteList'); +export const fileUploadMediaWhiteList = function (customWhiteList: string): string[] | undefined { + const mediaTypeWhiteList = customWhiteList; if (!mediaTypeWhiteList || mediaTypeWhiteList === '*') { return; @@ -19,8 +11,8 @@ export const fileUploadMediaWhiteList = function (customWhiteList) { }); }; -const fileUploadMediaBlackList = function () { - const blacklist = settings.get('FileUpload_MediaTypeBlackList'); +const fileUploadMediaBlackList = function (customBlackList: string): string[] | undefined { + const blacklist = customBlackList; if (!blacklist) { return; } @@ -28,7 +20,7 @@ const fileUploadMediaBlackList = function () { return _.map(blacklist.split(','), (item) => item.trim()); }; -const isTypeOnList = function (type, list) { +const isTypeOnList = function (type: string, list: string[]): boolean | undefined { if (_.contains(list, type)) { return true; } @@ -41,8 +33,8 @@ const isTypeOnList = function (type, list) { } }; -export const fileUploadIsValidContentType = function (type, customWhiteList) { - const blackList = fileUploadMediaBlackList(); +export const fileUploadIsValidContentTypeFromSettings = function (type: string, customWhiteList: string, customBlackList: string): boolean { + const blackList = fileUploadMediaBlackList(customBlackList); const whiteList = fileUploadMediaWhiteList(customWhiteList); if (!type && blackList) { @@ -57,5 +49,5 @@ export const fileUploadIsValidContentType = function (type, customWhiteList) { return true; } - return isTypeOnList(type, whiteList); + return !!isTypeOnList(type, whiteList); }; diff --git a/apps/meteor/app/utils/server/functions/normalizeMessageFileUpload.ts b/apps/meteor/app/utils/server/functions/normalizeMessageFileUpload.ts index bd20c4e9eb1..f00bda5a501 100644 --- a/apps/meteor/app/utils/server/functions/normalizeMessageFileUpload.ts +++ b/apps/meteor/app/utils/server/functions/normalizeMessageFileUpload.ts @@ -1,7 +1,7 @@ import { Uploads } from '@rocket.chat/models'; import type { IMessage } from '@rocket.chat/core-typings'; -import { getURL } from '../../lib/getURL'; +import { getURL } from '../getURL'; import { FileUpload } from '../../../file-upload/server'; export const normalizeMessageFileUpload = async (message: Omit): Promise> => { diff --git a/apps/meteor/app/utils/server/getAvatarURL.ts b/apps/meteor/app/utils/server/getAvatarURL.ts new file mode 100644 index 00000000000..b03903dbf58 --- /dev/null +++ b/apps/meteor/app/utils/server/getAvatarURL.ts @@ -0,0 +1,10 @@ +import { getURL } from './getURL'; + +export const getAvatarURL = ({ username, roomId, cache }: { username?: string; roomId?: string; cache?: string }): string | undefined => { + if (username) { + return getURL(`/avatar/${encodeURIComponent(username)}${cache ? `?etag=${cache}` : ''}`); + } + if (roomId) { + return getURL(`/avatar/room/${encodeURIComponent(roomId)}${cache ? `?etag=${cache}` : ''}`); + } +}; diff --git a/apps/meteor/app/utils/server/getURL.ts b/apps/meteor/app/utils/server/getURL.ts new file mode 100644 index 00000000000..17e0a68efa8 --- /dev/null +++ b/apps/meteor/app/utils/server/getURL.ts @@ -0,0 +1,13 @@ +import { settings } from '../../settings/server'; +import { getURLWithoutSettings } from '../lib/getURL'; + +export const getURL = function ( + path: string, // eslint-disable-next-line @typescript-eslint/naming-convention + params: Record = {}, + cloudDeepLinkUrl?: string, +): string { + const cdnPrefix = settings.get('CDN_PREFIX') || ''; + const siteUrl = settings.get('Site_Url') || ''; + + return getURLWithoutSettings(path, params, cdnPrefix, siteUrl, cloudDeepLinkUrl); +}; diff --git a/apps/meteor/app/utils/server/getUserAvatarURL.ts b/apps/meteor/app/utils/server/getUserAvatarURL.ts new file mode 100644 index 00000000000..e45b808f832 --- /dev/null +++ b/apps/meteor/app/utils/server/getUserAvatarURL.ts @@ -0,0 +1,14 @@ +import { getAvatarURL } from './getAvatarURL'; +import { settings } from '../../settings/server'; + +export const getUserAvatarURL = function (username: string, cache = ''): string | undefined { + const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); + if (externalSource !== '') { + return externalSource.replace('{username}', username); + } + if (username == null) { + return; + } + + return getAvatarURL({ username, cache }); +}; diff --git a/apps/meteor/app/utils/server/index.ts b/apps/meteor/app/utils/server/index.ts index 9b0f8d3b74f..2cea2faf5ae 100644 --- a/apps/meteor/app/utils/server/index.ts +++ b/apps/meteor/app/utils/server/index.ts @@ -2,13 +2,13 @@ export { t } from '../lib/tapi18n'; export { getDefaultSubscriptionPref } from '../lib/getDefaultSubscriptionPref'; export { Info } from '../rocketchat.info'; export { getUserPreference } from './lib/getUserPreference'; -export { fileUploadIsValidContentType } from '../lib/fileUploadRestrictions'; +export { fileUploadIsValidContentType } from './restrictions'; export { isDocker } from './functions/isDocker'; export { getMongoInfo } from './functions/getMongoInfo'; export { slashCommands } from '../lib/slashCommand'; export { getUserNotificationPreference } from '../lib/getUserNotificationPreference'; export { getAvatarColor } from '../lib/getAvatarColor'; -export { getURL } from '../lib/getURL'; +export { getURL } from './getURL'; export { getValidRoomName } from './lib/getValidRoomName'; export { placeholders } from '../lib/placeholders'; export { secondsToHHMMSS } from '../../../lib/utils/secondsToHHMMSS'; diff --git a/apps/meteor/app/utils/server/restrictions.ts b/apps/meteor/app/utils/server/restrictions.ts new file mode 100644 index 00000000000..543590dea91 --- /dev/null +++ b/apps/meteor/app/utils/server/restrictions.ts @@ -0,0 +1,9 @@ +import { fileUploadIsValidContentTypeFromSettings } from '../lib/restrictions'; +import { settings } from '../../settings/server'; + +export const fileUploadIsValidContentType = function (type: string, customWhiteList?: string): boolean { + const blackList = settings.get('FileUpload_MediaTypeBlackList'); + const whiteList = customWhiteList || settings.get('FileUpload_MediaTypeWhiteList'); + + return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList); +}; diff --git a/apps/meteor/app/webdav/client/actionButton.ts b/apps/meteor/app/webdav/client/actionButton.ts index ed6e764d9a4..84e66794074 100644 --- a/apps/meteor/app/webdav/client/actionButton.ts +++ b/apps/meteor/app/webdav/client/actionButton.ts @@ -29,7 +29,7 @@ Meteor.startup(function () { action(_, props) { const { message = messageArgs(this).msg } = props; const [attachment] = message.attachments || []; - const url = getURL(attachment.title_link, { full: true }); + const url = getURL(attachment.title_link as string, { full: true }); imperativeModal.open({ component: SaveToWebdav, props: { diff --git a/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx b/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx index edf4267e55e..8405677dc26 100644 --- a/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx +++ b/apps/meteor/client/components/avatar/RoomAvatarEditor.tsx @@ -7,7 +7,7 @@ import { useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-context import type { ReactElement } from 'react'; import React, { useEffect } from 'react'; -import { getAvatarURL } from '../../../app/utils/lib/getAvatarURL'; +import { getAvatarURL } from '../../../app/utils/client/getAvatarURL'; import { useFileInput } from '../../hooks/useFileInput'; import { isValidImageFormat } from '../../lib/utils/isValidImageFormat'; import RoomAvatar from './RoomAvatar'; diff --git a/apps/meteor/client/components/voip/room/VoipRoomForeword.tsx b/apps/meteor/client/components/voip/room/VoipRoomForeword.tsx index 2f0908959eb..f02ebc3fad3 100644 --- a/apps/meteor/client/components/voip/room/VoipRoomForeword.tsx +++ b/apps/meteor/client/components/voip/room/VoipRoomForeword.tsx @@ -10,7 +10,7 @@ import { parseOutboundPhoneNumber } from '../../../../ee/client/lib/voip/parseOu export const VoipRoomForeword = ({ room }: { room: IVoipRoom }): ReactElement => { const t = useTranslation(); - const avatarUrl = getUserAvatarURL(room.name); + const avatarUrl = getUserAvatarURL(room.name) as string; const roomName = room.fname; diff --git a/apps/meteor/client/lib/rooms/roomTypes/direct.ts b/apps/meteor/client/lib/rooms/roomTypes/direct.ts index 8cecd24f823..575ec1534b9 100644 --- a/apps/meteor/client/lib/rooms/roomTypes/direct.ts +++ b/apps/meteor/client/lib/rooms/roomTypes/direct.ts @@ -7,8 +7,8 @@ import { hasAtLeastOnePermission } from '../../../../app/authorization/client'; import { Subscriptions, Users, ChatRoom } from '../../../../app/models/client'; import { settings } from '../../../../app/settings/client'; import { getUserPreference } from '../../../../app/utils/client'; -import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL'; -import { getUserAvatarURL } from '../../../../app/utils/lib/getUserAvatarURL'; +import { getAvatarURL } from '../../../../app/utils/client/getAvatarURL'; +import { getUserAvatarURL } from '../../../../app/utils/client/getUserAvatarURL'; import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig'; import { RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../../../../definition/IRoomTypeConfig'; import { getDirectMessageRoomType } from '../../../../lib/rooms/roomTypes/direct'; @@ -126,7 +126,7 @@ roomCoordinator.add( return getUserAvatarURL(user?.username || sub.name, user?.avatarETag); } - return getUserAvatarURL(room.name || this.roomName(room)); + return getUserAvatarURL(room.name || this.roomName(room) || ''); }, getIcon(room) { diff --git a/apps/meteor/client/lib/rooms/roomTypes/livechat.ts b/apps/meteor/client/lib/rooms/roomTypes/livechat.ts index 0d91abc8051..82f2a48a9a9 100644 --- a/apps/meteor/client/lib/rooms/roomTypes/livechat.ts +++ b/apps/meteor/client/lib/rooms/roomTypes/livechat.ts @@ -3,7 +3,7 @@ import type { AtLeast, ValueOf } from '@rocket.chat/core-typings'; import { hasPermission } from '../../../../app/authorization/client'; import { ChatRoom, ChatSubscription } from '../../../../app/models/client'; import { settings } from '../../../../app/settings/client'; -import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL'; +import { getAvatarURL } from '../../../../app/utils/client/getAvatarURL'; import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig'; import { RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../../../../definition/IRoomTypeConfig'; import { getLivechatRoomType } from '../../../../lib/rooms/roomTypes/livechat'; diff --git a/apps/meteor/client/lib/rooms/roomTypes/private.ts b/apps/meteor/client/lib/rooms/roomTypes/private.ts index b9cc5deabf7..7cf087fe772 100644 --- a/apps/meteor/client/lib/rooms/roomTypes/private.ts +++ b/apps/meteor/client/lib/rooms/roomTypes/private.ts @@ -7,7 +7,7 @@ import { hasPermission } from '../../../../app/authorization/client'; import { ChatRoom } from '../../../../app/models/client'; import { settings } from '../../../../app/settings/client'; import { getUserPreference } from '../../../../app/utils/client'; -import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL'; +import { getAvatarURL } from '../../../../app/utils/client/getAvatarURL'; import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig'; import { RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../../../../definition/IRoomTypeConfig'; import { getPrivateRoomType } from '../../../../lib/rooms/roomTypes/private'; diff --git a/apps/meteor/client/lib/rooms/roomTypes/public.ts b/apps/meteor/client/lib/rooms/roomTypes/public.ts index c94125ed4e7..62ae0d74a24 100644 --- a/apps/meteor/client/lib/rooms/roomTypes/public.ts +++ b/apps/meteor/client/lib/rooms/roomTypes/public.ts @@ -7,7 +7,7 @@ import { hasAtLeastOnePermission } from '../../../../app/authorization/client'; import { ChatRoom } from '../../../../app/models/client'; import { settings } from '../../../../app/settings/client'; import { getUserPreference } from '../../../../app/utils/client'; -import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL'; +import { getAvatarURL } from '../../../../app/utils/client/getAvatarURL'; import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig'; import { RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../../../../definition/IRoomTypeConfig'; import { getPublicRoomType } from '../../../../lib/rooms/roomTypes/public'; diff --git a/apps/meteor/client/lib/rooms/roomTypes/voip.ts b/apps/meteor/client/lib/rooms/roomTypes/voip.ts index 2a8c27bba3d..258103651e0 100644 --- a/apps/meteor/client/lib/rooms/roomTypes/voip.ts +++ b/apps/meteor/client/lib/rooms/roomTypes/voip.ts @@ -3,7 +3,7 @@ import type { AtLeast } from '@rocket.chat/core-typings'; import { hasPermission } from '../../../../app/authorization/client'; import { ChatRoom } from '../../../../app/models/client'; import { settings } from '../../../../app/settings/client'; -import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL'; +import { getAvatarURL } from '../../../../app/utils/client/getAvatarURL'; import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig'; import { getVoipRoomType } from '../../../../lib/rooms/roomTypes/voip'; import { roomCoordinator } from '../roomCoordinator'; diff --git a/apps/meteor/client/lib/utils/getAvatarAsPng.ts b/apps/meteor/client/lib/utils/getAvatarAsPng.ts index fe39b5449e1..dabbd7efd65 100644 --- a/apps/meteor/client/lib/utils/getAvatarAsPng.ts +++ b/apps/meteor/client/lib/utils/getAvatarAsPng.ts @@ -1,6 +1,6 @@ import type { IUser } from '@rocket.chat/core-typings'; -import { getUserAvatarURL } from '../../../app/utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../../app/utils/client/getUserAvatarURL'; export const getAvatarAsPng = (username: IUser['username'], cb: (dataURL: string) => void): (() => void) => { const image = new Image(); @@ -27,7 +27,7 @@ export const getAvatarAsPng = (username: IUser['username'], cb: (dataURL: string image.onload = onLoad; image.onerror = onError; - image.src = getUserAvatarURL(username); + image.src = getUserAvatarURL(username || '') as string; return onError; }; diff --git a/apps/meteor/client/providers/AvatarUrlProvider.tsx b/apps/meteor/client/providers/AvatarUrlProvider.tsx index 18ad6b2e5f1..0f00e447c75 100644 --- a/apps/meteor/client/providers/AvatarUrlProvider.tsx +++ b/apps/meteor/client/providers/AvatarUrlProvider.tsx @@ -2,7 +2,7 @@ import { AvatarUrlContext, useSetting } from '@rocket.chat/ui-contexts'; import type { FC } from 'react'; import React, { useMemo } from 'react'; -import { getURL } from '../../app/utils/lib/getURL'; +import { getURL } from '../../app/utils/client/getURL'; import { roomCoordinator } from '../lib/rooms/roomCoordinator'; const AvatarUrlProvider: FC = ({ children }) => { diff --git a/apps/meteor/client/templateHelpers/avatarUrlFromUsername.ts b/apps/meteor/client/templateHelpers/avatarUrlFromUsername.ts index bda7294c1d7..1fc635bd9c6 100644 --- a/apps/meteor/client/templateHelpers/avatarUrlFromUsername.ts +++ b/apps/meteor/client/templateHelpers/avatarUrlFromUsername.ts @@ -1,5 +1,5 @@ import { Template } from 'meteor/templating'; -import { getUserAvatarURL } from '../../app/utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../app/utils/client/getUserAvatarURL'; Template.registerHelper('avatarUrlFromUsername', getUserAvatarURL); diff --git a/apps/meteor/client/views/modal/uikit/ModalBlock.tsx b/apps/meteor/client/views/modal/uikit/ModalBlock.tsx index 4729c75163b..7993355206e 100644 --- a/apps/meteor/client/views/modal/uikit/ModalBlock.tsx +++ b/apps/meteor/client/views/modal/uikit/ModalBlock.tsx @@ -8,7 +8,7 @@ import type { FormEventHandler, ReactElement } from 'react'; import React, { useCallback, useEffect, useMemo, useRef } from 'react'; import { FocusScope } from 'react-aria'; -import { getURL } from '../../../../app/utils/lib/getURL'; +import { getURL } from '../../../../app/utils/client/getURL'; import { getButtonStyle } from './getButtonStyle'; const focusableElementsString = ` diff --git a/apps/meteor/client/views/room/contextualBar/Apps/Apps.tsx b/apps/meteor/client/views/room/contextualBar/Apps/Apps.tsx index 19d242da58f..d8d722d2d13 100644 --- a/apps/meteor/client/views/room/contextualBar/Apps/Apps.tsx +++ b/apps/meteor/client/views/room/contextualBar/Apps/Apps.tsx @@ -5,7 +5,7 @@ import type { LayoutBlock } from '@rocket.chat/ui-kit'; import { BlockContext } from '@rocket.chat/ui-kit'; import React from 'react'; -import { getURL } from '../../../../../app/utils/lib/getURL'; +import { getURL } from '../../../../../app/utils/client/getURL'; import VerticalBar from '../../../../components/VerticalBar'; import { getButtonStyle } from '../../../modal/uikit/getButtonStyle'; diff --git a/apps/meteor/ee/client/apps/RealAppsEngineUIHost.js b/apps/meteor/ee/client/apps/RealAppsEngineUIHost.js index eed258c26bf..bd92603f1b1 100644 --- a/apps/meteor/ee/client/apps/RealAppsEngineUIHost.js +++ b/apps/meteor/ee/client/apps/RealAppsEngineUIHost.js @@ -3,7 +3,7 @@ import { Meteor } from 'meteor/meteor'; import { ChatRoom } from '../../../app/models/client'; import { APIClient } from '../../../app/utils/client'; -import { getUserAvatarURL } from '../../../app/utils/lib/getUserAvatarURL'; +import { getUserAvatarURL } from '../../../app/utils/client/getUserAvatarURL'; import { RoomManager } from '../../../client/lib/RoomManager'; import { baseURI } from '../../../client/lib/baseURI'; @@ -53,7 +53,7 @@ export class RealAppsEngineUIHost extends AppsEngineUIHost { return { id: _id, username, - avatarUrl: this.getUserAvatarUrl(username), + avatarUrl: this.getUserAvatarUrl(username) || '', }; } } diff --git a/apps/meteor/lib/createQuoteAttachment.ts b/apps/meteor/lib/createQuoteAttachment.ts index 90f64b10497..99e0f6f9229 100644 --- a/apps/meteor/lib/createQuoteAttachment.ts +++ b/apps/meteor/lib/createQuoteAttachment.ts @@ -1,17 +1,21 @@ import { isTranslatedMessage } from '@rocket.chat/core-typings'; import type { ITranslatedMessage, IMessage } from '@rocket.chat/core-typings'; -import { getUserAvatarURL } from '../app/utils/lib/getUserAvatarURL'; import { getUserDisplayName } from './getUserDisplayName'; -export function createQuoteAttachment(message: IMessage | ITranslatedMessage, messageLink: string, useRealName: boolean) { +export function createQuoteAttachment( + message: IMessage | ITranslatedMessage, + messageLink: string, + useRealName: boolean, + userAvatarUrl: string, +) { return { text: message.msg, md: message.md, ...(isTranslatedMessage(message) && { translations: message?.translations }), message_link: messageLink, author_name: message.alias || getUserDisplayName(message.u.name, message.u.username, useRealName), - author_icon: getUserAvatarURL(message.u.username), + author_icon: userAvatarUrl, attachments: message.attachments || [], ts: message.ts, }; diff --git a/apps/meteor/server/lib/dataExport/processDataDownloads.ts b/apps/meteor/server/lib/dataExport/processDataDownloads.ts index a9aab2bffb4..7c8817e7ffd 100644 --- a/apps/meteor/server/lib/dataExport/processDataDownloads.ts +++ b/apps/meteor/server/lib/dataExport/processDataDownloads.ts @@ -11,7 +11,7 @@ import { settings } from '../../../app/settings/server'; import { FileUpload } from '../../../app/file-upload/server'; import { getPath } from './getPath'; import { joinPath } from '../fileUtils'; -import { getURL } from '../../../app/utils/lib/getURL'; +import { getURL } from '../../../app/utils/server/getURL'; import { getRoomData } from './getRoomData'; import { sendEmail } from './sendEmail'; import { makeZipFile } from './makeZipFile'; diff --git a/apps/meteor/server/lib/dataExport/sendFile.ts b/apps/meteor/server/lib/dataExport/sendFile.ts index 38db5fb3963..75e5d6a918f 100644 --- a/apps/meteor/server/lib/dataExport/sendFile.ts +++ b/apps/meteor/server/lib/dataExport/sendFile.ts @@ -5,7 +5,7 @@ import { tmpdir } from 'os'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; import type { IUser } from '@rocket.chat/core-typings'; -import { getURL } from '../../../app/utils/lib/getURL'; +import { getURL } from '../../../app/utils/server/getURL'; import { getPath } from './getPath'; import { copyFileUpload } from './copyFileUpload'; import { getRoomData } from './getRoomData'; diff --git a/apps/meteor/server/services/omnichannel-integrations/providers/twilio.ts b/apps/meteor/server/services/omnichannel-integrations/providers/twilio.ts index abb332f2cd1..42c4bca39b9 100644 --- a/apps/meteor/server/services/omnichannel-integrations/providers/twilio.ts +++ b/apps/meteor/server/services/omnichannel-integrations/providers/twilio.ts @@ -6,7 +6,7 @@ import { api } from '@rocket.chat/core-services'; import { Users } from '@rocket.chat/models'; import { settings } from '../../../../app/settings/server'; -import { fileUploadIsValidContentType } from '../../../../app/utils/lib/fileUploadRestrictions'; +import { fileUploadIsValidContentType } from '../../../../app/utils/server/restrictions'; import { SystemLogger } from '../../../lib/logger/system'; type TwilioData = { @@ -148,7 +148,7 @@ export class Twilio implements ISMSProvider { size: filesize(MAX_FILE_SIZE), lng, }); - } else if (!fileUploadIsValidContentType(type, this.fileUploadMediaTypeWhiteList)) { + } else if (!fileUploadIsValidContentType(type, this.fileUploadMediaTypeWhiteList())) { reason = TAPi18n.__('File_type_is_not_accepted', { lng }); } @@ -181,7 +181,7 @@ export class Twilio implements ISMSProvider { }; } - fileUploadMediaTypeWhiteList() { + fileUploadMediaTypeWhiteList(): any { throw new Error('Method not implemented.'); } diff --git a/apps/meteor/server/services/omnichannel-integrations/providers/voxtelesys.ts b/apps/meteor/server/services/omnichannel-integrations/providers/voxtelesys.ts index dc778194628..82c57f58ca4 100644 --- a/apps/meteor/server/services/omnichannel-integrations/providers/voxtelesys.ts +++ b/apps/meteor/server/services/omnichannel-integrations/providers/voxtelesys.ts @@ -6,7 +6,7 @@ import type { ISMSProvider, ServiceData, SMSProviderResponse } from '@rocket.cha import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { settings } from '../../../../app/settings/server'; -import { fileUploadIsValidContentType } from '../../../../app/utils/lib/fileUploadRestrictions'; +import { fileUploadIsValidContentType } from '../../../../app/utils/server/restrictions'; import { mime } from '../../../../app/utils/lib/mimeTypes'; import { SystemLogger } from '../../../lib/logger/system'; @@ -119,7 +119,7 @@ export class Voxtelesys implements ISMSProvider { size: filesize(MAX_FILE_SIZE), lng, }); - } else if (!fileUploadIsValidContentType(type, this.fileUploadMediaTypeWhiteList)) { + } else if (!fileUploadIsValidContentType(type, this.fileUploadMediaTypeWhiteList())) { reason = TAPi18n.__('File_type_is_not_accepted', { lng }); } @@ -151,7 +151,7 @@ export class Voxtelesys implements ISMSProvider { } } - fileUploadMediaTypeWhiteList() { + fileUploadMediaTypeWhiteList(): any { throw new Error('Method not implemented.'); } diff --git a/apps/meteor/tests/unit/app/utils/lib/getURL.tests.js b/apps/meteor/tests/unit/app/utils/lib/getURL.tests.js index 50b6d1db2a3..8a714a143e6 100644 --- a/apps/meteor/tests/unit/app/utils/lib/getURL.tests.js +++ b/apps/meteor/tests/unit/app/utils/lib/getURL.tests.js @@ -12,11 +12,6 @@ const { _getURL } = proxyquire.noCallThru().load('../../../../../app/utils/lib/g }, '@global': true, }, - '../../settings': { - settings: { - get: () => 'https://go.rocket.chat', - }, - }, }); const testPaths = (o, _processPath) => { @@ -25,17 +20,19 @@ const testPaths = (o, _processPath) => { processPath = (path) => _processPath(o._root_url_path_prefix + path); } - expect(_getURL('', o)).to.be.equal(processPath('')); - expect(_getURL('/', o)).to.be.equal(processPath('')); - expect(_getURL('//', o)).to.be.equal(processPath('')); - expect(_getURL('///', o)).to.be.equal(processPath('')); - expect(_getURL('/channel', o)).to.be.equal(processPath('/channel')); - expect(_getURL('/channel/', o)).to.be.equal(processPath('/channel')); - expect(_getURL('/channel//', o)).to.be.equal(processPath('/channel')); - expect(_getURL('/channel/123', o)).to.be.equal(processPath('/channel/123')); - expect(_getURL('/channel/123/', o)).to.be.equal(processPath('/channel/123')); - expect(_getURL('/channel/123?id=456&name=test', o)).to.be.equal(processPath('/channel/123?id=456&name=test')); - expect(_getURL('/channel/123/?id=456&name=test', o)).to.be.equal(processPath('/channel/123?id=456&name=test')); + const cloudDeepLinkUrl = 'https://go.rocket.chat'; + + expect(_getURL('', o, cloudDeepLinkUrl)).to.be.equal(processPath('')); + expect(_getURL('/', o, cloudDeepLinkUrl)).to.be.equal(processPath('')); + expect(_getURL('//', o, cloudDeepLinkUrl)).to.be.equal(processPath('')); + expect(_getURL('///', o, cloudDeepLinkUrl)).to.be.equal(processPath('')); + expect(_getURL('/channel', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel')); + expect(_getURL('/channel/', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel')); + expect(_getURL('/channel//', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel')); + expect(_getURL('/channel/123', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123')); + expect(_getURL('/channel/123/', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123')); + expect(_getURL('/channel/123?id=456&name=test', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123?id=456&name=test')); + expect(_getURL('/channel/123/?id=456&name=test', o, cloudDeepLinkUrl)).to.be.equal(processPath('/channel/123?id=456&name=test')); }; const getCloudUrl = (_site_url, path) => {