Check for existing slug before creating a new blog

Fix #63
This commit is contained in:
Bat 2018-06-19 19:40:20 +01:00
parent e8d62e150a
commit 1653a3ac74

View File

@ -59,21 +59,25 @@ fn create(conn: DbConn, data: Form<NewBlogForm>, user: User) -> Redirect {
let form = data.get(); let form = data.get();
let slug = utils::make_actor_id(form.title.to_string()); let slug = utils::make_actor_id(form.title.to_string());
let blog = Blog::insert(&*conn, NewBlog::new_local( if Blog::find_local(&*conn, slug.clone()).is_some() {
slug.to_string(), Redirect::to(uri!(new))
form.title.to_string(), } else {
String::from(""), let blog = Blog::insert(&*conn, NewBlog::new_local(
Instance::local_id(&*conn) slug.to_string(),
)); form.title.to_string(),
blog.update_boxes(&*conn); String::from(""),
Instance::local_id(&*conn)
));
blog.update_boxes(&*conn);
BlogAuthor::insert(&*conn, NewBlogAuthor { BlogAuthor::insert(&*conn, NewBlogAuthor {
blog_id: blog.id, blog_id: blog.id,
author_id: user.id, author_id: user.id,
is_owner: true is_owner: true
}); });
Redirect::to(format!("/~/{}/", slug)) Redirect::to(format!("/~/{}/", slug))
}
} }
#[get("/~/<name>/outbox")] #[get("/~/<name>/outbox")]