Skip to content

Commit

Permalink
regression: Setting not considering license active modules (#34039)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris authored Nov 25, 2024
1 parent 49b90eb commit 1dd2b47
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 0 additions & 4 deletions apps/meteor/client/views/admin/EditableSettingsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type EditableSettingsContextValue = {
_id: ISetting['_id'],
) => [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => ISetting['_id'][]];
readonly dispatch: (changes: Partial<EditableSetting>[]) => void;
readonly isEnterprise: boolean;
};

export const EditableSettingsContext = createContext<EditableSettingsContextValue>({
Expand All @@ -37,11 +36,8 @@ export const EditableSettingsContext = createContext<EditableSettingsContextValu
queryGroupSections: () => [(): (() => void) => (): void => undefined, (): string[] => []],
queryGroupTabs: () => [(): (() => void) => (): void => undefined, (): ISetting['_id'][] => []],
dispatch: () => undefined,
isEnterprise: false,
});

export const useIsEnterprise = (): boolean => useContext(EditableSettingsContext).isEnterprise;

export const useEditableSetting = (_id: ISetting['_id']): EditableSetting | undefined => {
const { queryEditableSetting } = useContext(EditableSettingsContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { FilterOperators } from 'mongodb';
import type { MutableRefObject, ReactNode } from 'react';
import React, { useEffect, useMemo, useRef } from 'react';

import { useIsEnterprise } from '../../../hooks/useIsEnterprise';
import { createReactiveSubscriptionFactory } from '../../../lib/createReactiveSubscriptionFactory';
import type { EditableSetting, EditableSettingsContextValue } from '../EditableSettingsContext';
import { EditableSettingsContext } from '../EditableSettingsContext';
Expand Down Expand Up @@ -193,20 +192,15 @@ const EditableSettingsProvider = ({ children, query = defaultQuery, omit = defau
Tracker.flush();
});

const { data } = useIsEnterprise();

const isEnterprise = data?.isEnterprise ?? false;

const contextValue = useMemo<EditableSettingsContextValue>(
() => ({
queryEditableSetting,
queryEditableSettings,
queryGroupSections,
queryGroupTabs,
dispatch,
isEnterprise,
}),
[queryEditableSetting, queryEditableSettings, queryGroupSections, queryGroupTabs, dispatch, isEnterprise],
[queryEditableSetting, queryEditableSettings, queryGroupSections, queryGroupTabs, dispatch],
);

return <EditableSettingsContext.Provider children={children} value={contextValue} />;
Expand Down
8 changes: 5 additions & 3 deletions apps/meteor/client/views/admin/settings/Setting/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { useTranslation } from 'react-i18next';

import MemoizedSetting from './MemoizedSetting';
import MarkdownText from '../../../../components/MarkdownText';
import { useEditableSetting, useEditableSettingsDispatch, useIsEnterprise } from '../../EditableSettingsContext';
import { useEditableSetting, useEditableSettingsDispatch } from '../../EditableSettingsContext';
import { useHasSettingModule } from '../hooks/useHasSettingModule';

type SettingProps = {
className?: string;
Expand All @@ -20,7 +21,7 @@ type SettingProps = {
function Setting({ className = undefined, settingId, sectionChanged }: SettingProps): ReactElement {
const setting = useEditableSetting(settingId);
const persistedSetting = useSettingStructure(settingId);
const isEnterprise = useIsEnterprise();
const hasSettingModule = useHasSettingModule(setting);

if (!setting || !persistedSetting) {
throw new Error(`Setting ${settingId} not found`);
Expand Down Expand Up @@ -105,12 +106,13 @@ function Setting({ className = undefined, settingId, sectionChanged }: SettingPr
) : undefined,
[i18n, i18nDescription, t],
);

const callout = useMemo(
() => alert && <span dangerouslySetInnerHTML={{ __html: i18n.exists(alert) ? t(alert) : alert }} />,
[alert, i18n, t],
);

const shouldDisableEnterprise = setting.enterprise && !isEnterprise;
const shouldDisableEnterprise = setting.enterprise && !hasSettingModule;

const PRICING_URL = 'https://go.rocket.chat/i/see-paid-plan-customize-homepage';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ISetting, LicenseModule } from '@rocket.chat/core-typings';
import { useMemo } from 'react';

import { useLicenseBase } from '../../../../hooks/useLicense';

export const useHasSettingModule = (setting?: ISetting) => {
const { data } = useLicenseBase({
select: (data) => ({ isEnterprise: Boolean(data?.license.license), activeModules: data?.license.activeModules }),
});

const isEnterprise = data?.isEnterprise ?? false;

const hasSettingModule = useMemo(() => {
if (!setting?.modules || setting?.modules.length === 0) {
return false;
}

return setting.modules.every((module) => data?.activeModules.includes(module as LicenseModule));
}, [data?.activeModules, setting?.modules]);

if (!setting) {
throw new Error('No setting provided');
}

return isEnterprise && hasSettingModule;
};

0 comments on commit 1dd2b47

Please sign in to comment.