feat(handlers): Determine whether current user can edit a post

This commit is contained in:
Vincent Ambo 2018-04-15 12:38:12 +02:00
parent 02a466a28b
commit 9cee48f2da
3 changed files with 19 additions and 3 deletions

View file

@ -60,11 +60,18 @@ pub fn forum_index(state: State<AppState>) -> ConverseResponse {
}
/// This handler retrieves and displays a single forum thread.
pub fn forum_thread(state: State<AppState>, thread_id: Path<i32>) -> ConverseResponse {
pub fn forum_thread(state: State<AppState>,
mut req: HttpRequest<AppState>,
thread_id: Path<i32>) -> ConverseResponse {
let id = thread_id.into_inner();
let user = req.session().get(AUTHOR)
.unwrap_or_else(|_| None)
.map(|a: Author| a.email);
state.db.send(GetThread(id))
.flatten()
.and_then(move |res| state.renderer.send(ThreadPage {
current_user: user,
thread: res.0,
posts: res.1,
}).from_err())