mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-28 00:17:12 +01: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();
|
||||
handleClose();
|
||||
}}
|
||||
disabled={!hasAccess || environment.protected}
|
||||
disabled={!hasAccess}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<ConditionallyRender
|
||||
|
@ -94,7 +94,7 @@ export default class EnvironmentService {
|
||||
async toggleEnvironment(name: string, value: boolean): Promise<void> {
|
||||
const exists = await this.environmentStore.exists(name);
|
||||
if (exists) {
|
||||
return this.environmentStore.updateProperty(name, 'enabled', value);
|
||||
return this.environmentStore.toggle(name, value);
|
||||
}
|
||||
throw new NotFoundError(`Could not find environment ${name}`);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ export interface IEnvironmentStore extends Store<IEnvironment, string> {
|
||||
field: string,
|
||||
value: string | number | boolean,
|
||||
): Promise<void>;
|
||||
toggle(name: string, enabled: boolean): Promise<void>;
|
||||
updateSortOrder(id: string, value: number): Promise<void>;
|
||||
importEnvironments(environments: IEnvironment[]): Promise<IEnvironment[]>;
|
||||
delete(name: string): Promise<void>;
|
||||
|
@ -309,6 +309,14 @@ export default class EnvironmentStore implements IEnvironmentStore {
|
||||
.where({ name: id });
|
||||
}
|
||||
|
||||
async toggle(name: string, enabled: boolean): Promise<void> {
|
||||
await this.db(TABLE)
|
||||
.update({
|
||||
enabled,
|
||||
})
|
||||
.where({ name });
|
||||
}
|
||||
|
||||
async update(
|
||||
env: Pick<IEnvironment, 'type' | 'protected'>,
|
||||
name: string,
|
||||
|
@ -92,6 +92,14 @@ export default class FakeEnvironmentStore implements IEnvironmentStore {
|
||||
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(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
environment: string,
|
||||
|
@ -159,3 +159,12 @@ test('Getting a non existing environment yields 404', async () => {
|
||||
.get('/api/admin/environments/this-does-not-exist')
|
||||
.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