mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: only add project environments if enabled (#1050)
This commit is contained in:
parent
e345980dcf
commit
3484340cd0
@ -59,6 +59,8 @@ export default class ProjectService {
|
|||||||
|
|
||||||
private featureToggleService: FeatureToggleServiceV2;
|
private featureToggleService: FeatureToggleServiceV2;
|
||||||
|
|
||||||
|
private environmentsEnabled: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
{
|
{
|
||||||
projectStore,
|
projectStore,
|
||||||
@ -89,6 +91,8 @@ export default class ProjectService {
|
|||||||
this.featureTypeStore = featureTypeStore;
|
this.featureTypeStore = featureTypeStore;
|
||||||
this.featureToggleService = featureToggleService;
|
this.featureToggleService = featureToggleService;
|
||||||
this.logger = config.getLogger('services/project-service.js');
|
this.logger = config.getLogger('services/project-service.js');
|
||||||
|
this.environmentsEnabled =
|
||||||
|
config.experimental.environments?.enabled || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProjects(query?: IProjectQuery): Promise<IProjectWithCount[]> {
|
async getProjects(query?: IProjectQuery): Promise<IProjectWithCount[]> {
|
||||||
@ -122,17 +126,26 @@ export default class ProjectService {
|
|||||||
|
|
||||||
await this.store.create(data);
|
await this.store.create(data);
|
||||||
|
|
||||||
const enabledEnvironments = await this.environmentStore.getAll({
|
if (this.environmentsEnabled) {
|
||||||
enabled: true,
|
const enabledEnvironments = await this.environmentStore.getAll({
|
||||||
});
|
enabled: true,
|
||||||
await Promise.all(
|
});
|
||||||
enabledEnvironments.map(async (e) => {
|
|
||||||
await this.featureEnvironmentStore.connectProject(
|
// TODO: Only if enabled!
|
||||||
e.name,
|
await Promise.all(
|
||||||
data.id,
|
enabledEnvironments.map(async (e) => {
|
||||||
);
|
await this.featureEnvironmentStore.connectProject(
|
||||||
}),
|
e.name,
|
||||||
);
|
data.id,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await this.featureEnvironmentStore.connectProject(
|
||||||
|
'default',
|
||||||
|
data.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await this.accessService.createDefaultProjectRoles(user, data.id);
|
await this.accessService.createDefaultProjectRoles(user, data.id);
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ export interface IUnleashConfig {
|
|||||||
ui: IUIConfig;
|
ui: IUIConfig;
|
||||||
import: IImportOption;
|
import: IImportOption;
|
||||||
experimental: {
|
experimental: {
|
||||||
[key: string]: object;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
email: IEmailOption;
|
email: IEmailOption;
|
||||||
secureHeaders: boolean;
|
secureHeaders: boolean;
|
||||||
|
@ -30,7 +30,7 @@ beforeAll(async () => {
|
|||||||
const config = createTestConfig({
|
const config = createTestConfig({
|
||||||
getLogger,
|
getLogger,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
experimental: { rbac: true },
|
experimental: { environments: { enabled: true } },
|
||||||
});
|
});
|
||||||
accessService = new AccessService(stores, config);
|
accessService = new AccessService(stores, config);
|
||||||
featureToggleService = new FeatureToggleServiceV2(stores, config);
|
featureToggleService = new FeatureToggleServiceV2(stores, config);
|
||||||
@ -46,6 +46,16 @@ afterAll(async () => {
|
|||||||
await db.destroy();
|
await db.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const envs = await stores.environmentStore.getAll();
|
||||||
|
const deleteEnvs = envs
|
||||||
|
.filter((env) => env.name !== 'default')
|
||||||
|
.map(async (env) => {
|
||||||
|
await stores.environmentStore.delete(env.name);
|
||||||
|
});
|
||||||
|
await Promise.allSettled(deleteEnvs);
|
||||||
|
});
|
||||||
|
|
||||||
test('should have default project', async () => {
|
test('should have default project', async () => {
|
||||||
const project = await projectService.getProject('default');
|
const project = await projectService.getProject('default');
|
||||||
expect(project).toBeDefined();
|
expect(project).toBeDefined();
|
||||||
@ -536,3 +546,40 @@ test('A newly created project only gets connected to enabled environments', asyn
|
|||||||
expect(connectedEnvs.some((e) => e === enabledEnv)).toBeTruthy();
|
expect(connectedEnvs.some((e) => e === enabledEnv)).toBeTruthy();
|
||||||
expect(connectedEnvs.some((e) => e === disabledEnv)).toBeFalsy();
|
expect(connectedEnvs.some((e) => e === disabledEnv)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('A newly created project only gets connected to default environment if experimental flag is disabled', async () => {
|
||||||
|
const config = createTestConfig({
|
||||||
|
getLogger,
|
||||||
|
// @ts-ignore
|
||||||
|
experimental: { environments: { enabled: false } },
|
||||||
|
});
|
||||||
|
projectService = new ProjectService(
|
||||||
|
stores,
|
||||||
|
//@ts-ignore
|
||||||
|
config,
|
||||||
|
accessService,
|
||||||
|
featureToggleService,
|
||||||
|
);
|
||||||
|
const project = {
|
||||||
|
id: 'environment-test-default',
|
||||||
|
name: 'New environment project',
|
||||||
|
description: 'Blah',
|
||||||
|
};
|
||||||
|
const enabledEnv = 'connection_test';
|
||||||
|
await db.stores.environmentStore.create({
|
||||||
|
name: enabledEnv,
|
||||||
|
type: 'test',
|
||||||
|
});
|
||||||
|
const disabledEnv = 'do_not_connect';
|
||||||
|
await db.stores.environmentStore.create({
|
||||||
|
name: disabledEnv,
|
||||||
|
type: 'test',
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await projectService.createProject(project, user);
|
||||||
|
const connectedEnvs =
|
||||||
|
await db.stores.projectStore.getEnvironmentsForProject(project.id);
|
||||||
|
expect(connectedEnvs).toHaveLength(1); // default, connection_test
|
||||||
|
expect(connectedEnvs[0]).toBe('default');
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user