From 17150369d822231b288d7bb6b6b7cbadf20ec988 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:44:16 +0100 Subject: [PATCH 1/3] fix --- src-tauri/src/commands.rs | 8 +++++++- src-tauri/src/database/models/location.rs | 12 ++++++++++-- src-tauri/src/service/mod.rs | 6 ++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 561c4638..8f050e5b 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -977,7 +977,13 @@ pub async fn delete_instance(instance_id: Id, handle: AppHandle) -> Result<(), E instance_id: instance.uuid.clone(), }) .await - .unwrap(); + .map_err(|err| { + error!( + "Error while deleting service locations from the daemon for instance {}({}): {err}", + instance.name, instance.id, + ); + Error::InternalError(err.to_string()) + })?; reload_tray_menu(&handle).await; diff --git a/src-tauri/src/database/models/location.rs b/src-tauri/src/database/models/location.rs index 005b5fdb..deceaa2e 100644 --- a/src-tauri/src/database/models/location.rs +++ b/src-tauri/src/database/models/location.rs @@ -93,7 +93,11 @@ impl Location { where E: SqliteExecutor<'e>, { - let max_mode = if include_service_locations { 2 } else { 0 }; // 0 to exclude service locations, 2 to include them + let max_mode = if include_service_locations { + ServiceLocationMode::AlwaysOn as i32 + } else { + ServiceLocationMode::Disabled as i32 + }; query_as!( Self, "SELECT id, instance_id, name, address, pubkey, endpoint, allowed_ips, dns, network_id,\ @@ -163,7 +167,11 @@ impl Location { where E: SqliteExecutor<'e>, { - let max_mode = if include_service_locations { 2 } else { 0 }; // 0 to exclude service locations, 2 to include them + let max_mode = if include_service_locations { + ServiceLocationMode::AlwaysOn as i32 + } else { + ServiceLocationMode::Disabled as i32 + }; query_as!( Self, "SELECT id \"id: _\", instance_id, name, address, pubkey, endpoint, allowed_ips, dns, \ diff --git a/src-tauri/src/service/mod.rs b/src-tauri/src/service/mod.rs index c4de34ea..09f1600c 100644 --- a/src-tauri/src/service/mod.rs +++ b/src-tauri/src/service/mod.rs @@ -50,10 +50,12 @@ use tracing::{debug, error, info, info_span, Instrument}; use self::config::Config; use super::VERSION; -use crate::enterprise::service_locations::ServiceLocationError; #[cfg(windows)] use crate::enterprise::service_locations::ServiceLocationManager; -use crate::service::proto::{DeleteServiceLocationsRequest, SaveServiceLocationsRequest}; +use crate::{ + enterprise::service_locations::ServiceLocationError, + service::proto::{DeleteServiceLocationsRequest, SaveServiceLocationsRequest}, +}; #[cfg(windows)] const DAEMON_HTTP_PORT: u16 = 54127; From bcd90bdc411c3a210720827b5a6d3da1406717ba Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:19:31 +0100 Subject: [PATCH 2/3] extract to function --- src-tauri/src/database/models/location.rs | 30 +++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src-tauri/src/database/models/location.rs b/src-tauri/src/database/models/location.rs index deceaa2e..aae76b56 100644 --- a/src-tauri/src/database/models/location.rs +++ b/src-tauri/src/database/models/location.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::{fmt, i32}; use serde::{Deserialize, Serialize}; use sqlx::{prelude::Type, query, query_as, query_scalar, Error as SqlxError, SqliteExecutor}; @@ -93,11 +93,8 @@ impl Location { where E: SqliteExecutor<'e>, { - let max_mode = if include_service_locations { - ServiceLocationMode::AlwaysOn as i32 - } else { - ServiceLocationMode::Disabled as i32 - }; + let max_service_location_mode = + Self::get_service_location_mode_filter(include_service_locations); query_as!( Self, "SELECT id, instance_id, name, address, pubkey, endpoint, allowed_ips, dns, network_id,\ @@ -105,7 +102,7 @@ impl Location { location_mfa_mode \"location_mfa_mode: LocationMfaMode\", service_location_mode \"service_location_mode: ServiceLocationMode\" \ FROM location WHERE service_location_mode <= $1 \ ORDER BY name ASC;", - max_mode + max_service_location_mode ) .fetch_all(executor) .await @@ -167,11 +164,8 @@ impl Location { where E: SqliteExecutor<'e>, { - let max_mode = if include_service_locations { - ServiceLocationMode::AlwaysOn as i32 - } else { - ServiceLocationMode::Disabled as i32 - }; + let max_service_location_mode = + Self::get_service_location_mode_filter(include_service_locations); query_as!( Self, "SELECT id \"id: _\", instance_id, name, address, pubkey, endpoint, allowed_ips, dns, \ @@ -179,7 +173,7 @@ impl Location { FROM location WHERE instance_id = $1 AND service_location_mode <= $2 \ ORDER BY name ASC", instance_id, - max_mode + max_service_location_mode ) .fetch_all(executor) .await @@ -236,6 +230,16 @@ impl Location { LocationMfaMode::Internal | LocationMfaMode::External => true, } } + + /// Returns a filter value that can be used in SQL queries like `service_location_mode <= ?` when querying locations + /// to exclude (<= 1) or include service locations (all service locations modes). + fn get_service_location_mode_filter(include_service_locations: bool) -> i32 { + if include_service_locations { + i32::MAX + } else { + ServiceLocationMode::Disabled as i32 + } + } } impl Location { From 53f519a738be0cad48a00f112f3634bc46c96ed3 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:31:36 +0100 Subject: [PATCH 3/3] fix --- src-tauri/src/database/models/location.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/database/models/location.rs b/src-tauri/src/database/models/location.rs index aae76b56..7bee53ee 100644 --- a/src-tauri/src/database/models/location.rs +++ b/src-tauri/src/database/models/location.rs @@ -1,4 +1,4 @@ -use std::{fmt, i32}; +use std::fmt; use serde::{Deserialize, Serialize}; use sqlx::{prelude::Type, query, query_as, query_scalar, Error as SqlxError, SqliteExecutor};