From 90ac1854ce4255897cbd4a2017e96ac628a545b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Ciarcin=CC=81ski?= Date: Mon, 16 Mar 2026 12:35:36 +0100 Subject: [PATCH] Bug fixes --- .../src/enterprise/db/models/snat.rs | 36 ++++++++++--------- .../src/enterprise/snat/handlers.rs | 3 +- .../defguard_gateway_manager/src/handler.rs | 9 +++-- .../AssignUserDeviceIPModal.tsx | 2 +- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/crates/defguard_core/src/enterprise/db/models/snat.rs b/crates/defguard_core/src/enterprise/db/models/snat.rs index c4ae69fc8e..033052cb22 100644 --- a/crates/defguard_core/src/enterprise/db/models/snat.rs +++ b/crates/defguard_core/src/enterprise/db/models/snat.rs @@ -32,7 +32,7 @@ impl UserSnatBinding { } impl UserSnatBinding { - pub async fn find_binding<'e, E>( + pub(crate) async fn find_binding<'e, E>( executor: E, location_id: Id, user_id: Id, @@ -40,30 +40,32 @@ impl UserSnatBinding { where E: PgExecutor<'e>, { - let binding = query_as!(Self, - "SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" FROM user_snat_binding WHERE location_id = $1 AND user_id = $2", - location_id, user_id - ).fetch_one(executor).await?; + let binding = query_as!( + Self, + "SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" \ + FROM user_snat_binding WHERE location_id = $1 AND user_id = $2", + location_id, + user_id + ) + .fetch_one(executor) + .await?; Ok(binding) } - pub async fn all_for_location<'e, E>( - executor: E, - location_id: Id, - ) -> Result, sqlx::Error> + pub async fn all_for_location<'e, E>(executor: E, location_id: Id) -> sqlx::Result> where E: PgExecutor<'e>, { - let bindings = query_as!(Self, - "SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" FROM user_snat_binding WHERE location_id = $1", - location_id - ).fetch_all(executor).await?; + let bindings = query_as!( + Self, + "SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" \ + FROM user_snat_binding WHERE location_id = $1", + location_id + ) + .fetch_all(executor) + .await?; Ok(bindings) } - - pub fn update_ip(&mut self, new_public_ip: IpAddr) { - self.public_ip = new_public_ip; - } } diff --git a/crates/defguard_core/src/enterprise/snat/handlers.rs b/crates/defguard_core/src/enterprise/snat/handlers.rs index f0552c3938..9c510a9771 100644 --- a/crates/defguard_core/src/enterprise/snat/handlers.rs +++ b/crates/defguard_core/src/enterprise/snat/handlers.rs @@ -236,8 +236,7 @@ pub async fn modify_snat_binding( // clone state before modifications let before = snat_binding.clone(); - // update public IP - snat_binding.update_ip(data.public_ip); + snat_binding.public_ip = data.public_ip; snat_binding.save(&appstate.pool).await?; // emit event diff --git a/crates/defguard_gateway_manager/src/handler.rs b/crates/defguard_gateway_manager/src/handler.rs index ce705fdb5c..e10a012959 100644 --- a/crates/defguard_gateway_manager/src/handler.rs +++ b/crates/defguard_gateway_manager/src/handler.rs @@ -9,13 +9,11 @@ use std::{ }; use chrono::DateTime; -#[cfg(not(test))] -use defguard_common::db::models::Settings; use defguard_common::{ VERSION, db::{ Id, - models::{WireguardNetwork, gateway::Gateway, wireguard::DEFAULT_WIREGUARD_MTU}, + models::{Settings, WireguardNetwork, gateway::Gateway, wireguard::DEFAULT_WIREGUARD_MTU}, }, messages::peer_stats_update::PeerStatsUpdate, }; @@ -168,6 +166,11 @@ impl GatewayHandler { /// Send gateway disconnected notification. /// Sends notification only if last notification time is bigger than specified in config. async fn send_disconnect_notification(&self) { + let settings = Settings::get_current_settings(); + if !settings.gateway_disconnect_notifications_enabled { + return; + } + debug!("Sending gateway disconnect email notification"); let name = self.gateway.name.clone(); let pool = self.pool.clone(); diff --git a/web/src/shared/components/modals/AssignUserDeviceIPModal/AssignUserDeviceIPModal.tsx b/web/src/shared/components/modals/AssignUserDeviceIPModal/AssignUserDeviceIPModal.tsx index 11e1b0f7c8..83c263f7ef 100644 --- a/web/src/shared/components/modals/AssignUserDeviceIPModal/AssignUserDeviceIPModal.tsx +++ b/web/src/shared/components/modals/AssignUserDeviceIPModal/AssignUserDeviceIPModal.tsx @@ -237,7 +237,7 @@ const AssignmentForm = ({ form.handleSubmit(), }} cancelProps={{