Revert "Refine settings and panel preferences"
This reverts commit 760ab62c10.
This commit is contained in:
@@ -153,24 +153,6 @@ describe('panel api', () => {
|
||||
expect(response.body.system.previewConfig).toContain('socks -p1180 -u2');
|
||||
expect(response.body.service.lastEvent).toBe('System configuration updated from panel');
|
||||
});
|
||||
|
||||
it('removes linked users when a service is deleted from settings', async () => {
|
||||
const app = await createTestApp();
|
||||
const token = await authorize(app);
|
||||
const initial = await request(app).get('/api/state').set('Authorization', `Bearer ${token}`);
|
||||
const system = createSystemPayload(initial.body);
|
||||
|
||||
system.services = system.services.filter((service) => service.id !== 'socks-main');
|
||||
|
||||
const response = await request(app).put('/api/system').set('Authorization', `Bearer ${token}`).send(system);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.body.userRecords.some((user: { username: string }) => user.username === 'night-shift')).toBe(
|
||||
false,
|
||||
);
|
||||
expect(response.body.userRecords.some((user: { username: string }) => user.username === 'ops-east')).toBe(false);
|
||||
expect(response.body.service.lastEvent).toMatch(/removed 2 linked users/i);
|
||||
});
|
||||
});
|
||||
|
||||
async function createTestApp() {
|
||||
|
||||
@@ -129,23 +129,8 @@ export function createApp({ store, runtime, runtimeRootDir, auth }: AppServices)
|
||||
app.put('/api/system', async (request, response, next) => {
|
||||
try {
|
||||
const state = await store.read();
|
||||
const requestedSystem = request.body as Partial<UpdateSystemInput>;
|
||||
const nextServiceIds = new Set(
|
||||
(Array.isArray(requestedSystem.services) ? requestedSystem.services : []).map((service) => service.id),
|
||||
);
|
||||
const removedServiceIds = new Set(
|
||||
state.system.services
|
||||
.map((service) => service.id)
|
||||
.filter((serviceId) => !nextServiceIds.has(serviceId)),
|
||||
);
|
||||
|
||||
const removedUsers = state.userRecords.filter((user) => removedServiceIds.has(user.serviceId));
|
||||
state.userRecords = state.userRecords.filter((user) => !removedServiceIds.has(user.serviceId));
|
||||
state.system = validateSystemInput(requestedSystem, state.userRecords);
|
||||
state.service.lastEvent =
|
||||
removedUsers.length > 0
|
||||
? `System configuration updated from panel and removed ${removedUsers.length} linked users`
|
||||
: 'System configuration updated from panel';
|
||||
state.system = validateSystemInput(request.body as Partial<UpdateSystemInput>, state.userRecords);
|
||||
state.service.lastEvent = 'System configuration updated from panel';
|
||||
await persistRuntimeMutation(store, runtime, state, runtimePaths);
|
||||
response.json(await getSnapshot(store, runtime, runtimePaths));
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user