From 3c4abcff81db43ced49b5ac9144fbd583d5a1ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Wed, 21 Aug 2019 11:09:42 +0200 Subject: [PATCH] Allow updating of custom_domain --- plume-models/Cargo.toml | 1 - plume-models/src/blogs.rs | 11 ++++++++++- plume-models/src/lib.rs | 2 -- src/routes/blogs.rs | 12 ++++++++++-- templates/blogs/edit.rs.html | 2 ++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/plume-models/Cargo.toml b/plume-models/Cargo.toml index 436d67b4..8889d889 100644 --- a/plume-models/Cargo.toml +++ b/plume-models/Cargo.toml @@ -25,7 +25,6 @@ tantivy = "0.10.1" url = "2.1" webfinger = "0.4.1" whatlang = "0.7.1" -shrinkwraprs = "0.2.1" diesel-derive-newtype = "0.1.2" [dependencies.chrono] diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 728f4dec..67664658 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -26,14 +26,16 @@ use posts::Post; use safe_string::SafeString; use schema::blogs; use search::Searcher; +use std::default::Default; use std::fmt::{self, Display}; +use std::ops::Deref; use std::sync::RwLock; use users::User; use {Connection, Error, PlumeRocket, Result}; pub type CustomGroup = CustomObject; -#[derive(Clone, Debug, PartialEq, DieselNewType, Shrinkwrap)] +#[derive(Clone, Debug, PartialEq, DieselNewType)] pub struct Host(String); impl Host { @@ -42,6 +44,13 @@ impl Host { } } +impl Deref for Host { + type Target = str; + fn deref(&self) -> &str { + &self.0 + } +} + impl Display for Host { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index 5ed0cf3d..e43c19c0 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -33,8 +33,6 @@ extern crate serde_derive; #[macro_use] extern crate serde_json; #[macro_use] -extern crate shrinkwraprs; -#[macro_use] extern crate tantivy; extern crate url; extern crate webfinger; diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index e94c9fda..4716bafd 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -333,7 +333,7 @@ pub struct EditForm { pub summary: String, pub icon: Option, pub banner: Option, - pub custom_domain: Option, + pub custom_domain: String, } #[get("/~//edit")] @@ -351,6 +351,10 @@ pub fn edit(name: String, rockets: PlumeRocket) -> Result { .clone() .expect("blogs::edit: User was None while it shouldn't"); let medias = Media::for_user(conn, user.id).expect("Couldn't list media"); + let custom_domain = match blog.custom_domain { + Some(ref c) => c.to_string(), + _ => String::from(""), + }; Ok(render!(blogs::edit( &rockets.to_context(), &blog, @@ -360,7 +364,7 @@ pub fn edit(name: String, rockets: PlumeRocket) -> Result { summary: blog.summary.clone(), icon: blog.icon_id, banner: blog.banner_id, - custom_domain: blog.custom_domain.clone(), + custom_domain: custom_domain, }, ValidationErrors::default() ))) @@ -472,6 +476,10 @@ pub fn update( ); blog.icon_id = form.icon; blog.banner_id = form.banner; + if !form.custom_domain.is_empty() { + blog.custom_domain = Some(Host::new(form.custom_domain.clone())) + } + blog.save_changes::(&*conn) .expect("Couldn't save blog changes"); Ok(Flash::success( diff --git a/templates/blogs/edit.rs.html b/templates/blogs/edit.rs.html index dfa7f44f..fa988cb0 100644 --- a/templates/blogs/edit.rs.html +++ b/templates/blogs/edit.rs.html @@ -23,6 +23,8 @@ + @input!(ctx.1, custom_domain (optional text), "Custom Domain", form, errors, "") +

@i18n!(ctx.1, "You can upload images to your gallery, to use them as blog icons, or banners.") @i18n!(ctx.1, "Upload images")