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

feature: custom domains using Fairings #596

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6bcc4f0
add custom_domain (default to NULL) to schema
igalic May 22, 2019
92bbeeb
add Host(String) wrapper type
igalic May 24, 2019
65ae51b
implement Host more completely by doing less
igalic May 25, 2019
351c01f
list custom_domains
igalic May 25, 2019
3a4c2f2
create & attach an AdHoc Fairing for dealing with Custom Domains
igalic May 26, 2019
2746e08
appease clippy
igalic May 26, 2019
e6747de
cache custom_domains list
igalic May 26, 2019
b09b51c
normalize URLs before setting them
igalic May 27, 2019
f94b0c7
move impl closer to mother struct
igalic May 27, 2019
0645f7e
CustomDomainFairing must not match /static/ and /api/
igalic May 27, 2019
468e663
Add custom_details and custom_activity_details as first routes
igalic May 27, 2019
1c34ac3
replace if / else with ok_or()
igalic May 27, 2019
8e6b1ab
simplify retrieval in find_by_host()
igalic May 28, 2019
a0aef50
extract common routing code into private "_guts()" functions
igalic May 28, 2019
6253adf
simplify / unify error handling
igalic May 28, 2019
92fbd17
extend 404 handler to handle all the requests our custom_ routes dont
igalic May 28, 2019
8e7f789
Allow searching from custom_domain
igalic May 30, 2019
9cee38a
add url to Blog, this seems useful.
igalic May 31, 2019
cc0df4e
redirect blog urls to custom_domain if it exists
igalic Jun 14, 2019
fe110b5
fix issues pointed out by @BaptisteGelez in review
igalic Jun 15, 2019
f73fba5
custom_domainify posts::details
igalic Jul 10, 2019
203da23
follow up on @fdb-hiroshima & @BaptisteGelez review
igalic Jul 12, 2019
7139119
add url! macro for custom domain path uri creation
trinity-1686a Jul 14, 2019
f635dcf
move custom_ route functions into a custom namespace
igalic Jul 14, 2019
cdc919e
allow more syntaxes for url
trinity-1686a Jul 14, 2019
6cd8bd8
fix syntax: we're now down to type errors
igalic Jul 21, 2019
c5f6b88
make url! work better
trinity-1686a Jul 22, 2019
b172a80
finally fix url!
trinity-1686a Jul 22, 2019
2dedcdb
start modifying /blogs/new to add custom_domain to the form
igalic Jul 30, 2019
fdc7da0
Strings have to be cloned
elegaanz Jul 31, 2019
6027012
fix clippy warning
igalic Jul 31, 2019
da6757c
Basic domain validation
elegaanz Jul 31, 2019
ff0c82e
review by @fdb-hiroshima
igalic Aug 1, 2019
bf1673d
start exploring some ideas for domain validation
igalic Aug 14, 2019
ed30284
implement domain validation using rocket::State
igalic Aug 15, 2019
444a467
correctly mutex-lock and modify valid_domains
igalic Aug 19, 2019
6072351
one step closer to validating custom domains!
igalic Aug 19, 2019
5e46922
validate custom domain!
igalic Aug 19, 2019
38ece9b
do not panic if reqwest does not work
igalic Aug 20, 2019
f67ce93
fix getter router for domain_validation!
igalic Aug 20, 2019
df47cdd
also mount domain_validation into /custom_domains/
igalic Aug 20, 2019
064dd79
Allow editing blogs with custom_domain
igalic Aug 20, 2019
1694698
use Custom status code
igalic Aug 20, 2019
768f126
use Status::* as @fdb-hiroshima suggested
igalic Aug 20, 2019
df7adaf
when building links, skip both, /custom_domain/ and <custom_domain>
igalic Aug 20, 2019
f395c10
fix mount point for blog post routing function
igalic Aug 20, 2019
d242e6d
restore df7adaf0e067802daf3e83935cf9140fb15ca17b ← after fixing mount…
igalic Aug 20, 2019
3c4abcf
Allow updating of custom_domain
igalic Aug 21, 2019
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
1 change: 0 additions & 1 deletion plume-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 10 additions & 1 deletion plume-models/src/blogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApSignature, Group>;

#[derive(Clone, Debug, PartialEq, DieselNewType, Shrinkwrap)]
#[derive(Clone, Debug, PartialEq, DieselNewType)]
pub struct Host(String);

impl Host {
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions plume-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/routes/blogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ pub struct EditForm {
pub summary: String,
pub icon: Option<i32>,
pub banner: Option<i32>,
pub custom_domain: Option<Host>,
pub custom_domain: String,
}

#[get("/~/<name>/edit")]
Expand All @@ -351,6 +351,10 @@ pub fn edit(name: String, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
.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(""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a quite personal opinion, but I think blog.custom_domain.map(ToString::to_string).unwrap_or_default() is more explicit (but, yes, it is only my opinion, maybe it is not).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another question might be: why were you able to use Option<String> for theme in EditForm but i have to use String here?

};
Ok(render!(blogs::edit(
&rockets.to_context(),
&blog,
Expand All @@ -360,7 +364,7 @@ pub fn edit(name: String, rockets: PlumeRocket) -> Result<Ructe, ErrorPage> {
summary: blog.summary.clone(),
icon: blog.icon_id,
banner: blog.banner_id,
custom_domain: blog.custom_domain.clone(),
custom_domain: custom_domain,
},
ValidationErrors::default()
)))
Expand Down Expand Up @@ -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::<Blog>(&*conn)
.expect("Couldn't save blog changes");
Ok(Flash::success(
Expand Down
2 changes: 2 additions & 0 deletions templates/blogs/edit.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ <h1>@i18n!(ctx.1, "Edit \"{}\""; &blog.title)</h1>
<label for="summary">@i18n!(ctx.1, "Description")<small>@i18n!(ctx.1, "Markdown syntax is supported")</small></label>
<textarea id="summary" name="summary" rows="20">@form.summary</textarea>

@input!(ctx.1, custom_domain (optional text), "Custom Domain", form, errors, "")

<p>
@i18n!(ctx.1, "You can upload images to your gallery, to use them as blog icons, or banners.")
<a href="@uri!(medias::new)">@i18n!(ctx.1, "Upload images")</a>
Expand Down