mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
bc62eb0d6f
GET /api/admin/service-identity lists places, photon and valhalla, each with today's allowance read fresh from /v1/quota of its own host (cached for 20 seconds per host) and whether this instance asks it right now: Photon only beside the public Nominatim, the TREK Valhalla only where the routing choice comes to it. Photon and Valhalla are asked only with a key and only while TREK_SERVICES_HOSTS lists them. The last allowance an answer stated is kept per host for when a host does not answer. The card lists the three services under each other in the look it had, a service this instance does not ask dimmed and named as such.
170 lines
5.1 KiB
TypeScript
170 lines
5.1 KiB
TypeScript
import { http, HttpResponse } from 'msw';
|
|
import { buildUser, buildAdmin } from '../../factories';
|
|
|
|
export const adminHandlers = [
|
|
http.get('/api/admin/users', () => {
|
|
const user1 = buildUser({ username: 'alice', email: 'alice@example.com' });
|
|
const admin1 = buildAdmin({ username: 'admin', email: 'admin@example.com' });
|
|
return HttpResponse.json({ users: [admin1, user1] });
|
|
}),
|
|
|
|
http.post('/api/admin/users', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
const user = buildUser({ ...body });
|
|
return HttpResponse.json({ user });
|
|
}),
|
|
|
|
http.put('/api/admin/users/:id', async ({ params, request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
const user = buildUser({ id: Number(params.id), ...body });
|
|
return HttpResponse.json({ user });
|
|
}),
|
|
|
|
http.delete('/api/admin/users/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/admin/stats', () => {
|
|
return HttpResponse.json({
|
|
totalUsers: 2,
|
|
totalTrips: 5,
|
|
totalPlaces: 42,
|
|
totalFiles: 8,
|
|
});
|
|
}),
|
|
|
|
http.get('/api/admin/invites', () => {
|
|
return HttpResponse.json({ invites: [] });
|
|
}),
|
|
|
|
http.post('/api/admin/invites', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ invite: { id: 1, token: 'test-invite-token', ...body } });
|
|
}),
|
|
|
|
http.delete('/api/admin/invites/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/admin/oidc', () => {
|
|
return HttpResponse.json({
|
|
issuer: '',
|
|
client_id: '',
|
|
client_secret: '',
|
|
client_secret_set: false,
|
|
display_name: '',
|
|
oidc_only: false,
|
|
discovery_url: '',
|
|
});
|
|
}),
|
|
|
|
http.put('/api/admin/oidc', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ ...body });
|
|
}),
|
|
|
|
http.get('/api/admin/version-check', () => {
|
|
return HttpResponse.json({ update_available: false, latest: '1.0.0', current: '1.0.0' });
|
|
}),
|
|
|
|
http.get('/api/admin/bag-tracking', () => {
|
|
return HttpResponse.json({ enabled: false });
|
|
}),
|
|
|
|
http.put('/api/admin/bag-tracking', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/tours-wanderer', () => {
|
|
return HttpResponse.json({ enabled: false });
|
|
}),
|
|
|
|
http.put('/api/admin/tours-wanderer', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/tours-hiking-map', () => {
|
|
return HttpResponse.json({ enabled: true });
|
|
}),
|
|
|
|
http.put('/api/admin/tours-hiking-map', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/tours-ski-routing', () => {
|
|
return HttpResponse.json({ enabled: true });
|
|
}),
|
|
|
|
http.put('/api/admin/tours-ski-routing', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/addons', () => {
|
|
return HttpResponse.json({ addons: [] });
|
|
}),
|
|
|
|
http.get('/api/admin/packing-templates', () => {
|
|
return HttpResponse.json({ templates: [] });
|
|
}),
|
|
|
|
http.get('/api/admin/audit-log', () => {
|
|
return HttpResponse.json({ logs: [], total: 0 });
|
|
}),
|
|
|
|
http.get('/api/admin/mcp-tokens', () => {
|
|
return HttpResponse.json({ tokens: [] });
|
|
}),
|
|
|
|
http.get('/api/admin/oauth-sessions', () => {
|
|
return HttpResponse.json({ sessions: [] });
|
|
}),
|
|
|
|
http.delete('/api/admin/oauth-sessions/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.delete('/api/admin/mcp-tokens/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/admin/permissions', () => {
|
|
return HttpResponse.json({ permissions: {} });
|
|
}),
|
|
|
|
http.get('/api/admin/notification-preferences', () => {
|
|
return HttpResponse.json({
|
|
event_types: [],
|
|
available_channels: {},
|
|
implemented_combos: {},
|
|
preferences: {},
|
|
});
|
|
}),
|
|
|
|
// Auth settings endpoints used by AdminPage
|
|
http.get('/api/auth/app-settings', () => {
|
|
return HttpResponse.json({});
|
|
}),
|
|
|
|
http.put('/api/auth/app-settings', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ ...body });
|
|
}),
|
|
|
|
http.get('/api/auth/me/settings', () => {
|
|
return HttpResponse.json({ settings: { maps_api_key: '', openweather_api_key: '' } });
|
|
}),
|
|
|
|
http.get('/api/auth/validate-keys', () => {
|
|
return HttpResponse.json({ maps: true, weather: true });
|
|
}),
|
|
|
|
// The TREK API card's allowance panel, read whenever the settings tab renders it.
|
|
http.get('/api/admin/service-identity', () => {
|
|
return HttpResponse.json({ state: 'legacy', tier: 'legacy', keySource: null, services: [], lastSeenAt: null });
|
|
}),
|
|
];
|