From 68a041711cec27698e8282f6f49e4181d4f7815b Mon Sep 17 00:00:00 2001 From: Bat Date: Wed, 27 Jun 2018 00:19:18 +0200 Subject: [PATCH] We can't mix GET and POST (in the comment form) in_response_to was always null --- plume-models/src/lib.rs | 4 +++- po/en.po | 10 ++++++---- po/fr.po | 13 +++++++++---- po/pl.po | 12 ++++++++---- src/main.rs | 1 - src/routes/comments.rs | 14 ++------------ src/routes/posts.rs | 6 +++++- templates/posts/details.html.tera | 3 +++ 8 files changed, 36 insertions(+), 27 deletions(-) diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index 5df9c8af..5d15fc2c 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -77,7 +77,9 @@ sql_function!(setval, setval_t, (seq: ::diesel::sql_types::Text, val: ::diesel:: fn get_next_id(conn: &PgConnection, seq: &str) -> i32 { // We cant' use currval because it may fail if nextval have never been called before let next = select(nextval(seq)).get_result::(conn).expect("Next ID fail"); - select(setval(seq, next - 1)).get_result::(conn).expect("Reset ID fail"); + if next > 1 { + select(setval(seq, next - 1)).get_result::(conn).expect("Reset ID fail"); + } next as i32 } diff --git a/po/en.po b/po/en.po index 80ceeabd..8f35e7d6 100644 --- a/po/en.po +++ b/po/en.po @@ -60,13 +60,15 @@ msgstr "" msgid "Let's go!" msgstr "" -msgid "Welcome on {{ instance_name }}" +#, fuzzy +msgid "Welcome on {{ instance_name | escape }}" msgstr "Welcome on {{ instance_name }}" msgid "Notifications" msgstr "" -msgid "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" +msgid "" +"Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" msgstr "" msgid "This article is under the {{ license }} license." @@ -184,7 +186,7 @@ msgid "Update account" msgstr "" #, fuzzy -msgid "{{ name }}'s followers" +msgid "{{ name | escape }}'s followers" msgstr "One follower" #, fuzzy @@ -254,7 +256,7 @@ msgstr "" msgid "You need to be logged in order to edit your profile" msgstr "" -msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" +msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" msgstr "" msgid "{{ data }} reshared your article" diff --git a/po/fr.po b/po/fr.po index a38c24ec..b256a813 100644 --- a/po/fr.po +++ b/po/fr.po @@ -62,13 +62,16 @@ msgstr "Nom" msgid "Let's go!" msgstr "C'est parti !" -msgid "Welcome on {{ instance_name }}" +#, fuzzy +msgid "Welcome on {{ instance_name | escape }}" msgstr "Bienvenue sur {{ instance_name }}" msgid "Notifications" msgstr "Notifications" -msgid "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" +#, fuzzy +msgid "" +"Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" msgstr "Écrit par {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" msgid "This article is under the {{ license }} license." @@ -184,7 +187,8 @@ msgstr "Description" msgid "Update account" msgstr "Mettre à jour mes informations" -msgid "{{ name }}'s followers" +#, fuzzy +msgid "{{ name | escape }}'s followers" msgstr "{{ count }} abonné⋅e" msgid "Followers" @@ -253,7 +257,8 @@ msgstr "Vous devez vous connecter pour suivre quelqu'un" msgid "You need to be logged in order to edit your profile" msgstr "Vous devez vous connecter pour modifier votre profil" -msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" +#, fuzzy +msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" msgstr "De {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" msgid "{{ data }} reshared your article" diff --git a/po/pl.po b/po/pl.po index 5f0d98e6..d965d0c2 100644 --- a/po/pl.po +++ b/po/pl.po @@ -63,13 +63,16 @@ msgstr "Nazwa" msgid "Let's go!" msgstr "Przejdźmy dalej!" -msgid "Welcome on {{ instance_name }}" +#, fuzzy +msgid "Welcome on {{ instance_name | escape }}" msgstr "Witamy na {{ instance_name }}" msgid "Notifications" msgstr "Powiadomienia" -msgid "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" +#, fuzzy +msgid "" +"Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" msgstr "Napisano przez {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" msgid "This article is under the {{ license }} license." @@ -188,7 +191,8 @@ msgstr "Opis" msgid "Update account" msgstr "Aktualizuj konto" -msgid "{{ name }}'s followers" +#, fuzzy +msgid "{{ name | escape }}'s followers" msgstr "Osoby śledzące {{ name }}" msgid "Followers" @@ -258,7 +262,7 @@ msgid "You need to be logged in order to edit your profile" msgstr "Musisz się zalogować , aby móc edytować swój profil" #, fuzzy -msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name }}{{ link_4 }}" +msgid "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" msgstr "Napisano przez {{ link_1 }}{{ url }}{{ link_2 }}{{ name }}{{ link_3 }}" msgid "{{ data }} reshared your article" diff --git a/src/main.rs b/src/main.rs index ab54ad59..6d55a5dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,6 @@ fn main() { routes::blogs::create, routes::comments::create, - routes::comments::create_response, routes::instance::index, routes::instance::shared_inbox, diff --git a/src/routes/comments.rs b/src/routes/comments.rs index 3387f4b9..232b4dbe 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -15,31 +15,21 @@ use plume_models::{ }; use inbox::Inbox; -#[derive(FromForm)] -pub struct CommentQuery { - pub responding_to: Option -} - #[derive(FromForm)] struct NewCommentForm { + pub responding_to: Option, pub content: String } -// See: https://github.com/SergioBenitez/Rocket/pull/454 #[post("/~///comment", data = "")] fn create(blog_name: String, slug: String, data: LenientForm, user: User, conn: DbConn) -> Redirect { - create_response(blog_name, slug, None, data, user, conn) -} - -#[post("/~///comment?", data = "")] -fn create_response(blog_name: String, slug: String, query: Option, data: LenientForm, user: User, conn: DbConn) -> Redirect { let blog = Blog::find_by_fqn(&*conn, blog_name.clone()).unwrap(); let post = Post::find_by_slug(&*conn, slug.clone(), blog.id).unwrap(); let form = data.get(); let (new_comment, id) = NewComment::build() .content(form.content.clone()) - .in_response_to_id(query.and_then(|q| q.responding_to)) + .in_response_to_id(form.responding_to.clone()) .post(post) .author(user.clone()) .create(&*conn); diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 84cdd410..9a518b25 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -17,7 +17,11 @@ use plume_models::{ safe_string::SafeString, users::User }; -use routes::comments::CommentQuery; + +#[derive(FromForm)] +struct CommentQuery { + responding_to: Option +} // See: https://github.com/SergioBenitez/Rocket/pull/454 #[get("/~//", rank = 4)] diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index 7fdf6e80..5c3d45c3 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -63,6 +63,9 @@ {% if account %}
+ {% if previous %} + + {% endif %} {# Ugly, but we don't have the choice if we don't want weird paddings #}