[permissions] Rename enum SettingsFeatures --> SettingsPermissions (#10389)
This commit is contained in:
@ -4,7 +4,7 @@ import { Route, Routes } from 'react-router-dom';
|
||||
import { SettingsProtectedRouteWrapper } from '@/settings/components/SettingsProtectedRouteWrapper';
|
||||
import { SettingsSkeletonLoader } from '@/settings/components/SettingsSkeletonLoader';
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { SettingsFeatures } from 'twenty-shared';
|
||||
import { SettingsPermissions } from 'twenty-shared';
|
||||
import { FeatureFlagKey } from '~/generated-metadata/graphql';
|
||||
|
||||
const SettingsAccountsCalendars = lazy(() =>
|
||||
@ -308,7 +308,7 @@ export const SettingsRoutes = ({
|
||||
<Route
|
||||
element={
|
||||
<SettingsProtectedRouteWrapper
|
||||
settingsPermission={SettingsFeatures.WORKSPACE}
|
||||
settingsPermission={SettingsPermissions.WORKSPACE}
|
||||
/>
|
||||
}
|
||||
>
|
||||
@ -323,7 +323,7 @@ export const SettingsRoutes = ({
|
||||
<Route
|
||||
element={
|
||||
<SettingsProtectedRouteWrapper
|
||||
settingsPermission={SettingsFeatures.DATA_MODEL}
|
||||
settingsPermission={SettingsPermissions.DATA_MODEL}
|
||||
/>
|
||||
}
|
||||
>
|
||||
@ -341,7 +341,7 @@ export const SettingsRoutes = ({
|
||||
<Route
|
||||
element={
|
||||
<SettingsProtectedRouteWrapper
|
||||
settingsPermission={SettingsFeatures.ROLES}
|
||||
settingsPermission={SettingsPermissions.ROLES}
|
||||
requiredFeatureFlag={FeatureFlagKey.IsPermissionsEnabled}
|
||||
/>
|
||||
}
|
||||
@ -437,7 +437,7 @@ export const SettingsRoutes = ({
|
||||
<Route
|
||||
element={
|
||||
<SettingsProtectedRouteWrapper
|
||||
settingsPermission={SettingsFeatures.WORKSPACE}
|
||||
settingsPermission={SettingsPermissions.WORKSPACE}
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
||||
@ -12,7 +12,7 @@ import { ViewType } from '@/views/types/ViewType';
|
||||
import { useCallback, useContext } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { isDefined, SettingsFeatures } from 'twenty-shared';
|
||||
import { isDefined, SettingsPermissions } from 'twenty-shared';
|
||||
import { IconEyeOff, IconSettings } from 'twenty-ui';
|
||||
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
|
||||
|
||||
@ -71,7 +71,7 @@ export const useRecordGroupActions = ({
|
||||
]);
|
||||
|
||||
const hasAccessToDataModelSettings = useHasSettingsPermission(
|
||||
SettingsFeatures.DATA_MODEL,
|
||||
SettingsPermissions.DATA_MODEL,
|
||||
);
|
||||
|
||||
const recordGroupActions: RecordGroupAction[] = [];
|
||||
|
||||
@ -3,12 +3,12 @@ import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { ReactNode } from 'react';
|
||||
import { Navigate, Outlet } from 'react-router-dom';
|
||||
import { FeatureFlagKey, SettingsFeatures } from '~/generated/graphql';
|
||||
import { FeatureFlagKey, SettingsPermissions } from '~/generated/graphql';
|
||||
import { getSettingsPath } from '~/utils/navigation/getSettingsPath';
|
||||
|
||||
type SettingsProtectedRouteWrapperProps = {
|
||||
children?: ReactNode;
|
||||
settingsPermission?: SettingsFeatures;
|
||||
settingsPermission?: SettingsPermissions;
|
||||
requiredFeatureFlag?: FeatureFlagKey;
|
||||
};
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import { renderHook } from '@testing-library/react';
|
||||
import { ReactNode } from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { MutableSnapshot, RecoilRoot } from 'recoil';
|
||||
import { SettingsFeatures } from 'twenty-shared';
|
||||
import { SettingsPermissions } from 'twenty-shared';
|
||||
import { Billing, FeatureFlagKey, OnboardingStatus } from '~/generated/graphql';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
@ -56,12 +56,12 @@ jest.mock('@/workspace/hooks/useFeatureFlagsMap', () => ({
|
||||
describe('useSettingsNavigationItems', () => {
|
||||
it('should hide workspace settings when no permissions', () => {
|
||||
(useSettingsPermissionMap as jest.Mock).mockImplementation(() => ({
|
||||
[SettingsFeatures.WORKSPACE]: false,
|
||||
[SettingsFeatures.WORKSPACE_USERS]: false,
|
||||
[SettingsFeatures.DATA_MODEL]: false,
|
||||
[SettingsFeatures.API_KEYS_AND_WEBHOOKS]: false,
|
||||
[SettingsFeatures.ROLES]: false,
|
||||
[SettingsFeatures.SECURITY]: false,
|
||||
[SettingsPermissions.WORKSPACE]: false,
|
||||
[SettingsPermissions.WORKSPACE_USERS]: false,
|
||||
[SettingsPermissions.DATA_MODEL]: false,
|
||||
[SettingsPermissions.API_KEYS_AND_WEBHOOKS]: false,
|
||||
[SettingsPermissions.ROLES]: false,
|
||||
[SettingsPermissions.SECURITY]: false,
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSettingsNavigationItems(), {
|
||||
@ -77,12 +77,12 @@ describe('useSettingsNavigationItems', () => {
|
||||
|
||||
it('should show workspace settings when has permissions', () => {
|
||||
(useSettingsPermissionMap as jest.Mock).mockImplementation(() => ({
|
||||
[SettingsFeatures.WORKSPACE]: true,
|
||||
[SettingsFeatures.WORKSPACE_USERS]: true,
|
||||
[SettingsFeatures.DATA_MODEL]: true,
|
||||
[SettingsFeatures.API_KEYS_AND_WEBHOOKS]: true,
|
||||
[SettingsFeatures.ROLES]: true,
|
||||
[SettingsFeatures.SECURITY]: true,
|
||||
[SettingsPermissions.WORKSPACE]: true,
|
||||
[SettingsPermissions.WORKSPACE_USERS]: true,
|
||||
[SettingsPermissions.DATA_MODEL]: true,
|
||||
[SettingsPermissions.API_KEYS_AND_WEBHOOKS]: true,
|
||||
[SettingsPermissions.ROLES]: true,
|
||||
[SettingsPermissions.SECURITY]: true,
|
||||
}));
|
||||
|
||||
const { result } = renderHook(() => useSettingsNavigationItems(), {
|
||||
|
||||
@ -20,7 +20,7 @@ import {
|
||||
} from 'twenty-ui';
|
||||
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { SettingsFeatures } from 'twenty-shared';
|
||||
import { SettingsPermissions } from 'twenty-shared';
|
||||
import { FeatureFlagKey } from '~/generated-metadata/graphql';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
@ -105,20 +105,20 @@ const useSettingsNavigationItems = (): SettingsNavigationSection[] => {
|
||||
label: t`General`,
|
||||
path: SettingsPath.Workspace,
|
||||
Icon: IconSettings,
|
||||
isHidden: !permissionMap[SettingsFeatures.WORKSPACE],
|
||||
isHidden: !permissionMap[SettingsPermissions.WORKSPACE],
|
||||
},
|
||||
{
|
||||
label: t`Members`,
|
||||
path: SettingsPath.WorkspaceMembersPage,
|
||||
Icon: IconUsers,
|
||||
isHidden: !permissionMap[SettingsFeatures.WORKSPACE_USERS],
|
||||
isHidden: !permissionMap[SettingsPermissions.WORKSPACE_USERS],
|
||||
},
|
||||
{
|
||||
label: t`Billing`,
|
||||
path: SettingsPath.Billing,
|
||||
Icon: IconCurrencyDollar,
|
||||
isHidden:
|
||||
!isBillingEnabled || !permissionMap[SettingsFeatures.WORKSPACE],
|
||||
!isBillingEnabled || !permissionMap[SettingsPermissions.WORKSPACE],
|
||||
},
|
||||
{
|
||||
label: t`Roles`,
|
||||
@ -126,26 +126,26 @@ const useSettingsNavigationItems = (): SettingsNavigationSection[] => {
|
||||
Icon: IconLock,
|
||||
isHidden:
|
||||
!featureFlags[FeatureFlagKey.IsPermissionsEnabled] ||
|
||||
!permissionMap[SettingsFeatures.ROLES],
|
||||
!permissionMap[SettingsPermissions.ROLES],
|
||||
},
|
||||
{
|
||||
label: t`Data model`,
|
||||
path: SettingsPath.Objects,
|
||||
Icon: IconHierarchy2,
|
||||
isHidden: !permissionMap[SettingsFeatures.DATA_MODEL],
|
||||
isHidden: !permissionMap[SettingsPermissions.DATA_MODEL],
|
||||
},
|
||||
{
|
||||
label: t`Integrations`,
|
||||
path: SettingsPath.Integrations,
|
||||
Icon: IconApps,
|
||||
isHidden: !permissionMap[SettingsFeatures.API_KEYS_AND_WEBHOOKS],
|
||||
isHidden: !permissionMap[SettingsPermissions.API_KEYS_AND_WEBHOOKS],
|
||||
},
|
||||
{
|
||||
label: t`Security`,
|
||||
path: SettingsPath.Security,
|
||||
Icon: IconKey,
|
||||
isAdvanced: true,
|
||||
isHidden: !permissionMap[SettingsFeatures.SECURITY],
|
||||
isHidden: !permissionMap[SettingsPermissions.SECURITY],
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -158,7 +158,7 @@ const useSettingsNavigationItems = (): SettingsNavigationSection[] => {
|
||||
path: SettingsPath.Developers,
|
||||
Icon: IconCode,
|
||||
isAdvanced: true,
|
||||
isHidden: !permissionMap[SettingsFeatures.API_KEYS_AND_WEBHOOKS],
|
||||
isHidden: !permissionMap[SettingsPermissions.API_KEYS_AND_WEBHOOKS],
|
||||
},
|
||||
{
|
||||
label: t`Functions`,
|
||||
@ -184,7 +184,7 @@ const useSettingsNavigationItems = (): SettingsNavigationSection[] => {
|
||||
Icon: IconFlask,
|
||||
isHidden:
|
||||
!labPublicFeatureFlags.length ||
|
||||
!permissionMap[SettingsFeatures.WORKSPACE],
|
||||
!permissionMap[SettingsPermissions.WORKSPACE],
|
||||
},
|
||||
{
|
||||
label: t`Releases`,
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { SettingsFeatures } from 'twenty-shared';
|
||||
import { SettingsPermissions } from 'twenty-shared';
|
||||
|
||||
export const useHasSettingsPermission = (
|
||||
settingsPermission?: SettingsFeatures,
|
||||
settingsPermission?: SettingsPermissions,
|
||||
) => {
|
||||
const currentUserWorkspace = useRecoilValue(currentUserWorkspaceState);
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';
|
||||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { SettingsFeatures } from 'twenty-shared';
|
||||
import { SettingsPermissions } from 'twenty-shared';
|
||||
import { FeatureFlagKey } from '~/generated-metadata/graphql';
|
||||
import { buildRecordFromKeysWithSameValue } from '~/utils/array/buildRecordFromKeysWithSameValue';
|
||||
|
||||
export const useSettingsPermissionMap = (): Record<
|
||||
SettingsFeatures,
|
||||
SettingsPermissions,
|
||||
boolean
|
||||
> => {
|
||||
const currentUserWorkspace = useRecoilValue(currentUserWorkspaceState);
|
||||
@ -19,7 +19,7 @@ export const useSettingsPermissionMap = (): Record<
|
||||
currentUserWorkspace?.settingsPermissions;
|
||||
|
||||
const initialPermissions = buildRecordFromKeysWithSameValue(
|
||||
Object.values(SettingsFeatures),
|
||||
Object.values(SettingsPermissions),
|
||||
!isPermissionEnabled,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user