From 2d1a035877454d6a193ceea057fd4970fb73dd13 Mon Sep 17 00:00:00 2001 From: Didier Link Date: Thu, 21 Jun 2018 11:58:54 +0200 Subject: [PATCH 1/5] partially solve #68 --- src/routes/errors.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/routes/errors.rs b/src/routes/errors.rs index 68ca682e..83c71795 100644 --- a/src/routes/errors.rs +++ b/src/routes/errors.rs @@ -1,15 +1,22 @@ use rocket_contrib::Template; +use rocket::Request; +use rocket::request::FromRequest; +use models::users::User; #[catch(404)] -fn not_found() -> Template { +fn not_found(req: &Request) -> Template { + let user = User::from_request(req).succeeded(); Template::render("errors/404", json!({ - "error_message": "Page not found" + "error_message": "Page not found", + "account": user })) } #[catch(500)] -fn server_error() -> Template { +fn server_error(req: &Request) -> Template { + let user = User::from_request(req).succeeded(); Template::render("errors/500", json!({ - "error_message": "Server error" + "error_message": "Server error", + "account": user })) } From 30899059581029d3cc37b5012261a9e5afa4181c Mon Sep 17 00:00:00 2001 From: Didier Link Date: Thu, 21 Jun 2018 13:33:26 +0200 Subject: [PATCH 2/5] correct a link template to edit user account --- templates/users/header.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/users/header.tera b/templates/users/header.tera index 4ace87f2..e97c724d 100644 --- a/templates/users/header.tera +++ b/templates/users/header.tera @@ -11,7 +11,7 @@ {% if is_self %} - {{ "Edit your profile" | _ }} + {{ "Edit your profile" | _ }} {% endif %} {% if is_remote %} From 9abb5887b1bd9102991372e4a6848c5301d1e300 Mon Sep 17 00:00:00 2001 From: Didier Link Date: Fri, 22 Jun 2018 00:27:18 +0200 Subject: [PATCH 3/5] use user.username for the edit link, not the display name --- templates/users/header.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/users/header.tera b/templates/users/header.tera index e97c724d..3a337c52 100644 --- a/templates/users/header.tera +++ b/templates/users/header.tera @@ -11,7 +11,7 @@ {% if is_self %} - {{ "Edit your profile" | _ }} + {{ "Edit your profile" | _ }} {% endif %} {% if is_remote %} From b153a9ce2bd2abc839a1b75bc17ffcdb10a9e249 Mon Sep 17 00:00:00 2001 From: Didier Link Date: Fri, 22 Jun 2018 00:50:06 +0200 Subject: [PATCH 4/5] add an argument in the macro may_fail to have the account linked in the error template --- src/routes/blogs.rs | 2 +- src/routes/mod.rs | 13 +++++++------ src/routes/posts.rs | 4 ++-- src/routes/user.rs | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index c8439684..d06e56d9 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -19,7 +19,7 @@ use utils; #[get("/~/", rank = 2)] fn details(name: String, conn: DbConn, user: Option) -> Template { - may_fail!(Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| { + may_fail!(user, Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| { let recents = Post::get_recents_for_blog(&*conn, &blog, 5); Template::render("blogs/details", json!({ diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 6c33f75b..735cd4a1 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -2,7 +2,7 @@ use rocket::response::NamedFile; use std::path::{Path, PathBuf}; macro_rules! may_fail { - ($expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => { + ($account:expr, $expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => { { let res = $expr; if res.is_some() { @@ -10,18 +10,19 @@ macro_rules! may_fail { $block } else { Template::render(concat!("errors/", $template), json!({ - "error_message": $msg + "error_message": $msg, + "account": $account })) } } }; - ($expr:expr, $msg:expr, | $res:ident | $block:block) => { - may_fail!($expr, "404", $msg, |$res| { + ($account:expr, $expr:expr, $msg:expr, | $res:ident | $block:block) => { + may_fail!($account, $expr, "404", $msg, |$res| { $block }) }; - ($expr:expr, | $res:ident | $block:block) => { - may_fail!($expr, "", |$res| { + ($account:expr, $expr:expr, | $res:ident | $block:block) => { + may_fail!($account, $expr, "", |$res| { $block }) }; diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 79e0a8fe..7bb3841d 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -27,8 +27,8 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option) -> Temp #[get("/~//?")] fn details_response(blog: String, slug: String, conn: DbConn, user: Option, query: Option) -> Template { - may_fail!(Blog::find_by_fqn(&*conn, blog), "Couldn't find this blog", |blog| { - may_fail!(Post::find_by_slug(&*conn, slug, blog.id), "Couldn't find this post", |post| { + may_fail!(user, Blog::find_by_fqn(&*conn, blog), "Couldn't find this blog", |blog| { + may_fail!(user, Post::find_by_slug(&*conn, slug, blog.id), "Couldn't find this post", |post| { let comments = Comment::list_by_post(&*conn, post.id); Template::render("posts/details", json!({ diff --git a/src/routes/user.rs b/src/routes/user.rs index a2bbfc0b..09a7b93f 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -33,7 +33,7 @@ fn me(user: Option) -> Result> { #[get("/@/", rank = 2)] fn details(name: String, conn: DbConn, account: Option) -> Template { - may_fail!(User::find_by_fqn(&*conn, name), "Couldn't find requested user", |user| { + may_fail!(account, User::find_by_fqn(&*conn, name), "Couldn't find requested user", |user| { let recents = Post::get_recents_for_author(&*conn, &user, 6); let reshares = Reshare::get_recents_for_author(&*conn, &user, 6); let user_id = user.id.clone(); @@ -92,7 +92,7 @@ fn follow_auth(name: String) -> Flash { #[get("/@//followers", rank = 2)] fn followers(name: String, conn: DbConn, account: Option) -> Template { - may_fail!(User::find_by_fqn(&*conn, name.clone()), "Couldn't find requested user", |user| { + may_fail!(account, User::find_by_fqn(&*conn, name.clone()), "Couldn't find requested user", |user| { let user_id = user.id.clone(); Template::render("users/followers", json!({ From ae759114aa608dbb0bcf3b2814a67a41f36ed8d0 Mon Sep 17 00:00:00 2001 From: Didier Link Date: Fri, 22 Jun 2018 01:17:22 +0200 Subject: [PATCH 5/5] temporarly use an absolute link in users detail header template, linked with bug #65 --- templates/users/header.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/users/header.tera b/templates/users/header.tera index 3a337c52..c9e1797c 100644 --- a/templates/users/header.tera +++ b/templates/users/header.tera @@ -11,7 +11,7 @@ {% if is_self %} - {{ "Edit your profile" | _ }} + {{ "Edit your profile" | _ }} {% endif %} {% if is_remote %}