refactor: Separate isomorphic imports on utils - 1 (#29052)

pull/28330/head^2
Kevin Aleman 3 years ago committed by GitHub
parent 37cb94cc8c
commit 93f9828b5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/meteor/app/api/server/v1/misc.ts
  2. 4
      apps/meteor/app/assets/server/assets.ts
  3. 8
      apps/meteor/app/authorization/index.js
  4. 9
      apps/meteor/app/e2e/client/rocketchat.e2e.ts
  5. 4
      apps/meteor/app/file-upload/server/lib/FileUpload.ts
  6. 2
      apps/meteor/app/importer-slack/server/importer.js
  7. 16
      apps/meteor/app/invites/server/functions/findOrCreateInvite.js
  8. 4
      apps/meteor/app/lib/server/functions/attachMessage.ts
  9. 20
      apps/meteor/app/lib/server/functions/notifications/email.js
  10. 2
      apps/meteor/app/message-pin/server/pinMessage.ts
  11. 5
      apps/meteor/app/oembed/server/jumpToMessage.ts
  12. 2
      apps/meteor/app/slackbridge/server/SlackAdapter.js
  13. 4
      apps/meteor/app/ui/client/lib/KonchatNotification.ts
  14. 0
      apps/meteor/app/utils/client/getAvatarURL.ts
  15. 13
      apps/meteor/app/utils/client/getURL.ts
  16. 14
      apps/meteor/app/utils/client/getUserAvatarURL.ts
  17. 6
      apps/meteor/app/utils/client/index.ts
  18. 9
      apps/meteor/app/utils/client/restrictions.ts
  19. 54
      apps/meteor/app/utils/lib/getURL.ts
  20. 14
      apps/meteor/app/utils/lib/getUserAvatarURL.js
  21. 24
      apps/meteor/app/utils/lib/restrictions.ts
  22. 2
      apps/meteor/app/utils/server/functions/normalizeMessageFileUpload.ts
  23. 10
      apps/meteor/app/utils/server/getAvatarURL.ts
  24. 13
      apps/meteor/app/utils/server/getURL.ts
  25. 14
      apps/meteor/app/utils/server/getUserAvatarURL.ts
  26. 4
      apps/meteor/app/utils/server/index.ts
  27. 9
      apps/meteor/app/utils/server/restrictions.ts
  28. 2
      apps/meteor/app/webdav/client/actionButton.ts
  29. 2
      apps/meteor/client/components/avatar/RoomAvatarEditor.tsx
  30. 2
      apps/meteor/client/components/voip/room/VoipRoomForeword.tsx
  31. 6
      apps/meteor/client/lib/rooms/roomTypes/direct.ts
  32. 2
      apps/meteor/client/lib/rooms/roomTypes/livechat.ts
  33. 2
      apps/meteor/client/lib/rooms/roomTypes/private.ts
  34. 2
      apps/meteor/client/lib/rooms/roomTypes/public.ts
  35. 2
      apps/meteor/client/lib/rooms/roomTypes/voip.ts
  36. 4
      apps/meteor/client/lib/utils/getAvatarAsPng.ts
  37. 2
      apps/meteor/client/providers/AvatarUrlProvider.tsx
  38. 2
      apps/meteor/client/templateHelpers/avatarUrlFromUsername.ts
  39. 2
      apps/meteor/client/views/modal/uikit/ModalBlock.tsx
  40. 2
      apps/meteor/client/views/room/contextualBar/Apps/Apps.tsx
  41. 4
      apps/meteor/ee/client/apps/RealAppsEngineUIHost.js
  42. 10
      apps/meteor/lib/createQuoteAttachment.ts
  43. 2
      apps/meteor/server/lib/dataExport/processDataDownloads.ts
  44. 2
      apps/meteor/server/lib/dataExport/sendFile.ts
  45. 6
      apps/meteor/server/services/omnichannel-integrations/providers/twilio.ts
  46. 6
      apps/meteor/server/services/omnichannel-integrations/providers/voxtelesys.ts
  47. 29
      apps/meteor/tests/unit/app/utils/lib/getURL.tests.js

@ -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';

@ -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<IRocketChatAsset>(assetName);
const url = asset.url || asset.defaultUrl;
return getURL(url, options);
return getURL(url as string, options);
}
}

@ -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');
}

@ -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);
}),

@ -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);
}

@ -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) {

@ -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];

@ -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,

@ -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) {

@ -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';

@ -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;
}

@ -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';

@ -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<boolean>(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,

@ -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<string, any> = {},
cloudDeepLinkUrl?: string,
): string {
const cdnPrefix = settings.get('CDN_PREFIX') || '';
const siteUrl = settings.get('Site_Url') || '';
return getURLWithoutSettings(path, params, cdnPrefix, siteUrl, cloudDeepLinkUrl);
};

@ -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<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
if (username == null) {
return;
}
return getAvatarURL({ username, cache });
};

@ -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';

@ -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<string>('FileUpload_MediaTypeBlackList');
const whiteList = customWhiteList || settings.get<string>('FileUpload_MediaTypeWhiteList');
return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList);
};

@ -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<string, string> = {},
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<string, any>,
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<string, any> = {},
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,
);

@ -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 });
};

@ -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);
};

@ -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<IMessage, '_updatedAt'>): Promise<Omit<IMessage, '_updatedAt'>> => {

@ -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}` : ''}`);
}
};

@ -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<string, any> = {},
cloudDeepLinkUrl?: string,
): string {
const cdnPrefix = settings.get<string>('CDN_PREFIX') || '';
const siteUrl = settings.get<string>('Site_Url') || '';
return getURLWithoutSettings(path, params, cdnPrefix, siteUrl, cloudDeepLinkUrl);
};

@ -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<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
if (username == null) {
return;
}
return getAvatarURL({ username, cache });
};

@ -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';

@ -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<string>('FileUpload_MediaTypeBlackList');
const whiteList = customWhiteList || settings.get<string>('FileUpload_MediaTypeWhiteList');
return fileUploadIsValidContentTypeFromSettings(type, whiteList, blackList);
};

@ -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: {

@ -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';

@ -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;

@ -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) {

@ -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';

@ -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';

@ -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';

@ -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';

@ -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;
};

@ -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 }) => {

@ -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);

@ -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 = `

@ -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';

@ -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) || '',
};
}
}

@ -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,
};

@ -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';

@ -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';

@ -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.');
}

@ -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.');
}

@ -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) => {

Loading…
Cancel
Save