From 4c1dfbefa7877a37d2a0fc05ba6f8c88a572c7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Fri, 9 Feb 2024 08:41:40 +0000 Subject: [PATCH] chore: clean up customRootRolesKillSwitch (#6173) https://linear.app/unleash/issue/2-1308/remove-customrootroleskillswitch-flag Cleans up the `customRootRolesKillSwitch` flag. --- .../src/component/admin/roles/RolesPage.tsx | 48 +++++++------------ frontend/src/interfaces/uiConfig.ts | 1 - .../__snapshots__/create-config.test.ts.snap | 1 - .../features/access/createAccessService.ts | 6 +-- .../createFeatureToggleService.ts | 4 +- src/lib/services/access-service.test.ts | 9 +--- src/lib/services/access-service.ts | 27 +---------- src/lib/types/experimental.ts | 5 -- src/test/fixtures/access-service-mock.ts | 2 +- 9 files changed, 25 insertions(+), 78 deletions(-) diff --git a/frontend/src/component/admin/roles/RolesPage.tsx b/frontend/src/component/admin/roles/RolesPage.tsx index 0ffa53f466..3de251afcd 100644 --- a/frontend/src/component/admin/roles/RolesPage.tsx +++ b/frontend/src/component/admin/roles/RolesPage.tsx @@ -5,7 +5,6 @@ import { RolesTable } from './RolesTable/RolesTable'; import { PageContent } from 'component/common/PageContent/PageContent'; import { Tab, Tabs, styled, useMediaQuery } from '@mui/material'; import { Route, Routes, useLocation } from 'react-router-dom'; -import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { PROJECT_ROLE_TYPE, ROOT_ROLE_TYPE } from '@server/util/constants'; import { useRoles } from 'hooks/api/getters/useRoles/useRoles'; import { Search } from 'component/common/Search/Search'; @@ -32,7 +31,6 @@ const StyledActions = styled('div')({ }); export const RolesPage = () => { - const { uiConfig } = useUiConfig(); const { pathname } = useLocation(); const { roles, projectRoles, loading } = useRoles(); @@ -41,34 +39,24 @@ export const RolesPage = () => { const [modalOpen, setModalOpen] = useState(false); const [selectedRole, setSelectedRole] = useState(); - const tabs = !uiConfig.flags.customRootRolesKillSwitch - ? [ - { - label: 'Root roles', - path: '/admin/roles', - total: roles.length, - }, - { - label: 'Project roles', - path: '/admin/roles/project-roles', - total: projectRoles.length, - }, - ] - : [ - { - label: 'Project roles', - path: '/admin/roles', - total: projectRoles.length, - }, - ]; + const tabs = [ + { + label: 'Root roles', + path: '/admin/roles', + total: roles.length, + }, + { + label: 'Project roles', + path: '/admin/roles/project-roles', + total: projectRoles.length, + }, + ]; const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); - const type = - uiConfig.flags.customRootRolesKillSwitch || - pathname.includes('project-roles') - ? PROJECT_ROLE_TYPE - : ROOT_ROLE_TYPE; + const type = pathname.includes('project-roles') + ? PROJECT_ROLE_TYPE + : ROOT_ROLE_TYPE; return ( { path='*' element={ { - const { eventBus, getLogger, flagResolver } = config; + const { eventBus, getLogger } = config; const groupStore = new GroupStore(db); const accountStore = new AccountStore(db, getLogger); const roleStore = new RoleStore(db, eventBus, getLogger); @@ -34,7 +34,7 @@ export const createAccessService = ( return new AccessService( { accessStore, accountStore, roleStore, environmentStore }, - { getLogger, flagResolver }, + { getLogger }, groupService, eventService, ); @@ -63,7 +63,7 @@ export const createFakeAccessService = ( const accessService = new AccessService( { accessStore, accountStore, roleStore, environmentStore, groupStore }, - { getLogger, flagResolver }, + { getLogger }, groupService, eventService, ); diff --git a/src/lib/features/feature-toggle/createFeatureToggleService.ts b/src/lib/features/feature-toggle/createFeatureToggleService.ts index 1775938788..a1a9ec6f83 100644 --- a/src/lib/features/feature-toggle/createFeatureToggleService.ts +++ b/src/lib/features/feature-toggle/createFeatureToggleService.ts @@ -108,7 +108,7 @@ export const createFeatureToggleService = ( ); const accessService = new AccessService( { accessStore, accountStore, roleStore, environmentStore }, - { getLogger, flagResolver }, + { getLogger }, groupService, eventService, ); @@ -176,7 +176,7 @@ export const createFakeFeatureToggleService = ( ); const accessService = new AccessService( { accessStore, accountStore, roleStore, environmentStore, groupStore }, - { getLogger, flagResolver }, + { getLogger }, groupService, eventService, ); diff --git a/src/lib/services/access-service.test.ts b/src/lib/services/access-service.test.ts index 1750fbbed7..d99f975e54 100644 --- a/src/lib/services/access-service.test.ts +++ b/src/lib/services/access-service.test.ts @@ -19,14 +19,9 @@ import { IGroup, ROLE_CREATED, SYSTEM_USER } from '../../lib/types'; import BadDataError from '../../lib/error/bad-data-error'; import { createFakeEventsService } from '../../lib/features/events/createEventsService'; -function getSetup(customRootRolesKillSwitch: boolean = true) { +function getSetup() { const config = createTestConfig({ getLogger, - experimental: { - flags: { - customRootRolesKillSwitch, - }, - }, }); return createFakeAccessService(config); @@ -166,7 +161,7 @@ test('should be able to validate and cleanup with additional properties', async }); test('user with custom root role should get a user root role', async () => { - const { accessService, eventStore } = getSetup(false); + const { accessService, eventStore } = getSetup(); const createRoleInput: IRoleCreation = { name: 'custom-root-role', description: 'test custom root role', diff --git a/src/lib/services/access-service.ts b/src/lib/services/access-service.ts index 41911be292..c9508a2ea0 100644 --- a/src/lib/services/access-service.ts +++ b/src/lib/services/access-service.ts @@ -40,7 +40,6 @@ import BadDataError from '../error/bad-data-error'; import { IGroup } from '../types/group'; import { GroupService } from './group-service'; import { - IFlagResolver, IUnleashConfig, IUserAccessOverview, ROLE_CREATED, @@ -114,8 +113,6 @@ export class AccessService { private logger: Logger; - private flagResolver: IFlagResolver; - private eventService: EventService; constructor( @@ -128,10 +125,7 @@ export class AccessService { IUnleashStores, 'accessStore' | 'accountStore' | 'roleStore' | 'environmentStore' > & { groupStore?: any }, // TODO remove groupStore later, kept for backward compatibility with enterprise - { - getLogger, - flagResolver, - }: Pick, + { getLogger }: Pick, groupService: GroupService, eventService: EventService, ) { @@ -141,7 +135,6 @@ export class AccessService { this.groupService = groupService; this.environmentStore = environmentStore; this.logger = getLogger('/services/access-service.ts'); - this.flagResolver = flagResolver; this.eventService = eventService; } @@ -643,15 +636,6 @@ export class AccessService { ? CUSTOM_ROOT_ROLE_TYPE : CUSTOM_PROJECT_ROLE_TYPE; - if ( - roleType === CUSTOM_ROOT_ROLE_TYPE && - this.flagResolver.isEnabled('customRootRolesKillSwitch') - ) { - throw new InvalidOperationError( - 'Custom root roles are not enabled.', - ); - } - const baseRole = { ...(await this.validateRole(role)), roleType, @@ -695,15 +679,6 @@ export class AccessService { ? CUSTOM_ROOT_ROLE_TYPE : CUSTOM_PROJECT_ROLE_TYPE; - if ( - roleType === CUSTOM_ROOT_ROLE_TYPE && - this.flagResolver.isEnabled('customRootRolesKillSwitch') - ) { - throw new InvalidOperationError( - 'Custom root roles are not enabled.', - ); - } - await this.validateRole(role, role.id); const existingRole = await this.roleStore.get(role.id); const baseRole = { diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index 0038224348..e98e2e2b0c 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -25,7 +25,6 @@ export type IFlagKey = | 'disableNotifications' | 'advancedPlayground' | 'filterInvalidClientMetrics' - | 'customRootRolesKillSwitch' | 'disableMetrics' | 'scheduledConfigurationChanges' | 'stripClientHeadersOn304' @@ -123,10 +122,6 @@ const flags: IFlags = { process.env.FILTER_INVALID_CLIENT_METRICS, false, ), - customRootRolesKillSwitch: parseEnvVarBoolean( - process.env.UNLEASH_EXPERIMENTAL_CUSTOM_ROOT_ROLES_KILL_SWITCH, - false, - ), disableMetrics: parseEnvVarBoolean( process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS, false, diff --git a/src/test/fixtures/access-service-mock.ts b/src/test/fixtures/access-service-mock.ts index 5d7f1100f2..365d2cfbdc 100644 --- a/src/test/fixtures/access-service-mock.ts +++ b/src/test/fixtures/access-service-mock.ts @@ -18,7 +18,7 @@ class AccessServiceMock extends AccessService { roleStore: undefined, environmentStore: undefined, }, - { getLogger: noLoggerProvider, flagResolver: undefined }, + { getLogger: noLoggerProvider }, undefined, undefined, );