Skip to content

Commit a918767

Browse files
authored
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)
1 parent add4191 commit a918767

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

frontend/src/component/environments/EnvironmentTable/EnvironmentActionCell/EnvironmentActionCellPopover/EnvironmentActionCellPopover.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const EnvironmentActionCellPopover = ({
140140
onDeprecateToggle();
141141
handleClose();
142142
}}
143-
disabled={!hasAccess || environment.protected}
143+
disabled={!hasAccess}
144144
>
145145
<ListItemIcon>
146146
<ConditionallyRender

src/lib/features/project-environments/environment-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class EnvironmentService {
9494
async toggleEnvironment(name: string, value: boolean): Promise<void> {
9595
const exists = await this.environmentStore.exists(name);
9696
if (exists) {
97-
return this.environmentStore.updateProperty(name, 'enabled', value);
97+
return this.environmentStore.toggle(name, value);
9898
}
9999
throw new NotFoundError(`Could not find environment ${name}`);
100100
}

src/lib/features/project-environments/environment-store-type.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface IEnvironmentStore extends Store<IEnvironment, string> {
1717
field: string,
1818
value: string | number | boolean,
1919
): Promise<void>;
20+
toggle(name: string, enabled: boolean): Promise<void>;
2021
updateSortOrder(id: string, value: number): Promise<void>;
2122
importEnvironments(environments: IEnvironment[]): Promise<IEnvironment[]>;
2223
delete(name: string): Promise<void>;

src/lib/features/project-environments/environment-store.ts

+8
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ export default class EnvironmentStore implements IEnvironmentStore {
309309
.where({ name: id });
310310
}
311311

312+
async toggle(name: string, enabled: boolean): Promise<void> {
313+
await this.db(TABLE)
314+
.update({
315+
enabled,
316+
})
317+
.where({ name });
318+
}
319+
312320
async update(
313321
env: Pick<IEnvironment, 'type' | 'protected'>,
314322
name: string,

src/lib/features/project-environments/fake-environment-store.ts

+8
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ export default class FakeEnvironmentStore implements IEnvironmentStore {
9292
return Promise.resolve();
9393
}
9494

95+
async toggle(name: string, enabled: boolean): Promise<void> {
96+
const environment = this.environments.find(
97+
(env: IEnvironment) => env.name === name,
98+
);
99+
if (environment) environment.enabled = enabled;
100+
return Promise.resolve();
101+
}
102+
95103
async connectProject(
96104
// eslint-disable-next-line @typescript-eslint/no-unused-vars
97105
environment: string,

src/test/e2e/api/admin/environment.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,12 @@ test('Getting a non existing environment yields 404', async () => {
159159
.get('/api/admin/environments/this-does-not-exist')
160160
.expect(404);
161161
});
162+
163+
test('Can deprecate and undeprecate protected environments', async () => {
164+
await app.request
165+
.post(`/api/admin/environments/${DEFAULT_ENV}/off`)
166+
.expect(204);
167+
await app.request
168+
.post(`/api/admin/environments/${DEFAULT_ENV}/on`)
169+
.expect(204);
170+
});

0 commit comments

Comments
 (0)