fix(admin): prefer non-anonymized map locations
CI / validate (push) Successful in 6m9s
Release / release (push) Successful in 8m18s

This commit is contained in:
dmg
2026-08-07 18:36:59 -04:00
parent 6425a5056a
commit 20dfc58d63
5 changed files with 30 additions and 7 deletions
+2 -1
View File
@@ -5,7 +5,7 @@ import Link from "next/link";
import { UserWorldMap, type UserMapLocation } from "@/components/user-world-map";
import { db } from "@/lib/database";
import { fillDailySeries, mergeRiskActivity, type DailyCount } from "@/lib/admin-metrics";
import { parseUserLocation, parseUserNetwork } from "@/lib/user-location-map";
import { MAP_LOCATION_CLASSIFICATIONS, parseUserLocation, parseUserNetwork } from "@/lib/user-location-map";
export const dynamic = "force-dynamic";
@@ -58,6 +58,7 @@ export default async function AdminDashboardPage() {
))
.where(and(
isNotNull(ipObservations.userId),
inArray(ipIntelligence.classification, MAP_LOCATION_CLASSIFICATIONS),
sql`case when jsonb_typeof(${ipIntelligence.rawResponse}->'location'->'latitude') = 'number' then (${ipIntelligence.rawResponse}->'location'->>'latitude')::double precision between -90 and 90 else false end`,
sql`case when jsonb_typeof(${ipIntelligence.rawResponse}->'location'->'longitude') = 'number' then (${ipIntelligence.rawResponse}->'location'->>'longitude')::double precision between -180 and 180 else false end`,
))
+14 -1
View File
@@ -1,7 +1,20 @@
import { describe, expect, it } from "vitest";
import { groupMapLocations, parseUserLocation, parseUserNetwork, projectWorldPoint } from "./user-location-map";
import {
MAP_LOCATION_CLASSIFICATIONS,
groupMapLocations,
parseUserLocation,
parseUserNetwork,
projectWorldPoint,
} from "./user-location-map";
describe("user location map", () => {
it("allows only clear and hosting observations as map locations", () => {
expect(MAP_LOCATION_CLASSIFICATIONS).toEqual(["clear", "hosting"]);
expect(MAP_LOCATION_CLASSIFICATIONS).not.toContain("vpn");
expect(MAP_LOCATION_CLASSIFICATIONS).not.toContain("proxy");
expect(MAP_LOCATION_CLASSIFICATIONS).not.toContain("tor");
});
it("extracts a valid approximate location from cached IP intelligence", () => {
expect(parseUserLocation({
classification: "clear",
+2
View File
@@ -1,5 +1,7 @@
type UnknownMap = Record<string, unknown>;
export const MAP_LOCATION_CLASSIFICATIONS = ["clear", "hosting"] as const;
function objectValue(value: unknown): UnknownMap | null {
return value && typeof value === "object" && !Array.isArray(value)
? value as UnknownMap