From b834d1c282fe086df0803902e1c4142401aaf6bf Mon Sep 17 00:00:00 2001 From: KITAITI Makoto Date: Mon, 13 Apr 2020 00:36:00 +0900 Subject: [PATCH] Fix #701 Preferable default theme (#746) * Make it possible to update users.preferred_theme to NULL * Make preferred them null when 'Default theme' is selected * Run cargo fmt --- plume-models/src/users.rs | 1 + src/routes/user.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index d6c31f65..a8243d16 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -54,6 +54,7 @@ pub enum Role { } #[derive(Queryable, Identifiable, Clone, Debug, AsChangeset)] +#[changeset_options(treat_none_as_null = "true")] pub struct User { pub id: i32, pub username: String, diff --git a/src/routes/user.rs b/src/routes/user.rs index 2cc48302..2a952d1d 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -399,7 +399,10 @@ pub fn update( ) .0, ); - user.preferred_theme = form.theme.clone(); + user.preferred_theme = form + .theme + .clone() + .and_then(|t| if &t == "" { None } else { Some(t) }); user.hide_custom_css = form.hide_custom_css; let _: User = user.save_changes(&*conn).map_err(Error::from)?;