fix(admin): prefer non-anonymized map locations
This commit is contained in:
@@ -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`,
|
||||
))
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user