From 064dd79eef1b281c4e9316c93e8e2d0ffba02813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 20 Aug 2019 12:24:36 +0200 Subject: [PATCH] Allow editing blogs with custom_domain n.b.: no validation yet --- plume-models/src/blogs.rs | 12 +++++++++++- src/routes/blogs.rs | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 5baf85b5..728f4dec 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -8,8 +8,9 @@ use openssl::{ sign::{Signer, Verifier}, }; use rocket::{ + http::RawStr, outcome::IntoOutcome, - request::{self, FromRequest, Request}, + request::{self, FromFormValue, FromRequest, Request}, }; use serde_json; use url::Url; @@ -71,6 +72,15 @@ impl<'a, 'r> FromRequest<'a, 'r> for Host { } } +impl<'v> FromFormValue<'v> for Host { + type Error = &'v RawStr; + + fn from_form_value(form_value: &'v RawStr) -> std::result::Result { + let val = String::from_form_value(form_value)?; + Ok(Host::new(&val)) + } +} + #[derive(Queryable, Identifiable, Clone, AsChangeset)] #[changeset_options(treat_none_as_null = "true")] pub struct Blog { diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 6cbcd460..e58c859b 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -333,6 +333,7 @@ pub struct EditForm { pub summary: String, pub icon: Option, pub banner: Option, + pub custom_domain: Option, } #[get("/~//edit")] @@ -359,6 +360,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(), }, ValidationErrors::default() )))