fix(admin): read a geolocation provider the operator named as a decision, not a warning

This commit is contained in:
Marc-André Bombeck committed 2026-10-09 08:38:58 +02:00
1 parent 88836452eb
commit 0a6811c03f
16 files changed
+157 -14

No files matched your search

@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";
import { geoLookupState, type PublicVersion } from "../_shared";
const base: PublicVersion = {
version: "1.42.0",
buildSha: null,
builtAt: null,
};
describe("geoLookupState", () => {
it("warns only about the unconfigured default provider", () => {
expect(
geoLookupState({
...base,
offlineGeoEnabled: false,
geoLookup: "online",
}),
).toBe("default");
});
it("treats a provider the operator named as a decision", () => {
expect(
geoLookupState({
...base,
offlineGeoEnabled: false,
geoLookup: "online",
geoProviderChosen: true,
}),
).toBe("chosen");
});
it("reads a switched-off lookup and the offline databases as settled", () => {
expect(
geoLookupState({ ...base, offlineGeoEnabled: false, geoLookup: "off" }),
).toBe("off");
expect(geoLookupState({ ...base, offlineGeoEnabled: true })).toBe(
"offline",
);
});
});
+17
View File
@@ -590,6 +590,23 @@ export interface PublicVersion {
// offline tier is absent (host of IP_GEO_LOOKUP_URL, default ipwho.is).
// Optional so legacy /api/version responses still satisfy the shape.
geoProviderHost?: string;
/** v1.42 — `offline`, `online` or `off` (IP_GEO_LOOKUP_DISABLED). */
geoLookup?: "offline" | "online" | "off";
/** v1.42 — the operator named the provider in IP_GEO_LOOKUP_URL. */
geoProviderChosen?: boolean;
}
/**
* The geo row's state. Offline, switched off, or a provider the operator
* named are all decisions and read as fine; only the unconfigured default
* warns, because it sends every login IP to a third party nobody chose.
*/
export function geoLookupState(
version: PublicVersion,
): "offline" | "off" | "chosen" | "default" {
if (version.offlineGeoEnabled) return "offline";
if (version.geoLookup === "off") return "off";
return version.geoProviderChosen ? "chosen" : "default";
}
/** Shared `/api/version` reader — the system-status section + overview
+14 -6
View File
@@ -23,6 +23,7 @@ import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { useFormatters, useTranslations } from "@/lib/i18n/context";
import {
geoLookupState,
StatusItem,
usePublicVersion,
useSystemStatus,
@@ -245,13 +246,20 @@ export function SystemStatusSection() {
icon={Map}
label={t("admin.offlineGeoLabel")}
value={
version.offlineGeoEnabled
? t("admin.offlineGeoEnabled")
: t("admin.offlineGeoFallback", {
host: version.geoProviderHost ?? "ipwho.is",
})
{
offline: t("admin.offlineGeoEnabled"),
off: t("admin.offlineGeoOff"),
chosen: t("admin.offlineGeoChosen", {
host: version.geoProviderHost ?? "ipwho.is",
}),
default: t("admin.offlineGeoFallback", {
host: version.geoProviderHost ?? "ipwho.is",
}),
}[geoLookupState(version)]
}
tone={
geoLookupState(version) === "default" ? "warning" : "success"
}
tone={version.offlineGeoEnabled ? "success" : "warning"}
/>
)}
</div>
+19 -7
View File
@@ -26,7 +26,12 @@ import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { QueryErrorRow } from "@/components/ui/query-error-row";
import { useTranslations } from "@/lib/i18n/context";
import { StatusItem, usePublicVersion, useSystemStatus } from "./_shared";
import {
geoLookupState,
StatusItem,
usePublicVersion,
useSystemStatus,
} from "./_shared";
import { useKeyBackupStatus } from "./use-key-backup-status";
export function SystemStatusSummary() {
@@ -95,13 +100,20 @@ export function SystemStatusSummary() {
icon={Globe}
label={t("admin.overview.snapshotOfflineGeo")}
value={
version.offlineGeoEnabled
? t("admin.overview.snapshotOfflineGeoOn")
: t("admin.overview.snapshotOfflineGeoOff", {
host: version.geoProviderHost ?? "ipwho.is",
})
{
offline: t("admin.overview.snapshotOfflineGeoOn"),
off: t("admin.offlineGeoOff"),
chosen: t("admin.offlineGeoChosen", {
host: version.geoProviderHost ?? "ipwho.is",
}),
default: t("admin.overview.snapshotOfflineGeoOff", {
host: version.geoProviderHost ?? "ipwho.is",
}),
}[geoLookupState(version)]
}
tone={
geoLookupState(version) === "default" ? "warning" : "success"
}
tone={version.offlineGeoEnabled ? "success" : "warning"}
/>
)}
</div>