From 43e420b0ab2a51fe56ff1689598ad4cf6764f187 Mon Sep 17 00:00:00 2001 From: Hampus Date: Sun, 6 Sep 2026 18:40:50 +0200 Subject: [PATCH] fix(admin): require paired voice server coordinates (#2544) --- fluxer_admin/src/api/voice.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fluxer_admin/src/api/voice.rs b/fluxer_admin/src/api/voice.rs index d71db376d..d994fb2cf 100644 --- a/fluxer_admin/src/api/voice.rs +++ b/fluxer_admin/src/api/voice.rs @@ -102,6 +102,7 @@ impl AdminApiClient { params: &serde_json::Value, ) -> ApiResult { let region_id = required_field(params, "region_id")?; + paired_coordinates(params)?; let body = serde_json::from_value::(params.clone()) .map_err(|e| ApiError::Parse(e.to_string()))?; @@ -119,6 +120,7 @@ impl AdminApiClient { ) -> ApiResult { let region_id = required_field(params, "region_id")?; let server_id = required_field(params, "server_id")?; + paired_coordinates(params)?; let body = serde_json::from_value::(params.clone()) .map_err(|e| ApiError::Parse(e.to_string()))?; @@ -148,6 +150,17 @@ fn bool_param(value: bool) -> &'static str { if value { "true" } else { "false" } } +fn paired_coordinates(params: &serde_json::Value) -> ApiResult<()> { + let has_coordinate = |field: &str| params.get(field).is_some_and(|value| !value.is_null()); + if has_coordinate("latitude") == has_coordinate("longitude") { + Ok(()) + } else { + Err(ApiError::Parse( + "latitude and longitude must both be set or both be left empty".to_owned(), + )) + } +} + fn required_field(params: &serde_json::Value, field: &str) -> ApiResult { params .get(field)