mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
feat(admin): let an operator switch the place index off
trek_places_enabled was read by six call paths — search, autocomplete, the POI pills, booking-import geocoding, the offline area and details resolution — and written by nothing. No admin route, no MCP tool, no switch anywhere in the UI, and the key is not in the settings allow-lists either, so the only way to set it was an INSERT against app_settings by hand on the server. That matters more than the four switches beside it, which trade away quota. This one decides whether every search and every keystroke in the place box leaves the instance at all. The flag reads fail-open, so an install that upgrades without visiting the admin panel starts sending them, which is the right default and exactly why the operator needs somewhere to say no. Adds the pair symmetrically to place-shadow from the same branch: getTrekPlaces /updateTrekPlaces on AddonsService, GET/PUT /api/admin/trek-places with an audit row, and a real switch on the card. The read stays fail-open so it keeps agreeing with MapsService.trekPlacesEnabled(), and a test pins that agreement across every stored value — if those two ever diverge the panel shows "off" while the queries keep leaving, which is worse than either default. The card said this itself: `available` was a display-only prop whose comment read "False until the client is wired to the service; the card then says so instead of offering a switch that would do nothing." It is wired now, so the prop is a switch. Its two badge strings had been shipped to all 23 locales and rendered nowhere; they make way for the switch label and a line naming what answers while the index is off.
This commit is contained in:
@@ -48,6 +48,9 @@ const addonsStub = () => ({
|
||||
// Fail-open, unlike its three neighbours — see AddonsService.getPlacesEnrich.
|
||||
getPlacesEnrich: vi.fn(() => ({ enabled: true })),
|
||||
updatePlacesEnrich: vi.fn((enabled: boolean) => ({ enabled })),
|
||||
// Fail-open too, and the only switch here about egress rather than spending.
|
||||
getTrekPlaces: vi.fn(() => ({ enabled: true })),
|
||||
updateTrekPlaces: vi.fn((enabled: boolean) => ({ enabled })),
|
||||
getCollabFeatures: vi.fn(() => ({ chat: false })),
|
||||
updateCollabFeatures: vi.fn(() => ({ features: { chat: true }, changed: true })),
|
||||
getTransitProvider: vi.fn(() => ({ provider: 'transitous', googleKeySource: null })),
|
||||
@@ -299,6 +302,26 @@ describe('AdminController feature toggles', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('ADMIN-TOGGLE-005 trek-places forwards the body value and audits the stored one', () => {
|
||||
// The audit row carries what the service stored, not what the request
|
||||
// asked for: this switch decides whether every search leaves the instance,
|
||||
// so a row claiming it was turned off when it was not would be worse than
|
||||
// no row at all.
|
||||
const updateTrekPlaces = vi.fn(() => ({ enabled: true }));
|
||||
const c = adminCtl(svc(), undefined, { ...addonsStub(), updateTrekPlaces } as unknown as AddonsService);
|
||||
expect(c.updateTrekPlaces(user, { enabled: false }, req)).toEqual({ enabled: true });
|
||||
expect(updateTrekPlaces).toHaveBeenCalledWith(false);
|
||||
expect(writeAudit).toHaveBeenCalledWith({ userId: user.id, action: 'admin.trek_places', ip: '1.2.3.4', details: { enabled: true } });
|
||||
});
|
||||
|
||||
it('ADMIN-TOGGLE-005b trek-places reads through to AddonsService instead of a controller-side default', () => {
|
||||
const getTrekPlaces = vi.fn(() => ({ enabled: false }));
|
||||
const c = adminCtl(svc(), undefined, { ...addonsStub(), getTrekPlaces } as unknown as AddonsService);
|
||||
expect(c.getTrekPlaces()).toEqual({ enabled: false });
|
||||
expect(getTrekPlaces).toHaveBeenCalledTimes(1);
|
||||
expect(writeAudit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('ADMIN-TOGGLE-004 place-shadow forwards the body value and audits the stored one', () => {
|
||||
// The handler audits result.enabled. A service that declines the flip must
|
||||
// not leave behind an audit row claiming the shadow log was switched on.
|
||||
|
||||
Reference in New Issue
Block a user