1
0
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.


![image](https://github.com/user-attachments/assets/621684d3-21e3-4f58-b6b5-2d2731c9fd9e)
This commit is contained in:
Nuno Góis 2025-02-25 13:41:41 +00:00 committed by GitHub
parent add4191381
commit a91876790e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 2 deletions

View File

@ -140,7 +140,7 @@ export const EnvironmentActionCellPopover = ({
onDeprecateToggle();
handleClose();
}}
disabled={!hasAccess || environment.protected}
disabled={!hasAccess}
>
<ListItemIcon>
<ConditionallyRender

View File

@ -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}`);
}

View File

@ -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>;

View File

@ -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,

View File

@ -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,

View File

@ -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);
});