Skip to content

Commit

Permalink
fix: return default logo if empty (#519)
Browse files Browse the repository at this point in the history
* fix: ensure to return default logo

* cleanup

---------

Co-authored-by: Maciek <[email protected]>
Co-authored-by: Maciej Wójcik <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent b3ea027 commit e5fe26e
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/handlers/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppState>) -> 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,
})
}
Expand All @@ -42,7 +56,13 @@ pub async fn update_settings(

pub async fn get_settings_essentials(State(appstate): State<AppState>) -> 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),
Expand All @@ -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",
Expand Down Expand Up @@ -97,7 +117,7 @@ pub async fn patch_settings(
pub async fn test_ldap_settings(_admin: AdminRole, State(appstate): State<AppState>) -> 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,
Expand Down

0 comments on commit e5fe26e

Please sign in to comment.