1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-09 01:17:06 +02:00

chore: clean up customRootRolesKillSwitch (#6173)

https://linear.app/unleash/issue/2-1308/remove-customrootroleskillswitch-flag

Cleans up the `customRootRolesKillSwitch` flag.
This commit is contained in:
Nuno Góis 2024-02-09 08:41:40 +00:00 committed by GitHub
parent 13df715bfd
commit 4c1dfbefa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 78 deletions

View File

@ -5,7 +5,6 @@ import { RolesTable } from './RolesTable/RolesTable';
import { PageContent } from 'component/common/PageContent/PageContent'; import { PageContent } from 'component/common/PageContent/PageContent';
import { Tab, Tabs, styled, useMediaQuery } from '@mui/material'; import { Tab, Tabs, styled, useMediaQuery } from '@mui/material';
import { Route, Routes, useLocation } from 'react-router-dom'; 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 { PROJECT_ROLE_TYPE, ROOT_ROLE_TYPE } from '@server/util/constants';
import { useRoles } from 'hooks/api/getters/useRoles/useRoles'; import { useRoles } from 'hooks/api/getters/useRoles/useRoles';
import { Search } from 'component/common/Search/Search'; import { Search } from 'component/common/Search/Search';
@ -32,7 +31,6 @@ const StyledActions = styled('div')({
}); });
export const RolesPage = () => { export const RolesPage = () => {
const { uiConfig } = useUiConfig();
const { pathname } = useLocation(); const { pathname } = useLocation();
const { roles, projectRoles, loading } = useRoles(); const { roles, projectRoles, loading } = useRoles();
@ -41,8 +39,7 @@ export const RolesPage = () => {
const [modalOpen, setModalOpen] = useState(false); const [modalOpen, setModalOpen] = useState(false);
const [selectedRole, setSelectedRole] = useState<IRole>(); const [selectedRole, setSelectedRole] = useState<IRole>();
const tabs = !uiConfig.flags.customRootRolesKillSwitch const tabs = [
? [
{ {
label: 'Root roles', label: 'Root roles',
path: '/admin/roles', path: '/admin/roles',
@ -53,20 +50,11 @@ export const RolesPage = () => {
path: '/admin/roles/project-roles', path: '/admin/roles/project-roles',
total: projectRoles.length, total: projectRoles.length,
}, },
]
: [
{
label: 'Project roles',
path: '/admin/roles',
total: projectRoles.length,
},
]; ];
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
const type = const type = pathname.includes('project-roles')
uiConfig.flags.customRootRolesKillSwitch ||
pathname.includes('project-roles')
? PROJECT_ROLE_TYPE ? PROJECT_ROLE_TYPE
: ROOT_ROLE_TYPE; : ROOT_ROLE_TYPE;
@ -156,11 +144,7 @@ export const RolesPage = () => {
path='*' path='*'
element={ element={
<RolesTable <RolesTable
type={ type={ROOT_ROLE_TYPE}
!uiConfig.flags.customRootRolesKillSwitch
? ROOT_ROLE_TYPE
: PROJECT_ROLE_TYPE
}
searchValue={searchValue} searchValue={searchValue}
modalOpen={modalOpen} modalOpen={modalOpen}
setModalOpen={setModalOpen} setModalOpen={setModalOpen}

View File

@ -59,7 +59,6 @@ export type UiFlags = {
disableBulkToggle?: boolean; disableBulkToggle?: boolean;
disableNotifications?: boolean; disableNotifications?: boolean;
advancedPlayground?: boolean; advancedPlayground?: boolean;
customRootRolesKillSwitch?: boolean;
strategyVariant?: boolean; strategyVariant?: boolean;
doraMetrics?: boolean; doraMetrics?: boolean;
dependentFeatures?: boolean; dependentFeatures?: boolean;

View File

@ -81,7 +81,6 @@ exports[`should create default config 1`] = `
"changeRequestConflictHandling": false, "changeRequestConflictHandling": false,
"collectTrafficDataUsage": false, "collectTrafficDataUsage": false,
"createdByUserIdDataMigration": false, "createdByUserIdDataMigration": false,
"customRootRolesKillSwitch": false,
"demo": false, "demo": false,
"disableBulkToggle": false, "disableBulkToggle": false,
"disableMetrics": false, "disableMetrics": false,

View File

@ -19,7 +19,7 @@ export const createAccessService = (
db: Db, db: Db,
config: IUnleashConfig, config: IUnleashConfig,
): AccessService => { ): AccessService => {
const { eventBus, getLogger, flagResolver } = config; const { eventBus, getLogger } = config;
const groupStore = new GroupStore(db); const groupStore = new GroupStore(db);
const accountStore = new AccountStore(db, getLogger); const accountStore = new AccountStore(db, getLogger);
const roleStore = new RoleStore(db, eventBus, getLogger); const roleStore = new RoleStore(db, eventBus, getLogger);
@ -34,7 +34,7 @@ export const createAccessService = (
return new AccessService( return new AccessService(
{ accessStore, accountStore, roleStore, environmentStore }, { accessStore, accountStore, roleStore, environmentStore },
{ getLogger, flagResolver }, { getLogger },
groupService, groupService,
eventService, eventService,
); );
@ -63,7 +63,7 @@ export const createFakeAccessService = (
const accessService = new AccessService( const accessService = new AccessService(
{ accessStore, accountStore, roleStore, environmentStore, groupStore }, { accessStore, accountStore, roleStore, environmentStore, groupStore },
{ getLogger, flagResolver }, { getLogger },
groupService, groupService,
eventService, eventService,
); );

View File

@ -108,7 +108,7 @@ export const createFeatureToggleService = (
); );
const accessService = new AccessService( const accessService = new AccessService(
{ accessStore, accountStore, roleStore, environmentStore }, { accessStore, accountStore, roleStore, environmentStore },
{ getLogger, flagResolver }, { getLogger },
groupService, groupService,
eventService, eventService,
); );
@ -176,7 +176,7 @@ export const createFakeFeatureToggleService = (
); );
const accessService = new AccessService( const accessService = new AccessService(
{ accessStore, accountStore, roleStore, environmentStore, groupStore }, { accessStore, accountStore, roleStore, environmentStore, groupStore },
{ getLogger, flagResolver }, { getLogger },
groupService, groupService,
eventService, eventService,
); );

View File

@ -19,14 +19,9 @@ import { IGroup, ROLE_CREATED, SYSTEM_USER } from '../../lib/types';
import BadDataError from '../../lib/error/bad-data-error'; import BadDataError from '../../lib/error/bad-data-error';
import { createFakeEventsService } from '../../lib/features/events/createEventsService'; import { createFakeEventsService } from '../../lib/features/events/createEventsService';
function getSetup(customRootRolesKillSwitch: boolean = true) { function getSetup() {
const config = createTestConfig({ const config = createTestConfig({
getLogger, getLogger,
experimental: {
flags: {
customRootRolesKillSwitch,
},
},
}); });
return createFakeAccessService(config); 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 () => { 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 = { const createRoleInput: IRoleCreation = {
name: 'custom-root-role', name: 'custom-root-role',
description: 'test custom root role', description: 'test custom root role',

View File

@ -40,7 +40,6 @@ import BadDataError from '../error/bad-data-error';
import { IGroup } from '../types/group'; import { IGroup } from '../types/group';
import { GroupService } from './group-service'; import { GroupService } from './group-service';
import { import {
IFlagResolver,
IUnleashConfig, IUnleashConfig,
IUserAccessOverview, IUserAccessOverview,
ROLE_CREATED, ROLE_CREATED,
@ -114,8 +113,6 @@ export class AccessService {
private logger: Logger; private logger: Logger;
private flagResolver: IFlagResolver;
private eventService: EventService; private eventService: EventService;
constructor( constructor(
@ -128,10 +125,7 @@ export class AccessService {
IUnleashStores, IUnleashStores,
'accessStore' | 'accountStore' | 'roleStore' | 'environmentStore' 'accessStore' | 'accountStore' | 'roleStore' | 'environmentStore'
> & { groupStore?: any }, // TODO remove groupStore later, kept for backward compatibility with enterprise > & { groupStore?: any }, // TODO remove groupStore later, kept for backward compatibility with enterprise
{ { getLogger }: Pick<IUnleashConfig, 'getLogger'>,
getLogger,
flagResolver,
}: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>,
groupService: GroupService, groupService: GroupService,
eventService: EventService, eventService: EventService,
) { ) {
@ -141,7 +135,6 @@ export class AccessService {
this.groupService = groupService; this.groupService = groupService;
this.environmentStore = environmentStore; this.environmentStore = environmentStore;
this.logger = getLogger('/services/access-service.ts'); this.logger = getLogger('/services/access-service.ts');
this.flagResolver = flagResolver;
this.eventService = eventService; this.eventService = eventService;
} }
@ -643,15 +636,6 @@ export class AccessService {
? CUSTOM_ROOT_ROLE_TYPE ? CUSTOM_ROOT_ROLE_TYPE
: CUSTOM_PROJECT_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 = { const baseRole = {
...(await this.validateRole(role)), ...(await this.validateRole(role)),
roleType, roleType,
@ -695,15 +679,6 @@ export class AccessService {
? CUSTOM_ROOT_ROLE_TYPE ? CUSTOM_ROOT_ROLE_TYPE
: CUSTOM_PROJECT_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); await this.validateRole(role, role.id);
const existingRole = await this.roleStore.get(role.id); const existingRole = await this.roleStore.get(role.id);
const baseRole = { const baseRole = {

View File

@ -25,7 +25,6 @@ export type IFlagKey =
| 'disableNotifications' | 'disableNotifications'
| 'advancedPlayground' | 'advancedPlayground'
| 'filterInvalidClientMetrics' | 'filterInvalidClientMetrics'
| 'customRootRolesKillSwitch'
| 'disableMetrics' | 'disableMetrics'
| 'scheduledConfigurationChanges' | 'scheduledConfigurationChanges'
| 'stripClientHeadersOn304' | 'stripClientHeadersOn304'
@ -123,10 +122,6 @@ const flags: IFlags = {
process.env.FILTER_INVALID_CLIENT_METRICS, process.env.FILTER_INVALID_CLIENT_METRICS,
false, false,
), ),
customRootRolesKillSwitch: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_CUSTOM_ROOT_ROLES_KILL_SWITCH,
false,
),
disableMetrics: parseEnvVarBoolean( disableMetrics: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS, process.env.UNLEASH_EXPERIMENTAL_DISABLE_METRICS,
false, false,

View File

@ -18,7 +18,7 @@ class AccessServiceMock extends AccessService {
roleStore: undefined, roleStore: undefined,
environmentStore: undefined, environmentStore: undefined,
}, },
{ getLogger: noLoggerProvider, flagResolver: undefined }, { getLogger: noLoggerProvider },
undefined, undefined,
undefined, undefined,
); );