diff --git a/src/lib/features/feature-toggle/feature-toggle-store.ts b/src/lib/features/feature-toggle/feature-toggle-store.ts index 26d7d33cf589..1deb717200b8 100644 --- a/src/lib/features/feature-toggle/feature-toggle-store.ts +++ b/src/lib/features/feature-toggle/feature-toggle-store.ts @@ -198,6 +198,10 @@ export default class FeatureToggleStore implements IFeatureToggleStore { builder.addSelectColumn('df.enabled as parent_enabled'); } + if (featureQuery?.project) { + builder.forProject(featureQuery.project); + } + const rows = await builder.internalQuery.select( builder.getSelectColumns(), ); diff --git a/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts b/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts index da388a6db831..0fa22b4e90a7 100644 --- a/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts +++ b/src/lib/features/feature-toggle/query-builders/feature-toggle-list-builder.ts @@ -129,7 +129,11 @@ export class FeatureToggleListBuilder { userId, ); }); - + return this; } -} \ No newline at end of file + + forProject = (project: string[]) => { + this.internalQuery.whereIn('features.project', project); + } +} diff --git a/src/lib/features/feature-toggle/tests/feature-toggle-store.e2e.test.ts b/src/lib/features/feature-toggle/tests/feature-toggle-store.e2e.test.ts index beeca94b467d..1f3f43279c9d 100644 --- a/src/lib/features/feature-toggle/tests/feature-toggle-store.e2e.test.ts +++ b/src/lib/features/feature-toggle/tests/feature-toggle-store.e2e.test.ts @@ -1,16 +1,22 @@ import dbInit from '../../../../test/e2e/helpers/database-init'; import getLogger from '../../../../test/fixtures/no-logger'; -import { FeatureToggleDTO, IFeatureToggleStore } from '../../../types'; +import { + FeatureToggleDTO, + IFeatureToggleStore, + IProjectStore, +} from '../../../types'; let stores; let db; let featureToggleStore: IFeatureToggleStore; +let projectStore: IProjectStore; beforeAll(async () => { getLogger.setMuteError(true); db = await dbInit('feature_toggle_store_serial', getLogger); stores = db.stores; featureToggleStore = stores.featureToggleStore; + projectStore = stores.projectStore; }); afterAll(async () => { @@ -301,5 +307,24 @@ describe('potentially_stale marking', () => { expect(potentiallyStale).toBeFalsy(); }); + + test('it should filter projects for playground', async () => { + await projectStore.create({ + id: 'MyProject', + name: 'MyProject', + description: 'MyProject', + }); + await featureToggleStore.create('default', { name: 'featureA' }); + + await featureToggleStore.create('MyProject', { name: 'featureB' }); + + const playgroundFeatures = + await featureToggleStore.getPlaygroundFeatures({ + project: ['MyProject'], + }); + + expect(playgroundFeatures).toHaveLength(1); + expect(playgroundFeatures[0].project).toBe('MyProject'); + }); }); }); diff --git a/src/lib/features/playground/playground-service.ts b/src/lib/features/playground/playground-service.ts index 4b29f1d7888a..23ab10d74af0 100644 --- a/src/lib/features/playground/playground-service.ts +++ b/src/lib/features/playground/playground-service.ts @@ -101,7 +101,7 @@ export class PlaygroundService { ): Promise { const segments = await this.segmentService.getActive(); - let filteredProjects: typeof projects; + let filteredProjects: typeof projects = projects; if (this.flagResolver.isEnabled('privateProjects')) { const projectAccess = await this.privateProjectChecker.getUserAccessibleProjects(