Skip to content

Commit

Permalink
chore: remove customRootRoles flag in favor of killswitch (#4431)
Browse files Browse the repository at this point in the history
https://linear.app/unleash/issue/2-1303/adapt-existing-customrootroles-flag-to-a-customrootroleskillswitch

Removes the existing `customRootRoles` flag in favor of a
`customRootRolesKillSwitch` which should follow the same logic but
negated/inverted.

Once released, this will effectively make custom root roles GA, and we
can use
[customRootRolesKillSwitch](https://app.unleash-hosted.com/hosted/projects/eg/features/customRootRolesKillSwitch)
to disable the feature if needed.
  • Loading branch information
nunogois committed Aug 10, 2023
1 parent 22273d7 commit ded33a6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 107 deletions.
7 changes: 4 additions & 3 deletions frontend/src/component/admin/roles/RolesPage.tsx
Expand Up @@ -41,7 +41,7 @@ export const RolesPage = () => {
const [modalOpen, setModalOpen] = useState(false);
const [selectedRole, setSelectedRole] = useState<IRole>();

const tabs = uiConfig.flags.customRootRoles
const tabs = !uiConfig.flags.customRootRolesKillSwitch
? [
{
label: 'Root roles',
Expand All @@ -65,7 +65,8 @@ export const RolesPage = () => {
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));

const type =
!uiConfig.flags.customRootRoles || pathname.includes('project-roles')
uiConfig.flags.customRootRolesKillSwitch ||
pathname.includes('project-roles')
? PROJECT_ROLE_TYPE
: ROOT_ROLE_TYPE;

Expand Down Expand Up @@ -157,7 +158,7 @@ export const RolesPage = () => {
element={
<RolesTable
type={
uiConfig.flags.customRootRoles
!uiConfig.flags.customRootRolesKillSwitch
? ROOT_ROLE_TYPE
: PROJECT_ROLE_TYPE
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/interfaces/uiConfig.ts
Expand Up @@ -50,7 +50,7 @@ export interface IFlags {
disableBulkToggle?: boolean;
disableNotifications?: boolean;
advancedPlayground?: boolean;
customRootRoles?: boolean;
customRootRolesKillSwitch?: boolean;
strategyVariant?: boolean;
newProjectLayout?: boolean;
configurableFeatureTypeLifetimes?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__snapshots__/create-config.test.ts.snap
Expand Up @@ -70,7 +70,7 @@ exports[`should create default config 1`] = `
"anonymiseEventLog": false,
"caseInsensitiveInOperators": false,
"configurableFeatureTypeLifetimes": false,
"customRootRoles": false,
"customRootRolesKillSwitch": false,
"demo": false,
"disableBulkToggle": false,
"disableNotifications": false,
Expand Down Expand Up @@ -107,7 +107,7 @@ exports[`should create default config 1`] = `
"anonymiseEventLog": false,
"caseInsensitiveInOperators": false,
"configurableFeatureTypeLifetimes": false,
"customRootRoles": false,
"customRootRolesKillSwitch": false,
"demo": false,
"disableBulkToggle": false,
"disableNotifications": false,
Expand Down
11 changes: 3 additions & 8 deletions src/lib/services/access-service.test.ts
Expand Up @@ -14,12 +14,12 @@ import FakeEventStore from '../../test/fixtures/fake-event-store';
import { IRole } from 'lib/types/stores/access-store';
import { IGroup } from 'lib/types';

function getSetup(customRootRoles: boolean = false) {
function getSetup(customRootRolesKillSwitch: boolean = true) {
const config = createTestConfig({
getLogger,
experimental: {
flags: {
customRootRoles: customRootRoles,
customRootRolesKillSwitch,
},
},
});
Expand Down Expand Up @@ -161,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 } = getSetup(true);
const { accessService } = getSetup(false);
const customRootRole = await accessService.createRole({
name: 'custom-root-role',
description: 'test custom root role',
Expand All @@ -185,11 +185,6 @@ test('throws error when trying to delete a project role in use by group', async
};
const config = createTestConfig({
getLogger,
experimental: {
flags: {
customRootRoles: false,
},
},
});

const eventStore = new FakeEventStore();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/services/access-service.ts
Expand Up @@ -519,7 +519,7 @@ export class AccessService {

if (
roleType === CUSTOM_ROOT_ROLE_TYPE &&
!this.flagResolver.isEnabled('customRootRoles')
this.flagResolver.isEnabled('customRootRolesKillSwitch')
) {
throw new InvalidOperationError(
'Custom root roles are not enabled.',
Expand Down Expand Up @@ -557,7 +557,7 @@ export class AccessService {

if (
roleType === CUSTOM_ROOT_ROLE_TYPE &&
!this.flagResolver.isEnabled('customRootRoles')
this.flagResolver.isEnabled('customRootRolesKillSwitch')
) {
throw new InvalidOperationError(
'Custom root roles are not enabled.',
Expand Down
13 changes: 6 additions & 7 deletions src/lib/types/experimental.ts
Expand Up @@ -20,7 +20,6 @@ export type IFlagKey =
| 'disableBulkToggle'
| 'disableNotifications'
| 'advancedPlayground'
| 'customRootRoles'
| 'strategyVariant'
| 'newProjectLayout'
| 'slackAppAddon'
Expand All @@ -29,7 +28,8 @@ export type IFlagKey =
| 'filterInvalidClientMetrics'
| 'frontendNavigationUpdate'
| 'lastSeenByEnvironment'
| 'segmentChangeRequests';
| 'segmentChangeRequests'
| 'customRootRolesKillSwitch';

export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

Expand Down Expand Up @@ -97,10 +97,6 @@ const flags: IFlags = {
process.env.DISABLE_NOTIFICATIONS,
false,
),
customRootRoles: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_CUSTOM_ROOT_ROLES,
false,
),
newProjectLayout: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_NEW_PROJECT_LAYOUT,
false,
Expand All @@ -113,7 +109,6 @@ const flags: IFlags = {
process.env.UNLEASH_SLACK_APP_ADDON,
false,
),

emitPotentiallyStaleEvents: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_EMIT_POTENTIALLY_STALE_EVENTS,
false,
Expand All @@ -138,6 +133,10 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_SEGMENT_CHANGE_REQUESTS,
false,
),
customRootRolesKillSwitch: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_CUSTOM_ROOT_ROLES_KILL_SWITCH,
false,
),
};

export const defaultExperimentalOptions: IExperimentalOptions = {
Expand Down
85 changes: 1 addition & 84 deletions src/test/e2e/api/admin/api-token.auth.e2e.test.ts
Expand Up @@ -206,13 +206,7 @@ test('A role with only CREATE_PROJECT_API_TOKEN can create project tokens', asyn
});
};

const { request, destroy } = await setupAppWithCustomAuth(stores, preHook, {
experimental: {
flags: {
customRootRoles: true,
},
},
});
const { request, destroy } = await setupAppWithCustomAuth(stores, preHook);

await request
.post('/api/admin/projects/default/api-tokens')
Expand Down Expand Up @@ -261,13 +255,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
await request
.post('/api/admin/api-tokens')
Expand Down Expand Up @@ -312,13 +299,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
await request
.post('/api/admin/api-tokens')
Expand Down Expand Up @@ -363,13 +343,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
await request
.post('/api/admin/api-tokens')
Expand Down Expand Up @@ -417,13 +390,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
await stores.apiTokenStore.insert({
username: 'client',
Expand Down Expand Up @@ -486,13 +452,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
await stores.apiTokenStore.insert({
username: 'client',
Expand Down Expand Up @@ -650,13 +609,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
const token = await stores.apiTokenStore.insert({
username: 'cilent',
Expand Down Expand Up @@ -706,13 +658,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
const token = await stores.apiTokenStore.insert({
username: 'frontend',
Expand Down Expand Up @@ -763,13 +708,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
const token = await stores.apiTokenStore.insert({
username: 'admin',
Expand Down Expand Up @@ -823,13 +761,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
const token = await stores.apiTokenStore.insert({
username: 'cilent',
Expand Down Expand Up @@ -879,13 +810,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
const token = await stores.apiTokenStore.insert({
username: 'frontend',
Expand Down Expand Up @@ -935,13 +859,6 @@ describe('Fine grained API token permissions', () => {
const { request, destroy } = await setupAppWithCustomAuth(
stores,
preHook,
{
experimental: {
flags: {
customRootRoles: true,
},
},
},
);
const token = await stores.apiTokenStore.insert({
username: 'admin',
Expand Down

0 comments on commit ded33a6

Please sign in to comment.