diff --git a/src/handlers/settings.rs b/src/handlers/settings.rs index bcf633700..118531784 100644 --- a/src/handlers/settings.rs +++ b/src/handlers/settings.rs @@ -17,12 +17,26 @@ use crate::{ AppState, }; +static DEFAULT_NAV_LOGO_URL: &str = "/svg/defguard-nav-logo.svg"; +static DEFAULT_MAIN_LOGO_URL: &str = "/svg/logo-defguard-white.svg"; + pub async fn get_settings(State(appstate): State) -> ApiResult { debug!("Retrieving settings"); - let settings = Settings::find_by_id(&appstate.pool, 1).await?; - info!("Retrieved settings"); + if let Some(mut settings) = Settings::find_by_id(&appstate.pool, 1).await? { + if settings.nav_logo_url.is_empty() { + settings.nav_logo_url = DEFAULT_NAV_LOGO_URL.into(); + } + if settings.main_logo_url.is_empty() { + settings.main_logo_url = DEFAULT_MAIN_LOGO_URL.into(); + } + return Ok(ApiResponse { + json: json!(settings), + status: StatusCode::OK, + }); + } + debug!("Retrieved settings"); Ok(ApiResponse { - json: json!(settings), + json: json!({}), status: StatusCode::OK, }) } @@ -42,7 +56,13 @@ pub async fn update_settings( pub async fn get_settings_essentials(State(appstate): State) -> ApiResult { debug!("Retrieving essential settings"); - let settings = SettingsEssentials::get_settings_essentials(&appstate.pool).await?; + let mut settings = SettingsEssentials::get_settings_essentials(&appstate.pool).await?; + if settings.nav_logo_url.is_empty() { + settings.nav_logo_url = DEFAULT_NAV_LOGO_URL.into(); + } + if settings.main_logo_url.is_empty() { + settings.main_logo_url = DEFAULT_MAIN_LOGO_URL.into(); + } info!("Retrieved essential settings"); Ok(ApiResponse { json: json!(settings), @@ -64,8 +84,8 @@ pub async fn set_default_branding( match settings { Some(mut settings) => { settings.instance_name = "Defguard".into(); - settings.nav_logo_url = "/svg/defguard-nav-logo.svg".into(); - settings.main_logo_url = "/svg/logo-defguard-white.svg".into(); + settings.nav_logo_url = DEFAULT_NAV_LOGO_URL.into(); + settings.main_logo_url = DEFAULT_MAIN_LOGO_URL.into(); settings.save(&appstate.pool).await?; info!( "User {} restored default branding settings", @@ -97,7 +117,7 @@ pub async fn patch_settings( pub async fn test_ldap_settings(_admin: AdminRole, State(appstate): State) -> ApiResult { debug!("Testing LDAP connection"); if LDAPConnection::create(&appstate.pool).await.is_ok() { - debug!("LDAP connected succesfully"); + debug!("LDAP connected successfully"); Ok(ApiResponse { json: json!({}), status: StatusCode::OK,