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..7bee53ee 100644 --- a/src-tauri/src/database/models/location.rs +++ b/src-tauri/src/database/models/location.rs @@ -93,7 +93,8 @@ 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_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,\ @@ -101,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 @@ -163,7 +164,8 @@ 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_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, \ @@ -171,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 @@ -228,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 { 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;