fix(admin-panel): resolve feature flag key mismatch (#9530)

Update feature flag handling by mapping input keys to enum values. This
ensures compatibility and prevents potential runtime errors when
updating workspace feature flags.
This commit is contained in:
Antoine Moreaux
2025-01-10 12:30:42 +01:00
committed by GitHub
parent c716a30d92
commit 75bf9e3c69
7 changed files with 324 additions and 10 deletions

View File

@ -26,7 +26,7 @@ export class FeatureFlagEntity {
@Field(() => FeatureFlagKey)
@Column({ nullable: false, type: 'text' })
key: FeatureFlagKey;
key: `${FeatureFlagKey}`;
@Field()
@Column({ nullable: false, type: 'uuid' })

View File

@ -0,0 +1,24 @@
import { CustomException } from 'src/utils/custom-exception';
import { featureFlagValidator } from 'src/engine/core-modules/feature-flag/validates/feature-flag.validate';
describe('featureFlagValidator', () => {
describe('assertIsFeatureFlagKey', () => {
it('should not throw error if featureFlagKey is valid', () => {
expect(() =>
featureFlagValidator.assertIsFeatureFlagKey(
'IsWorkflowEnabled',
new CustomException('Error', 'Error'),
),
).not.toThrow();
});
it('should throw error if featureFlagKey is invalid', () => {
const invalidKey = 'InvalidKey';
const exception = new CustomException('Error', 'Error');
expect(() =>
featureFlagValidator.assertIsFeatureFlagKey(invalidKey, exception),
).toThrow(exception);
});
});
});

View File

@ -0,0 +1,17 @@
import { CustomException } from 'src/utils/custom-exception';
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { isDefined } from 'src/utils/is-defined';
const assertIsFeatureFlagKey = (
featureFlagKey: string,
exceptionToThrow: CustomException,
): asserts featureFlagKey is FeatureFlagKey => {
if (isDefined(FeatureFlagKey[featureFlagKey])) return;
throw exceptionToThrow;
};
export const featureFlagValidator: {
assertIsFeatureFlagKey: typeof assertIsFeatureFlagKey;
} = {
assertIsFeatureFlagKey: assertIsFeatureFlagKey,
};