diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-04-15T10·38+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2018-04-15T10·38+0200 |
commit | 9cee48f2dac7400fc0df78b8790ff1e1600a632e (patch) | |
tree | cd21cdad21f6dc8c046be7819564ba8d80005f00 /src/render.rs | |
parent | 02a466a28be4c6fdcd88075d6345841759ff630c (diff) |
feat(handlers): Determine whether current user can edit a post
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/render.rs b/src/render.rs index 3254d480b5d2..9cc9efd4d10e 100644 --- a/src/render.rs +++ b/src/render.rs @@ -86,6 +86,7 @@ impl Handler<IndexPage> for Renderer { /// Message used to render a thread. pub struct ThreadPage { + pub current_user: Option<String>, pub thread: Thread, pub posts: Vec<Post>, } @@ -102,6 +103,7 @@ struct RenderablePost { posted: FormattedDate, author_name: String, author_gravatar: String, + editable: bool, } /// This structure represents the transformed thread data with @@ -119,14 +121,21 @@ fn md5_hex(input: &[u8]) -> String { } fn prepare_thread(comrak: &ComrakOptions, page: ThreadPage) -> RenderableThreadPage { + let user = page.current_user; + let posts = page.posts.into_iter().map(|post| { let escaped_body = escape_html(&post.body); + let editable = user.clone() + .map(|c| post.author_email.eq(&c)) + .unwrap_or_else(|| false); + RenderablePost { id: post.id, body: markdown_to_html(&escaped_body, comrak), posted: post.posted.into(), - author_name: post.author_name, + author_name: post.author_name.clone(), author_gravatar: md5_hex(post.author_email.as_bytes()), + editable, } }).collect(); |