diff --git a/.changeset/popular-fishes-lay.md b/.changeset/popular-fishes-lay.md new file mode 100644 index 0000000000000000000000000000000000000000..e709c0e3563362505db2355464b7e76a82e1fcfa --- /dev/null +++ b/.changeset/popular-fishes-lay.md @@ -0,0 +1,8 @@ +--- +"@rocket.chat/meteor": patch +--- + +**Fixed settings-related statistics not being updated according to the license.** + +We've identified an issue where certain statistics were not reflecting recent license changes. This resulted in outdated information being reported for workspaces. +This change ensures that all reported statistics are current and consider the workspace license. diff --git a/apps/meteor/app/statistics/server/lib/statistics.ts b/apps/meteor/app/statistics/server/lib/statistics.ts index 42d678bb594cbcb563ac693d0b22e5ffb679b483..a6fcc5b17b5b1616dbb441a18cdce574a69fc95a 100644 --- a/apps/meteor/app/statistics/server/lib/statistics.ts +++ b/apps/meteor/app/statistics/server/lib/statistics.ts @@ -70,20 +70,17 @@ export const statistics = { const statistics = {} as IStats; const statsPms = []; - const fetchWizardSettingValue = async <T>(settingName: string): Promise<T | undefined> => { - return ((await Settings.findOne(settingName))?.value as T | undefined) ?? undefined; - }; - // Setup Wizard const [organizationType, industry, size, country, language, serverType, registerServer] = await Promise.all([ - fetchWizardSettingValue<string>('Organization_Type'), - fetchWizardSettingValue<string>('Industry'), - fetchWizardSettingValue<string>('Size'), - fetchWizardSettingValue<string>('Country'), - fetchWizardSettingValue<string>('Language'), - fetchWizardSettingValue<string>('Server_Type'), - fetchWizardSettingValue<boolean>('Register_Server'), + settings.get<string>('Organization_Type'), + settings.get<string>('Industry'), + settings.get<string>('Size'), + settings.get<string>('Country'), + settings.get<string>('Language'), + settings.get<string>('Server_Type'), + settings.get<boolean>('Register_Server'), ]); + statistics.wizard = { organizationType, industry, diff --git a/apps/meteor/server/lib/statistics/getSettingsStatistics.ts b/apps/meteor/server/lib/statistics/getSettingsStatistics.ts index 8573f7abd43a99621586c0c596e20791cf121a3b..6aa9d5284294cc4a383e8418265996243a8b67b6 100644 --- a/apps/meteor/server/lib/statistics/getSettingsStatistics.ts +++ b/apps/meteor/server/lib/statistics/getSettingsStatistics.ts @@ -1,5 +1,6 @@ import type { ISettingStatistics, ISettingStatisticsObject } from '@rocket.chat/core-typings'; -import { Settings } from '@rocket.chat/models'; + +import { settings } from '../../../app/settings/server'; const setSettingsStatistics = async (settings: ISettingStatistics): Promise<ISettingStatisticsObject> => { const { @@ -131,22 +132,16 @@ export const getSettingsStatistics = async (): Promise<ISettingStatisticsObject> { key: 'WebRTC_Enable_Private', alias: 'webRTCEnablePrivate' }, { key: 'WebRTC_Enable_Direct', alias: 'webRTCEnableDirect' }, { key: 'Canned_Responses_Enable', alias: 'cannedResponsesEnabled' }, - ]; + ] as const; + + const settingsStatistics = settingsBase.reduce<ISettingStatistics>((acc, { key, alias }) => { + if (!settings.has(key)) return acc; - // Mapping only _id values - const settingsIDs = settingsBase.map((el) => el.key); + acc[alias] = settings.get(key); - const settingsStatistics = ( - await Settings.findByIds(settingsIDs) - .map((el): ISettingStatistics => { - const alias = settingsBase.find((obj) => obj.key === el._id)?.alias || {}; + return acc; + }, {}); - if (!!alias && Object.keys(el).length) return { [String(alias)]: el.value }; - return alias; - }) - .filter((el: ISettingStatistics) => Object.keys(el).length) // Filter to remove all empty objects - .toArray() - ).reduce((a, b) => Object.assign(a, b), {}); // Convert array to objects const staticticObject = await setSettingsStatistics(settingsStatistics); return staticticObject;