mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-04 01:18:20 +02:00
chore: deprecate and undeprecate protected environments (#9360)
https://linear.app/unleash/issue/2-3320/allow-users-to-deprecate-and-undeprecate-protected-environments Allows users to deprecate and undeprecate protected environments. 
This commit is contained in:
parent
add4191381
commit
a91876790e
@ -140,7 +140,7 @@ export const EnvironmentActionCellPopover = ({
|
|||||||
onDeprecateToggle();
|
onDeprecateToggle();
|
||||||
handleClose();
|
handleClose();
|
||||||
}}
|
}}
|
||||||
disabled={!hasAccess || environment.protected}
|
disabled={!hasAccess}
|
||||||
>
|
>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
|
@ -94,7 +94,7 @@ export default class EnvironmentService {
|
|||||||
async toggleEnvironment(name: string, value: boolean): Promise<void> {
|
async toggleEnvironment(name: string, value: boolean): Promise<void> {
|
||||||
const exists = await this.environmentStore.exists(name);
|
const exists = await this.environmentStore.exists(name);
|
||||||
if (exists) {
|
if (exists) {
|
||||||
return this.environmentStore.updateProperty(name, 'enabled', value);
|
return this.environmentStore.toggle(name, value);
|
||||||
}
|
}
|
||||||
throw new NotFoundError(`Could not find environment ${name}`);
|
throw new NotFoundError(`Could not find environment ${name}`);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ export interface IEnvironmentStore extends Store<IEnvironment, string> {
|
|||||||
field: string,
|
field: string,
|
||||||
value: string | number | boolean,
|
value: string | number | boolean,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
toggle(name: string, enabled: boolean): Promise<void>;
|
||||||
updateSortOrder(id: string, value: number): Promise<void>;
|
updateSortOrder(id: string, value: number): Promise<void>;
|
||||||
importEnvironments(environments: IEnvironment[]): Promise<IEnvironment[]>;
|
importEnvironments(environments: IEnvironment[]): Promise<IEnvironment[]>;
|
||||||
delete(name: string): Promise<void>;
|
delete(name: string): Promise<void>;
|
||||||
|
@ -309,6 +309,14 @@ export default class EnvironmentStore implements IEnvironmentStore {
|
|||||||
.where({ name: id });
|
.where({ name: id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async toggle(name: string, enabled: boolean): Promise<void> {
|
||||||
|
await this.db(TABLE)
|
||||||
|
.update({
|
||||||
|
enabled,
|
||||||
|
})
|
||||||
|
.where({ name });
|
||||||
|
}
|
||||||
|
|
||||||
async update(
|
async update(
|
||||||
env: Pick<IEnvironment, 'type' | 'protected'>,
|
env: Pick<IEnvironment, 'type' | 'protected'>,
|
||||||
name: string,
|
name: string,
|
||||||
|
@ -92,6 +92,14 @@ export default class FakeEnvironmentStore implements IEnvironmentStore {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async toggle(name: string, enabled: boolean): Promise<void> {
|
||||||
|
const environment = this.environments.find(
|
||||||
|
(env: IEnvironment) => env.name === name,
|
||||||
|
);
|
||||||
|
if (environment) environment.enabled = enabled;
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
async connectProject(
|
async connectProject(
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
environment: string,
|
environment: string,
|
||||||
|
@ -159,3 +159,12 @@ test('Getting a non existing environment yields 404', async () => {
|
|||||||
.get('/api/admin/environments/this-does-not-exist')
|
.get('/api/admin/environments/this-does-not-exist')
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Can deprecate and undeprecate protected environments', async () => {
|
||||||
|
await app.request
|
||||||
|
.post(`/api/admin/environments/${DEFAULT_ENV}/off`)
|
||||||
|
.expect(204);
|
||||||
|
await app.request
|
||||||
|
.post(`/api/admin/environments/${DEFAULT_ENV}/on`)
|
||||||
|
.expect(204);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user