Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return default logo if empty #519

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading