From 04a3d87a64a4340b74125a87d690d416d6fbe637 Mon Sep 17 00:00:00 2001 From: Leonardo Ostjen Couto Date: Thu, 3 Feb 2022 10:15:28 -0300 Subject: [PATCH 1/9] [FIX] Slash commands previews not working (#24387) --- app/utils/lib/slashCommand.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/utils/lib/slashCommand.js b/app/utils/lib/slashCommand.js index 67e72e36cf0ae..42d9dd5a53651 100644 --- a/app/utils/lib/slashCommand.js +++ b/app/utils/lib/slashCommand.js @@ -24,18 +24,25 @@ export const slashCommands = { return slashCommands.commands[command].callback(command, params, message, triggerId); } }, - getPreviews: function _executeSlashCommandPreview(command, params, message, preview, triggerId) { - if (slashCommands.commands[command] && typeof slashCommands.commands[command].previewCallback === 'function') { + getPreviews: function _gettingSlashCommandPreviews(command, params, message) { + if (slashCommands.commands[command] && typeof slashCommands.commands[command].previewer === 'function') { if (!message || !message.rid) { throw new Meteor.Error('invalid-command-usage', 'Executing a command requires at least a message with a room id.'); } - // { id, type, value } - if (!preview.id || !preview.type || !preview.value) { - throw new Meteor.Error('error-invalid-preview', 'Preview Item must have an id, type, and value.'); + // { i18nTitle, items: [{ id, type, value }] } + const previewInfo = slashCommands.commands[command].previewer(command, params, message); + + if (typeof previewInfo !== 'object' || !Array.isArray(previewInfo.items) || previewInfo.items.length === 0) { + return; } - return slashCommands.commands[command].previewCallback(command, params, message, preview, triggerId); + // A limit of ten results, to save time and bandwidth + if (previewInfo.items.length >= 10) { + previewInfo.items = previewInfo.items.slice(0, 10); + } + + return previewInfo; } }, executePreview: function _executeSlashCommandPreview(command, params, message, preview, triggerId) { From 8c6c788b20a86a32eeeaf7f850a99827fb7b5b40 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 3 Feb 2022 10:15:52 -0300 Subject: [PATCH 2/9] [FIX] Add ?close to OAuth callback url (#24381) --- client/lib/oauthRedirectUri.ts | 16 ++++++++++++++++ client/main.ts | 1 + client/startup/oauth.ts | 3 +-- definition/externals/meteor/oauth.d.ts | 7 +++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 client/lib/oauthRedirectUri.ts create mode 100644 definition/externals/meteor/oauth.d.ts diff --git a/client/lib/oauthRedirectUri.ts b/client/lib/oauthRedirectUri.ts new file mode 100644 index 0000000000000..447340588891e --- /dev/null +++ b/client/lib/oauthRedirectUri.ts @@ -0,0 +1,16 @@ +import { OAuth } from 'meteor/oauth'; + +const { _redirectUri } = OAuth; + +OAuth._redirectUri = (serviceName: string, config: any, params: unknown, absoluteUrlOptions: unknown): string => { + const ret = _redirectUri(serviceName, config, params, absoluteUrlOptions); + + // DEPRECATED: Remove in v5.0.0 + // Meteor 2.3 removed ?close from redirect uri so we need to add it back to not break old oauth clients + // https://github.com/meteor/meteor/commit/b5b7306bedc3e8eb241e64efb1e281925aa75dd3#diff-59244f4e0176cb1beed2e287924e97dc7ae2c0cc51494ce121a85d8937d116a5L11 + if (!config?.loginStyle && !ret.includes('close')) { + return `${ret + (ret.includes('?') ? '&' : '?')}close`; + } + + return ret; +}; diff --git a/client/main.ts b/client/main.ts index e08f775af7dee..eae3b5ade5fae 100644 --- a/client/main.ts +++ b/client/main.ts @@ -1,6 +1,7 @@ import '../ee/client/ecdh'; import './polyfills'; +import './lib/oauthRedirectUri'; import './lib/meteorCallWrapper'; import './importPackages'; diff --git a/client/startup/oauth.ts b/client/startup/oauth.ts index 7be58ef055dfe..23f5ec8246b46 100644 --- a/client/startup/oauth.ts +++ b/client/startup/oauth.ts @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -// @ts-ignore #ToDo: Add definitions for meteor/oauth import { OAuth } from 'meteor/oauth'; // OAuth._retrieveCredentialSecret is a meteor method modified to also check the global localStorage @@ -8,7 +7,7 @@ import { OAuth } from 'meteor/oauth'; Meteor.startup(() => { const meteorOAuthRetrieveCredentialSecret = OAuth._retrieveCredentialSecret; - OAuth._retrieveCredentialSecret = (credentialToken: string): string | undefined => { + OAuth._retrieveCredentialSecret = (credentialToken: string): string | null => { let secret = meteorOAuthRetrieveCredentialSecret.call(OAuth, credentialToken); if (!secret) { const localStorageKey = `${OAuth._storageTokenPrefix}${credentialToken}`; diff --git a/definition/externals/meteor/oauth.d.ts b/definition/externals/meteor/oauth.d.ts new file mode 100644 index 0000000000000..67780bcbdb350 --- /dev/null +++ b/definition/externals/meteor/oauth.d.ts @@ -0,0 +1,7 @@ +declare module 'meteor/oauth' { + namespace OAuth { + function _redirectUri(serviceName: string, config: any, params: any, absoluteUrlOptions: any): string; + function _retrieveCredentialSecret(credentialToken: string): string | null; + const _storageTokenPrefix: string; + } +} From 949115a5edf11fa8e4e910e0f0ac6cf73a9506c2 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Thu, 3 Feb 2022 11:26:14 -0600 Subject: [PATCH 3/9] Chore: Unify ILivechatAgent with ILivechatAgentRecord (#24406) --- .../Omnichannel/hooks/useAgentsList.ts | 8 +++---- definition/ILivechatAgent.ts | 22 +++++++++++++------ definition/ILivechatAgentRecord.ts | 16 -------------- ee/client/hooks/useAgentsList.ts | 8 +++---- 4 files changed, 23 insertions(+), 31 deletions(-) delete mode 100644 definition/ILivechatAgentRecord.ts diff --git a/client/components/Omnichannel/hooks/useAgentsList.ts b/client/components/Omnichannel/hooks/useAgentsList.ts index d280aa5a0df34..9e5dafad23976 100644 --- a/client/components/Omnichannel/hooks/useAgentsList.ts +++ b/client/components/Omnichannel/hooks/useAgentsList.ts @@ -1,6 +1,6 @@ import { useCallback, useState } from 'react'; -import { ILivechatAgentRecord } from '../../../../definition/ILivechatAgentRecord'; +import { ILivechatAgent } from '../../../../definition/ILivechatAgent'; import { useEndpoint } from '../../../contexts/ServerContext'; import { useTranslation } from '../../../contexts/TranslationContext'; import { useScrollableRecordList } from '../../../hooks/lists/useScrollableRecordList'; @@ -15,14 +15,14 @@ type AgentsListOptions = { export const useAgentsList = ( options: AgentsListOptions, ): { - itemsList: RecordList; + itemsList: RecordList; initialItemCount: number; reload: () => void; loadMoreItems: (start: number, end: number) => void; } => { const t = useTranslation(); - const [itemsList, setItemsList] = useState(() => new RecordList()); - const reload = useCallback(() => setItemsList(new RecordList()), []); + const [itemsList, setItemsList] = useState(() => new RecordList()); + const reload = useCallback(() => setItemsList(new RecordList()), []); const endpoint = 'livechat/users/agent'; const getAgents = useEndpoint('GET', endpoint); diff --git a/definition/ILivechatAgent.ts b/definition/ILivechatAgent.ts index a6f6d24542601..f9ba0a4a33c26 100644 --- a/definition/ILivechatAgent.ts +++ b/definition/ILivechatAgent.ts @@ -1,8 +1,16 @@ -export interface ILivechatAgent { - _id: string; - emails: { adress: string; verified: boolean }; - status: string; - name: string; - username: string; - statusLivechat: string; +import { IUser } from './IUser'; + +export enum ILivechatAgentStatus { + AVAILABLE = 'available', + UNAVAILABLE = 'unavailable', +} + +export interface ILivechatAgent extends IUser { + statusLivechat: ILivechatAgentStatus; + livechat: { + maxNumberSimultaneousChat: number; + }; + livechatCount: number; + lastRoutingTime: Date; + livechatStatusSystemModified?: boolean; } diff --git a/definition/ILivechatAgentRecord.ts b/definition/ILivechatAgentRecord.ts deleted file mode 100644 index 897a2a90d878e..0000000000000 --- a/definition/ILivechatAgentRecord.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { IRocketChatRecord } from './IRocketChatRecord'; - -export interface ILivechatAgentRecord extends IRocketChatRecord { - _id: string; - emails: { - address: string; - verified: boolean; - }[]; - status: string; - name: string; - username: string; - statusLivechat: string; - livechat: { - maxNumberSimultaneousChat: number; - }; -} diff --git a/ee/client/hooks/useAgentsList.ts b/ee/client/hooks/useAgentsList.ts index 7a177f9e8747c..b120dc9489e7b 100644 --- a/ee/client/hooks/useAgentsList.ts +++ b/ee/client/hooks/useAgentsList.ts @@ -4,7 +4,7 @@ import { useEndpoint } from '../../../client/contexts/ServerContext'; import { useScrollableRecordList } from '../../../client/hooks/lists/useScrollableRecordList'; import { useComponentDidUpdate } from '../../../client/hooks/useComponentDidUpdate'; import { RecordList } from '../../../client/lib/lists/RecordList'; -import { ILivechatAgentRecord } from '../../../definition/ILivechatAgentRecord'; +import { ILivechatAgent } from '../../../definition/ILivechatAgent'; type AgentsListOptions = { filter: string; @@ -13,13 +13,13 @@ type AgentsListOptions = { export const useAgentsList = ( options: AgentsListOptions, ): { - itemsList: RecordList; + itemsList: RecordList; initialItemCount: number; reload: () => void; loadMoreItems: (start: number, end: number) => void; } => { - const [itemsList, setItemsList] = useState(() => new RecordList()); - const reload = useCallback(() => setItemsList(new RecordList()), []); + const [itemsList, setItemsList] = useState(() => new RecordList()); + const reload = useCallback(() => setItemsList(new RecordList()), []); const getAgents = useEndpoint('GET', 'livechat/users/agent'); From d254da574ad42a01d95679eeb61d67eaedd714df Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Thu, 3 Feb 2022 17:24:03 -0300 Subject: [PATCH 4/9] [FIX] Startup errors creating indexes (#24409) --- server/startup/migrations/index.ts | 1 + server/startup/migrations/v254.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 server/startup/migrations/v254.ts diff --git a/server/startup/migrations/index.ts b/server/startup/migrations/index.ts index 5be02fd851df6..f87385facdcda 100644 --- a/server/startup/migrations/index.ts +++ b/server/startup/migrations/index.ts @@ -77,4 +77,5 @@ import './v250'; import './v251'; import './v252'; import './v253'; +import './v254'; import './xrun'; diff --git a/server/startup/migrations/v254.ts b/server/startup/migrations/v254.ts new file mode 100644 index 0000000000000..c9abebd67ed47 --- /dev/null +++ b/server/startup/migrations/v254.ts @@ -0,0 +1,13 @@ +import { addMigration } from '../../lib/migrations'; +import { Users, Rooms } from '../../../app/models/server'; + +addMigration({ + version: 254, + up() { + Users.tryDropIndex({ bio: 1 }); + Users.tryEnsureIndex({ bio: 1 }, { unique: 1 }); + + Rooms.tryDropIndex({ prid: 1 }); + Rooms.tryEnsureIndex({ prid: 1 }, { sparse: true }); + }, +}); From 627d8880e8ce8a619de0bf2ab8fa164830faa18f Mon Sep 17 00:00:00 2001 From: Douglas Fabris Date: Thu, 3 Feb 2022 18:18:18 -0300 Subject: [PATCH 5/9] [IMPROVE] CloudLoginModal visual consistency (#24334) --- client/views/admin/apps/CloudLoginModal.tsx | 46 ++++++++------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/client/views/admin/apps/CloudLoginModal.tsx b/client/views/admin/apps/CloudLoginModal.tsx index d82f093f944f3..35a069e3a82d2 100644 --- a/client/views/admin/apps/CloudLoginModal.tsx +++ b/client/views/admin/apps/CloudLoginModal.tsx @@ -1,47 +1,35 @@ -import { Button, ButtonGroup, Icon, Modal } from '@rocket.chat/fuselage'; -import React from 'react'; +import React, { ReactElement } from 'react'; +import GenericModal from '../../../components/GenericModal'; import { useSetModal } from '../../../contexts/ModalContext'; import { useRoute } from '../../../contexts/RouterContext'; import { useTranslation } from '../../../contexts/TranslationContext'; -const CloudLoginModal = (): JSX.Element => { +const CloudLoginModal = (): ReactElement => { const t = useTranslation(); const setModal = useSetModal(); const cloudRoute = useRoute('cloud'); - const handleCloseButtonClick = (): void => { - setModal(null); + const handleCancel = (): void => { + setModal(undefined); }; - const handleCancelButtonClick = (): void => { - setModal(null); - }; - - const handleLoginButtonClick = (): void => { + const handleLogin = (): void => { cloudRoute.push(); - setModal(null); + setModal(undefined); }; return ( - - - - {t('Apps_Marketplace_Login_Required_Title')} - - - {t('Apps_Marketplace_Login_Required_Description')} - - - - - - - + + {t('Apps_Marketplace_Login_Required_Description')} + ); }; From 4e670154af23741c865c0be26e269e86fad26dcf Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 4 Feb 2022 13:51:38 -0300 Subject: [PATCH 6/9] [FIX] Outgoing webhook without scripts not saving messages (#24401) --- app/integrations/server/lib/triggerHandler.js | 150 +++++++++--------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/app/integrations/server/lib/triggerHandler.js b/app/integrations/server/lib/triggerHandler.js index a565fa0b4d945..8ba50fca9bd4a 100644 --- a/app/integrations/server/lib/triggerHandler.js +++ b/app/integrations/server/lib/triggerHandler.js @@ -841,91 +841,91 @@ export class RocketChatIntegrationHandler { this.updateHistory({ historyId, step: 'after-process-false-result', finished: true }); return; } + } - // if the result contained nothing or wasn't a successful statusCode - if (!content || !this.successResults.includes(res.status)) { - if (content) { - outgoingLogger.error({ - msg: `Error for the Integration "${trigger.name}" to ${url}`, - result: content, - }); + // if the result contained nothing or wasn't a successful statusCode + if (!content || !this.successResults.includes(res.status)) { + if (content) { + outgoingLogger.error({ + msg: `Error for the Integration "${trigger.name}" to ${url}`, + result: content, + }); - if (res.status === 410) { - this.updateHistory({ historyId, step: 'after-process-http-status-410', error: true }); - outgoingLogger.error(`Disabling the Integration "${trigger.name}" because the status code was 401 (Gone).`); - await Integrations.updateOne({ _id: trigger._id }, { $set: { enabled: false } }); - return; - } + if (res.status === 410) { + this.updateHistory({ historyId, step: 'after-process-http-status-410', error: true }); + outgoingLogger.error(`Disabling the Integration "${trigger.name}" because the status code was 401 (Gone).`); + await Integrations.updateOne({ _id: trigger._id }, { $set: { enabled: false } }); + return; + } - if (res.status === 500) { - this.updateHistory({ historyId, step: 'after-process-http-status-500', error: true }); - outgoingLogger.error({ - msg: `Error "500" for the Integration "${trigger.name}" to ${url}.`, - content, - }); - return; - } + if (res.status === 500) { + this.updateHistory({ historyId, step: 'after-process-http-status-500', error: true }); + outgoingLogger.error({ + msg: `Error "500" for the Integration "${trigger.name}" to ${url}.`, + content, + }); + return; } + } - if (trigger.retryFailedCalls) { - if (tries < trigger.retryCount && trigger.retryDelay) { - this.updateHistory({ historyId, error: true, step: `going-to-retry-${tries + 1}` }); - - let waitTime; - - switch (trigger.retryDelay) { - case 'powers-of-ten': - // Try again in 0.1s, 1s, 10s, 1m40s, 16m40s, 2h46m40s, 27h46m40s, etc - waitTime = Math.pow(10, tries + 2); - break; - case 'powers-of-two': - // 2 seconds, 4 seconds, 8 seconds - waitTime = Math.pow(2, tries + 1) * 1000; - break; - case 'increments-of-two': - // 2 second, 4 seconds, 6 seconds, etc - waitTime = (tries + 1) * 2 * 1000; - break; - default: - const er = new Error("The integration's retryDelay setting is invalid."); - this.updateHistory({ - historyId, - step: 'failed-and-retry-delay-is-invalid', - error: true, - errorStack: er.stack, - }); - return; - } - - outgoingLogger.info(`Trying the Integration ${trigger.name} to ${url} again in ${waitTime} milliseconds.`); - Meteor.setTimeout(() => { - this.executeTriggerUrl(url, trigger, { event, message, room, owner, user }, historyId, tries + 1); - }, waitTime); - } else { - this.updateHistory({ historyId, step: 'too-many-retries', error: true }); + if (trigger.retryFailedCalls) { + if (tries < trigger.retryCount && trigger.retryDelay) { + this.updateHistory({ historyId, error: true, step: `going-to-retry-${tries + 1}` }); + + let waitTime; + + switch (trigger.retryDelay) { + case 'powers-of-ten': + // Try again in 0.1s, 1s, 10s, 1m40s, 16m40s, 2h46m40s, 27h46m40s, etc + waitTime = Math.pow(10, tries + 2); + break; + case 'powers-of-two': + // 2 seconds, 4 seconds, 8 seconds + waitTime = Math.pow(2, tries + 1) * 1000; + break; + case 'increments-of-two': + // 2 second, 4 seconds, 6 seconds, etc + waitTime = (tries + 1) * 2 * 1000; + break; + default: + const er = new Error("The integration's retryDelay setting is invalid."); + this.updateHistory({ + historyId, + step: 'failed-and-retry-delay-is-invalid', + error: true, + errorStack: er.stack, + }); + return; } + + outgoingLogger.info(`Trying the Integration ${trigger.name} to ${url} again in ${waitTime} milliseconds.`); + Meteor.setTimeout(() => { + this.executeTriggerUrl(url, trigger, { event, message, room, owner, user }, historyId, tries + 1); + }, waitTime); } else { - this.updateHistory({ - historyId, - step: 'failed-and-not-configured-to-retry', - error: true, - }); + this.updateHistory({ historyId, step: 'too-many-retries', error: true }); } - - return; + } else { + this.updateHistory({ + historyId, + step: 'failed-and-not-configured-to-retry', + error: true, + }); } - // process outgoing webhook response as a new message - if (content && this.successResults.includes(res.status)) { - if (data?.text || data?.attachments) { - const resultMsg = this.sendMessage({ trigger, room, message: data, data }); - this.updateHistory({ - historyId, - step: 'url-response-sent-message', - resultMessage: resultMsg, - finished: true, - }); - } + return; + } + + // process outgoing webhook response as a new message + if (content && this.successResults.includes(res.status)) { + if (data?.text || data?.attachments) { + const resultMsg = this.sendMessage({ trigger, room, message: data, data }); + this.updateHistory({ + historyId, + step: 'url-response-sent-message', + resultMessage: resultMsg, + finished: true, + }); } } }) From 919d5d5fd9cfefd86f5965e34d58fad910f5f4c3 Mon Sep 17 00:00:00 2001 From: Lucas Souza <32396925+LucasFASouza@users.noreply.github.com> Date: Fri, 4 Feb 2022 15:13:29 -0300 Subject: [PATCH 7/9] [IMPROVE] Convert tag edit with department data to tsx (#24369) --- definition/rest/v1/omnichannel.ts | 5 +++++ ee/client/audit/Result.js | 2 ++ ee/client/omnichannel/tags/TagEdit.js | 2 +- ee/client/omnichannel/tags/TagEditWithData.js | 6 +++--- ...mentData.js => TagEditWithDepartmentData.tsx} | 16 ++++++++++++---- 5 files changed, 23 insertions(+), 8 deletions(-) rename ee/client/omnichannel/tags/{TagEditWithDepartmentData.js => TagEditWithDepartmentData.tsx} (60%) diff --git a/definition/rest/v1/omnichannel.ts b/definition/rest/v1/omnichannel.ts index 07d14ae8a71ae..075c531820bcc 100644 --- a/definition/rest/v1/omnichannel.ts +++ b/definition/rest/v1/omnichannel.ts @@ -92,6 +92,11 @@ export type OmnichannelEndpoints = { departments: ILivechatDepartment[]; }>; }; + + 'livechat/department.listByIds': { + GET: (params: { ids: string[]; fields?: Record }) => { departments: ILivechatDepartment[] }; + }; + 'livechat/custom-fields': { GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ customFields: [ diff --git a/ee/client/audit/Result.js b/ee/client/audit/Result.js index 36d2a15906223..a71a27a4f55d7 100644 --- a/ee/client/audit/Result.js +++ b/ee/client/audit/Result.js @@ -39,4 +39,6 @@ const Result = memo(({ setDataRef }) => { return ; }); +Result.displayName = 'Result'; + export default Result; diff --git a/ee/client/omnichannel/tags/TagEdit.js b/ee/client/omnichannel/tags/TagEdit.js index 48f900be01711..d8e7f50bd8b6a 100644 --- a/ee/client/omnichannel/tags/TagEdit.js +++ b/ee/client/omnichannel/tags/TagEdit.js @@ -10,7 +10,7 @@ import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessag import { useTranslation } from '../../../../client/contexts/TranslationContext'; import { useForm } from '../../../../client/hooks/useForm'; -function TagEdit({ title, data, tagId, isNew, reload, currentDepartments, ...props }) { +function TagEdit({ title, data, tagId, reload, currentDepartments, ...props }) { const t = useTranslation(); const tagsRoute = useRoute('omnichannel-tags'); diff --git a/ee/client/omnichannel/tags/TagEditWithData.js b/ee/client/omnichannel/tags/TagEditWithData.js index edcf266e86ffa..516ba2f7265b8 100644 --- a/ee/client/omnichannel/tags/TagEditWithData.js +++ b/ee/client/omnichannel/tags/TagEditWithData.js @@ -8,7 +8,7 @@ import { useEndpointData } from '../../../../client/hooks/useEndpointData'; import TagEdit from './TagEdit'; import TagEditWithDepartmentData from './TagEditWithDepartmentData'; -function TagEditWithData({ tagId, reload }) { +function TagEditWithData({ tagId, reload, title }) { const query = useMemo(() => ({ tagId }), [tagId]); const { value: data, phase: state, error } = useEndpointData('livechat/tags.getOne', query); @@ -29,9 +29,9 @@ function TagEditWithData({ tagId, reload }) { return ( <> {data && data.departments && data.departments.length > 0 ? ( - + ) : ( - + )} ); diff --git a/ee/client/omnichannel/tags/TagEditWithDepartmentData.js b/ee/client/omnichannel/tags/TagEditWithDepartmentData.tsx similarity index 60% rename from ee/client/omnichannel/tags/TagEditWithDepartmentData.js rename to ee/client/omnichannel/tags/TagEditWithDepartmentData.tsx index a4d5731ace58b..138f6a986c839 100644 --- a/ee/client/omnichannel/tags/TagEditWithDepartmentData.js +++ b/ee/client/omnichannel/tags/TagEditWithDepartmentData.tsx @@ -1,13 +1,21 @@ import { Callout } from '@rocket.chat/fuselage'; -import React, { useMemo } from 'react'; +import React, { ReactElement, useMemo, ReactNode } from 'react'; import { FormSkeleton } from '../../../../client/components/Skeleton'; import { useTranslation } from '../../../../client/contexts/TranslationContext'; import { AsyncStatePhase } from '../../../../client/hooks/useAsyncState'; import { useEndpointData } from '../../../../client/hooks/useEndpointData'; +import { ILivechatTag } from '../../../../definition/ILivechatTag'; import TagEdit from './TagEdit'; -function TagEditWithDepartmentData({ data, ...props }) { +type TagEditWithDepartmentDataPropsType = { + data: ILivechatTag; + title: ReactNode; + tagId: ILivechatTag['_id']; + reload: () => void; +}; + +function TagEditWithDepartmentData({ data, title, ...props }: TagEditWithDepartmentDataPropsType): ReactElement { const t = useTranslation(); const { @@ -16,7 +24,7 @@ function TagEditWithDepartmentData({ data, ...props }) { error: currentDepartmentsError, } = useEndpointData( 'livechat/department.listByIds', - useMemo(() => ({ ids: data && data.departments ? data.departments : [] }), [data]), + useMemo(() => ({ ids: data?.departments ? data.departments : [] }), [data]), ); if ([currentDepartmentsState].includes(AsyncStatePhase.LOADING)) { @@ -31,7 +39,7 @@ function TagEditWithDepartmentData({ data, ...props }) { ); } - return ; + return ; } export default TagEditWithDepartmentData; From 17346d0556ad4fdfb8d3f9f66b84000f772d0203 Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Fri, 4 Feb 2022 16:28:05 -0300 Subject: [PATCH 8/9] Chore: Convert JS files to Typescript (#24410) Co-authored-by: Guilherme Gazzo --- .../{addOAuthService.js => addOAuthService.ts} | 2 +- .../methods/{addUserToRoom.js => addUserToRoom.ts} | 0 .../methods/{archiveRoom.js => archiveRoom.ts} | 4 ++-- .../server/methods/{blockUser.js => blockUser.ts} | 3 +-- ...nSecretURL.js => checkRegistrationSecretURL.ts} | 2 +- ...vailability.js => checkUsernameAvailability.ts} | 6 +++--- .../methods/{createChannel.js => createChannel.ts} | 4 ++-- .../methods/{createToken.js => createToken.ts} | 4 ++-- .../methods/{deleteMessage.js => deleteMessage.ts} | 5 +++-- ...teUserOwnAccount.js => deleteUserOwnAccount.ts} | 4 ++-- ...andPreview.js => executeSlashCommandPreview.ts} | 2 +- .../{getChannelHistory.js => getChannelHistory.ts} | 4 ++-- .../methods/{getMessages.js => getMessages.ts} | 11 +++++++++-- .../{getRoomJoinCode.js => getRoomJoinCode.ts} | 6 +++--- .../methods/{getRoomRoles.js => getRoomRoles.ts} | 2 +- .../{getSingleMessage.js => getSingleMessage.ts} | 8 +++++++- ...mmandPreviews.js => getSlashCommandPreviews.ts} | 2 +- ...inDefaultChannels.js => joinDefaultChannels.ts} | 0 .../server/methods/{joinRoom.js => joinRoom.ts} | 14 ++++++++------ .../methods/{restartServer.js => restartServer.ts} | 9 ++++++--- .../{setAdminStatus.js => setAdminStatus.ts} | 12 +++++++----- .../server/methods/{setEmail.js => setEmail.ts} | 8 ++++---- .../methods/{setRealName.js => setRealName.ts} | 2 +- .../methods/{setUsername.js => setUsername.ts} | 12 ++++++------ .../methods/{unarchiveRoom.js => unarchiveRoom.ts} | 4 ++-- .../methods/{unblockUser.js => unblockUser.ts} | 2 +- app/utils/lib/slashCommand.d.ts | 2 +- definition/externals/meteor/accounts-base.d.ts | 2 ++ 28 files changed, 79 insertions(+), 57 deletions(-) rename app/lib/server/methods/{addOAuthService.js => addOAuthService.ts} (90%) rename app/lib/server/methods/{addUserToRoom.js => addUserToRoom.ts} (100%) rename app/lib/server/methods/{archiveRoom.js => archiveRoom.ts} (89%) rename app/lib/server/methods/{blockUser.js => blockUser.ts} (91%) rename app/lib/server/methods/{checkRegistrationSecretURL.js => checkRegistrationSecretURL.ts} (81%) rename app/lib/server/methods/{checkUsernameAvailability.js => checkUsernameAvailability.ts} (80%) rename app/lib/server/methods/{createChannel.js => createChannel.ts} (79%) rename app/lib/server/methods/{createToken.js => createToken.ts} (78%) rename app/lib/server/methods/{deleteMessage.js => deleteMessage.ts} (83%) rename app/lib/server/methods/{deleteUserOwnAccount.js => deleteUserOwnAccount.ts} (93%) rename app/lib/server/methods/{executeSlashCommandPreview.js => executeSlashCommandPreview.ts} (94%) rename app/lib/server/methods/{getChannelHistory.js => getChannelHistory.ts} (96%) rename app/lib/server/methods/{getMessages.js => getMessages.ts} (62%) rename app/lib/server/methods/{getRoomJoinCode.js => getRoomJoinCode.ts} (77%) rename app/lib/server/methods/{getRoomRoles.js => getRoomRoles.ts} (89%) rename app/lib/server/methods/{getSingleMessage.js => getSingleMessage.ts} (70%) rename app/lib/server/methods/{getSlashCommandPreviews.js => getSlashCommandPreviews.ts} (93%) rename app/lib/server/methods/{joinDefaultChannels.js => joinDefaultChannels.ts} (100%) rename app/lib/server/methods/{joinRoom.js => joinRoom.ts} (89%) rename app/lib/server/methods/{restartServer.js => restartServer.ts} (73%) rename app/lib/server/methods/{setAdminStatus.js => setAdminStatus.ts} (76%) rename app/lib/server/methods/{setEmail.js => setEmail.ts} (92%) rename app/lib/server/methods/{setRealName.js => setRealName.ts} (93%) rename app/lib/server/methods/{setUsername.js => setUsername.ts} (92%) rename app/lib/server/methods/{unarchiveRoom.js => unarchiveRoom.ts} (85%) rename app/lib/server/methods/{unblockUser.js => unblockUser.ts} (92%) diff --git a/app/lib/server/methods/addOAuthService.js b/app/lib/server/methods/addOAuthService.ts similarity index 90% rename from app/lib/server/methods/addOAuthService.js rename to app/lib/server/methods/addOAuthService.ts index 36a4ba555ec26..57ce8265fc3a2 100644 --- a/app/lib/server/methods/addOAuthService.js +++ b/app/lib/server/methods/addOAuthService.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; import { addOAuthService } from '../functions/addOAuthService'; Meteor.methods({ diff --git a/app/lib/server/methods/addUserToRoom.js b/app/lib/server/methods/addUserToRoom.ts similarity index 100% rename from app/lib/server/methods/addUserToRoom.js rename to app/lib/server/methods/addUserToRoom.ts diff --git a/app/lib/server/methods/archiveRoom.js b/app/lib/server/methods/archiveRoom.ts similarity index 89% rename from app/lib/server/methods/archiveRoom.js rename to app/lib/server/methods/archiveRoom.ts index 4f101615b8416..7f55af28122b5 100644 --- a/app/lib/server/methods/archiveRoom.js +++ b/app/lib/server/methods/archiveRoom.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { Rooms } from '../../../models'; -import { hasPermission } from '../../../authorization'; +import { Rooms } from '../../../models/server'; +import { hasPermission } from '../../../authorization/server'; import { archiveRoom } from '../functions'; import { roomTypes, RoomMemberActions } from '../../../utils/server'; diff --git a/app/lib/server/methods/blockUser.js b/app/lib/server/methods/blockUser.ts similarity index 91% rename from app/lib/server/methods/blockUser.js rename to app/lib/server/methods/blockUser.ts index f9e4bb4c54d22..7ca223e4ad00b 100644 --- a/app/lib/server/methods/blockUser.js +++ b/app/lib/server/methods/blockUser.ts @@ -1,9 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { Subscriptions } from '../../../models'; import { roomTypes, RoomMemberActions } from '../../../utils/server'; -import { Rooms } from '../../../models/server'; +import { Rooms, Subscriptions } from '../../../models/server'; Meteor.methods({ blockUser({ rid, blocked }) { diff --git a/app/lib/server/methods/checkRegistrationSecretURL.js b/app/lib/server/methods/checkRegistrationSecretURL.ts similarity index 81% rename from app/lib/server/methods/checkRegistrationSecretURL.js rename to app/lib/server/methods/checkRegistrationSecretURL.ts index ab411be95d1a5..11a1d4ea42007 100644 --- a/app/lib/server/methods/checkRegistrationSecretURL.js +++ b/app/lib/server/methods/checkRegistrationSecretURL.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; Meteor.methods({ checkRegistrationSecretURL(hash) { diff --git a/app/lib/server/methods/checkUsernameAvailability.js b/app/lib/server/methods/checkUsernameAvailability.ts similarity index 80% rename from app/lib/server/methods/checkUsernameAvailability.js rename to app/lib/server/methods/checkUsernameAvailability.ts index 7bf9b7f9acdbd..2a9f34780f2a1 100644 --- a/app/lib/server/methods/checkUsernameAvailability.js +++ b/app/lib/server/methods/checkUsernameAvailability.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { checkUsernameAvailability } from '../functions'; import { RateLimiter } from '../lib'; @@ -15,11 +15,11 @@ Meteor.methods({ const user = Meteor.user(); - if (user.username && !settings.get('Accounts_AllowUsernameChange')) { + if (user?.username && !settings.get('Accounts_AllowUsernameChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUsername' }); } - if (user.username === username) { + if (user?.username === username) { return true; } return checkUsernameAvailability(username); diff --git a/app/lib/server/methods/createChannel.js b/app/lib/server/methods/createChannel.ts similarity index 79% rename from app/lib/server/methods/createChannel.js rename to app/lib/server/methods/createChannel.ts index 0201e985e74f7..364d31200d21c 100644 --- a/app/lib/server/methods/createChannel.js +++ b/app/lib/server/methods/createChannel.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; import { createRoom } from '../functions'; Meteor.methods({ @@ -16,7 +16,7 @@ Meteor.methods({ if (!hasPermission(Meteor.userId(), 'create-c')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'createChannel' }); } - return createRoom('c', name, Meteor.user() && Meteor.user().username, members, readOnly, { + return createRoom('c', name, Meteor.user() && Meteor.user()?.username, members, readOnly, { customFields, ...extraData, }); diff --git a/app/lib/server/methods/createToken.js b/app/lib/server/methods/createToken.ts similarity index 78% rename from app/lib/server/methods/createToken.js rename to app/lib/server/methods/createToken.ts index 47713c0fc44ee..d05df8d95562f 100644 --- a/app/lib/server/methods/createToken.js +++ b/app/lib/server/methods/createToken.ts @@ -1,12 +1,12 @@ import { Meteor } from 'meteor/meteor'; import { Accounts } from 'meteor/accounts-base'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; Meteor.methods({ createToken(userId) { if ( - !['yes', 'true'].includes(process.env.CREATE_TOKENS_FOR_USERS) || + !['yes', 'true'].includes(String(process.env.CREATE_TOKENS_FOR_USERS)) || (Meteor.userId() !== userId && !hasPermission(Meteor.userId(), 'user-generate-access-token')) ) { throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'createToken' }); diff --git a/app/lib/server/methods/deleteMessage.js b/app/lib/server/methods/deleteMessage.ts similarity index 83% rename from app/lib/server/methods/deleteMessage.js rename to app/lib/server/methods/deleteMessage.ts index 47d54f4e940e3..d8c1b97034dbc 100644 --- a/app/lib/server/methods/deleteMessage.js +++ b/app/lib/server/methods/deleteMessage.ts @@ -2,8 +2,9 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { canDeleteMessage } from '../../../authorization/server/functions/canDeleteMessage'; -import { Messages } from '../../../models'; +import { Messages } from '../../../models/server'; import { deleteMessage } from '../functions'; +import { IUser } from '../../../../definition/IUser'; Meteor.methods({ async deleteMessage(message) { @@ -38,6 +39,6 @@ Meteor.methods({ }); } - return deleteMessage(originalMessage, Meteor.user()); + return deleteMessage(originalMessage, Meteor.user() as IUser); }, }); diff --git a/app/lib/server/methods/deleteUserOwnAccount.js b/app/lib/server/methods/deleteUserOwnAccount.ts similarity index 93% rename from app/lib/server/methods/deleteUserOwnAccount.js rename to app/lib/server/methods/deleteUserOwnAccount.ts index f6dda0888febd..2ce0a3df79fa3 100644 --- a/app/lib/server/methods/deleteUserOwnAccount.js +++ b/app/lib/server/methods/deleteUserOwnAccount.ts @@ -4,8 +4,8 @@ import { Accounts } from 'meteor/accounts-base'; import { SHA256 } from 'meteor/sha'; import s from 'underscore.string'; -import { settings } from '../../../settings'; -import { Users } from '../../../models'; +import { settings } from '../../../settings/server'; +import { Users } from '../../../models/server'; import { deleteUser } from '../functions'; Meteor.methods({ diff --git a/app/lib/server/methods/executeSlashCommandPreview.js b/app/lib/server/methods/executeSlashCommandPreview.ts similarity index 94% rename from app/lib/server/methods/executeSlashCommandPreview.js rename to app/lib/server/methods/executeSlashCommandPreview.ts index 52f2c18527a5c..8df013402607a 100644 --- a/app/lib/server/methods/executeSlashCommandPreview.js +++ b/app/lib/server/methods/executeSlashCommandPreview.ts @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { slashCommands } from '../../../utils'; +import { slashCommands } from '../../../utils/server'; Meteor.methods({ executeSlashCommandPreview(command, preview) { diff --git a/app/lib/server/methods/getChannelHistory.js b/app/lib/server/methods/getChannelHistory.ts similarity index 96% rename from app/lib/server/methods/getChannelHistory.js rename to app/lib/server/methods/getChannelHistory.ts index d39499a845245..939889eff2fea 100644 --- a/app/lib/server/methods/getChannelHistory.js +++ b/app/lib/server/methods/getChannelHistory.ts @@ -16,7 +16,7 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelHistory' }); } - const fromUserId = Meteor.userId(); + const fromUserId = Meteor.userId() || undefined; const room = Rooms.findOneById(rid); if (!room) { return false; @@ -47,7 +47,7 @@ Meteor.methods({ const hiddenMessageTypes = getHiddenSystemMessages(room); - const options = { + const options: Record = { sort: { ts: -1, }, diff --git a/app/lib/server/methods/getMessages.js b/app/lib/server/methods/getMessages.ts similarity index 62% rename from app/lib/server/methods/getMessages.js rename to app/lib/server/methods/getMessages.ts index f8ccbbbb6f740..57b5d50483fb6 100644 --- a/app/lib/server/methods/getMessages.js +++ b/app/lib/server/methods/getMessages.ts @@ -3,16 +3,23 @@ import { check } from 'meteor/check'; import { canAccessRoom } from '../../../authorization/server'; import { Messages } from '../../../models/server'; +import { IMessage } from '../../../../definition/IMessage'; Meteor.methods({ getMessages(messages) { check(messages, [String]); + const uid = Meteor.userId(); - const msgs = Messages.findVisibleByIds(messages).fetch(); + if (!uid) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getMessages' }); + } + + const msgs = Messages.findVisibleByIds(messages).fetch() as IMessage[]; - const user = { _id: Meteor.userId() }; + const user = { _id: uid }; const rids = [...new Set(msgs.map((m) => m.rid))]; + if (!rids.every((_id) => canAccessRoom({ _id }, user))) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); } diff --git a/app/lib/server/methods/getRoomJoinCode.js b/app/lib/server/methods/getRoomJoinCode.ts similarity index 77% rename from app/lib/server/methods/getRoomJoinCode.js rename to app/lib/server/methods/getRoomJoinCode.ts index da58b6b86e834..0776787a0a285 100644 --- a/app/lib/server/methods/getRoomJoinCode.js +++ b/app/lib/server/methods/getRoomJoinCode.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; -import { Rooms } from '../../../models'; +import { hasPermission } from '../../../authorization/server'; +import { Rooms } from '../../../models/server'; Meteor.methods({ getRoomJoinCode(rid) { @@ -18,6 +18,6 @@ Meteor.methods({ const [room] = Rooms.findById(rid).fetch(); - return room && room.joinCode; + return room?.joinCode; }, }); diff --git a/app/lib/server/methods/getRoomRoles.js b/app/lib/server/methods/getRoomRoles.ts similarity index 89% rename from app/lib/server/methods/getRoomRoles.js rename to app/lib/server/methods/getRoomRoles.ts index 33b6ef34edad3..5b20c92849236 100644 --- a/app/lib/server/methods/getRoomRoles.js +++ b/app/lib/server/methods/getRoomRoles.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { getRoomRoles } from '../lib/getRoomRoles'; Meteor.methods({ diff --git a/app/lib/server/methods/getSingleMessage.js b/app/lib/server/methods/getSingleMessage.ts similarity index 70% rename from app/lib/server/methods/getSingleMessage.js rename to app/lib/server/methods/getSingleMessage.ts index 604ac2f1b4f70..ff5457a06657a 100644 --- a/app/lib/server/methods/getSingleMessage.js +++ b/app/lib/server/methods/getSingleMessage.ts @@ -8,13 +8,19 @@ Meteor.methods({ getSingleMessage(msgId) { check(msgId, String); + const uid = Meteor.userId(); + + if (!uid) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getSingleMessage' }); + } + const msg = Messages.findOneById(msgId); if (!msg || !msg.rid) { return undefined; } - if (!canAccessRoom({ _id: msg.rid }, { _id: Meteor.userId() })) { + if (!canAccessRoom({ _id: msg.rid }, { _id: uid })) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' }); } diff --git a/app/lib/server/methods/getSlashCommandPreviews.js b/app/lib/server/methods/getSlashCommandPreviews.ts similarity index 93% rename from app/lib/server/methods/getSlashCommandPreviews.js rename to app/lib/server/methods/getSlashCommandPreviews.ts index a643593217354..2d8b7ce179b5f 100644 --- a/app/lib/server/methods/getSlashCommandPreviews.js +++ b/app/lib/server/methods/getSlashCommandPreviews.ts @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { slashCommands } from '../../../utils'; +import { slashCommands } from '../../../utils/server'; Meteor.methods({ getSlashCommandPreviews(command) { diff --git a/app/lib/server/methods/joinDefaultChannels.js b/app/lib/server/methods/joinDefaultChannels.ts similarity index 100% rename from app/lib/server/methods/joinDefaultChannels.js rename to app/lib/server/methods/joinDefaultChannels.ts diff --git a/app/lib/server/methods/joinRoom.js b/app/lib/server/methods/joinRoom.ts similarity index 89% rename from app/lib/server/methods/joinRoom.js rename to app/lib/server/methods/joinRoom.ts index 9460f68cf6729..c4de0456dd393 100644 --- a/app/lib/server/methods/joinRoom.js +++ b/app/lib/server/methods/joinRoom.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission, canAccessRoom } from '../../../authorization'; -import { Rooms } from '../../../models'; +import { hasPermission, canAccessRoom } from '../../../authorization/server'; +import { Rooms } from '../../../models/server'; import { Tokenpass, updateUserTokenpassBalances } from '../../../tokenpass/server'; import { addUserToRoom } from '../functions'; import { roomTypes, RoomMemberActions } from '../../../utils/server'; @@ -11,7 +11,9 @@ Meteor.methods({ joinRoom(rid, code) { check(rid, String); - if (!Meteor.userId()) { + const user = Meteor.user(); + + if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'joinRoom' }); } @@ -26,7 +28,7 @@ Meteor.methods({ } // TODO we should have a 'beforeJoinRoom' call back so external services can do their own validations - const user = Meteor.user(); + if (room.tokenpass && user && user.services && user.services.tokenpass) { const balances = updateUserTokenpassBalances(user); @@ -34,10 +36,10 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Token required', { method: 'joinRoom' }); } } else { - if (!canAccessRoom(room, Meteor.user())) { + if (!canAccessRoom(room, user)) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'joinRoom' }); } - if (room.joinCodeRequired === true && code !== room.joinCode && !hasPermission(Meteor.userId(), 'join-without-join-code')) { + if (room.joinCodeRequired === true && code !== room.joinCode && !hasPermission(user._id, 'join-without-join-code')) { throw new Meteor.Error('error-code-invalid', 'Invalid Room Password', { method: 'joinRoom', }); diff --git a/app/lib/server/methods/restartServer.js b/app/lib/server/methods/restartServer.ts similarity index 73% rename from app/lib/server/methods/restartServer.js rename to app/lib/server/methods/restartServer.ts index d694b833f746f..c530ee1b7afa2 100644 --- a/app/lib/server/methods/restartServer.js +++ b/app/lib/server/methods/restartServer.ts @@ -1,14 +1,17 @@ import { Meteor } from 'meteor/meteor'; -import { hasRole } from '../../../authorization'; +import { hasRole } from '../../../authorization/server'; Meteor.methods({ + // eslint-disable-next-line @typescript-eslint/camelcase restart_server() { - if (!Meteor.userId()) { + const uid = Meteor.userId(); + + if (!uid) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'restart_server' }); } - if (hasRole(Meteor.userId(), 'admin') !== true) { + if (hasRole(uid, 'admin') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'restart_server' }); } diff --git a/app/lib/server/methods/setAdminStatus.js b/app/lib/server/methods/setAdminStatus.ts similarity index 76% rename from app/lib/server/methods/setAdminStatus.js rename to app/lib/server/methods/setAdminStatus.ts index 9ea6d5259d315..2f416fe8e6d77 100644 --- a/app/lib/server/methods/setAdminStatus.js +++ b/app/lib/server/methods/setAdminStatus.ts @@ -1,26 +1,28 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; +import { hasPermission } from '../../../authorization/server'; Meteor.methods({ setAdminStatus(userId, admin) { check(userId, String); check(admin, Match.Optional(Boolean)); - if (!Meteor.userId()) { + const uid = Meteor.userId(); + + if (!uid) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setAdminStatus' }); } - if (hasPermission(Meteor.userId(), 'assign-admin-role') !== true) { + if (hasPermission(uid, 'assign-admin-role') !== true) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setAdminStatus' }); } const user = Meteor.users.findOne({ _id: userId }, { fields: { username: 1 } }); if (admin) { - return Meteor.call('authorization:addUserToRole', 'admin', user.username); + return Meteor.call('authorization:addUserToRole', 'admin', user?.username); } - return Meteor.call('authorization:removeUserFromRole', 'admin', user.username); + return Meteor.call('authorization:removeUserFromRole', 'admin', user?.username); }, }); diff --git a/app/lib/server/methods/setEmail.js b/app/lib/server/methods/setEmail.ts similarity index 92% rename from app/lib/server/methods/setEmail.js rename to app/lib/server/methods/setEmail.ts index 027e6418145c1..682f936defc7f 100644 --- a/app/lib/server/methods/setEmail.js +++ b/app/lib/server/methods/setEmail.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { setEmail } from '../functions'; import { RateLimiter } from '../lib'; @@ -9,12 +9,12 @@ Meteor.methods({ setEmail(email) { check(email, String); - if (!Meteor.userId()) { + const user = Meteor.user(); + + if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setEmail' }); } - const user = Meteor.user(); - if (!settings.get('Accounts_AllowEmailChange')) { throw new Meteor.Error('error-action-not-allowed', 'Changing email is not allowed', { method: 'setEmail', diff --git a/app/lib/server/methods/setRealName.js b/app/lib/server/methods/setRealName.ts similarity index 93% rename from app/lib/server/methods/setRealName.js rename to app/lib/server/methods/setRealName.ts index 5f8301667a344..0ebc9ebb76bf8 100644 --- a/app/lib/server/methods/setRealName.js +++ b/app/lib/server/methods/setRealName.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { settings } from '../../../settings'; +import { settings } from '../../../settings/server'; import { setRealName } from '../functions'; import { RateLimiter } from '../lib'; diff --git a/app/lib/server/methods/setUsername.js b/app/lib/server/methods/setUsername.ts similarity index 92% rename from app/lib/server/methods/setUsername.js rename to app/lib/server/methods/setUsername.ts index 91e1d60d6d86c..83ffee0bf2f96 100644 --- a/app/lib/server/methods/setUsername.js +++ b/app/lib/server/methods/setUsername.ts @@ -2,8 +2,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import _ from 'underscore'; -import { settings } from '../../../settings'; -import { Users } from '../../../models'; +import { settings } from '../../../settings/server'; +import { Users } from '../../../models/server'; import { callbacks } from '../../../../lib/callbacks'; import { checkUsernameAvailability } from '../functions'; import { RateLimiter } from '../lib'; @@ -14,12 +14,12 @@ Meteor.methods({ const { joinDefaultChannelsSilenced } = param; check(username, String); - if (!Meteor.userId()) { + const user = Meteor.user(); + + if (!user) { throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUsername' }); } - const user = Meteor.user(); - if (user.username && !settings.get('Accounts_AllowUsernameChange')) { throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUsername' }); } @@ -49,7 +49,7 @@ Meteor.methods({ }); } - if (!saveUserIdentity({ _id: user._id, username })) { + if (!saveUserIdentity({ _id: user?._id, username })) { throw new Meteor.Error('error-could-not-change-username', 'Could not change username', { method: 'setUsername', }); diff --git a/app/lib/server/methods/unarchiveRoom.js b/app/lib/server/methods/unarchiveRoom.ts similarity index 85% rename from app/lib/server/methods/unarchiveRoom.js rename to app/lib/server/methods/unarchiveRoom.ts index e584ce1044d3c..f0313b7a24cc5 100644 --- a/app/lib/server/methods/unarchiveRoom.js +++ b/app/lib/server/methods/unarchiveRoom.ts @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { hasPermission } from '../../../authorization'; -import { Rooms } from '../../../models'; +import { hasPermission } from '../../../authorization/server'; +import { Rooms } from '../../../models/server'; import { unarchiveRoom } from '../functions'; Meteor.methods({ diff --git a/app/lib/server/methods/unblockUser.js b/app/lib/server/methods/unblockUser.ts similarity index 92% rename from app/lib/server/methods/unblockUser.js rename to app/lib/server/methods/unblockUser.ts index 3b3522feebd89..4a4650e6fd40c 100644 --- a/app/lib/server/methods/unblockUser.js +++ b/app/lib/server/methods/unblockUser.ts @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { Subscriptions } from '../../../models'; +import { Subscriptions } from '../../../models/server'; Meteor.methods({ unblockUser({ rid, blocked }) { diff --git a/app/utils/lib/slashCommand.d.ts b/app/utils/lib/slashCommand.d.ts index 43c9bbb11cde8..a21676baaf98f 100644 --- a/app/utils/lib/slashCommand.d.ts +++ b/app/utils/lib/slashCommand.d.ts @@ -10,6 +10,6 @@ export declare const slashCommands: { previewCallback: Function | undefined, ): void; run(command: string, params: string, message: object, triggerId: string | undefined): Function | void; - getPreviews(command: string, params: string, message: object, preview: unknown, triggerId: string | undefined): Function | void; + getPreviews(command: string, params: string, message: object, preview?: unknown, triggerId?: string | undefined): Function | void; executePreview(command: string, params: string, message: object, preview: unknown, triggerId: string | undefined): Function | void; }; diff --git a/definition/externals/meteor/accounts-base.d.ts b/definition/externals/meteor/accounts-base.d.ts index 885d0ba385730..8f625c007331e 100644 --- a/definition/externals/meteor/accounts-base.d.ts +++ b/definition/externals/meteor/accounts-base.d.ts @@ -8,6 +8,8 @@ declare module 'meteor/accounts-base' { function _generateStampedLoginToken(): { token: string; when: Date }; + function _insertLoginToken(userId: string, token: { token: string; when: Date }): void; + function _runLoginHandlers(methodInvocation: Function, loginRequest: Record): Record | undefined; export class ConfigError extends Error {} From e990444c9567c5a2690bf7bd87cbabd390595a62 Mon Sep 17 00:00:00 2001 From: Douglas Fabris Date: Sat, 5 Feb 2022 00:53:31 -0300 Subject: [PATCH 9/9] [FIX] Skip cloud steps for registered servers on setup wizard (#24407) --- app/ui-login/client/login/form.html | 2 +- app/ui-login/client/login/form.js | 2 +- .../contexts/SetupWizardContext.tsx | 8 +++- .../views/setupWizard/hooks/useParameters.ts | 14 +++--- .../providers/SetupWizardProvider.tsx | 43 +++++++++++-------- .../views/setupWizard/steps/AdminInfoStep.tsx | 3 +- .../steps/OrganizationInfoStep.tsx | 9 +++- .../setupWizard/steps/RegisterServerStep.tsx | 3 +- .../steps/StandaloneServerStep.tsx | 20 ++++----- packages/rocketchat-i18n/i18n/en.i18n.json | 3 +- server/methods/getSetupWizardParameters.js | 9 ++-- 11 files changed, 67 insertions(+), 49 deletions(-) diff --git a/app/ui-login/client/login/form.html b/app/ui-login/client/login/form.html index ef639ddc1719f..4c4a253104d93 100644 --- a/app/ui-login/client/login/form.html +++ b/app/ui-login/client/login/form.html @@ -126,7 +126,7 @@

{{{_ "Registration_Succeeded"}}}

{{/if}} {{#if registrationAllowed}} - + {{else}} {{#if linkReplacementText}}