feat(db): Prevent responses to closed threads
This concludes the thread-closing implementation!
This commit is contained in:
parent
a14ece6af3
commit
8901d5d73a
2 changed files with 14 additions and 1 deletions
13
src/db.rs
13
src/db.rs
|
@ -208,6 +208,19 @@ impl Handler<CreatePost> for DbExecutor {
|
||||||
|
|
||||||
let conn = self.0.get()?;
|
let conn = self.0.get()?;
|
||||||
|
|
||||||
|
let closed: bool = {
|
||||||
|
use schema::threads::dsl::*;
|
||||||
|
threads.select(closed)
|
||||||
|
.find(msg.0.thread_id)
|
||||||
|
.first(&conn)?
|
||||||
|
};
|
||||||
|
|
||||||
|
if closed {
|
||||||
|
return Err(ConverseError::ThreadClosed {
|
||||||
|
id: msg.0.thread_id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Ok(diesel::insert_into(posts::table)
|
Ok(diesel::insert_into(posts::table)
|
||||||
.values(&msg.0)
|
.values(&msg.0)
|
||||||
.get_result(&conn)?)
|
.get_result(&conn)?)
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl ResponseError for ConverseError {
|
||||||
// Everything is mapped to internal server errors for now.
|
// Everything is mapped to internal server errors for now.
|
||||||
match *self {
|
match *self {
|
||||||
ConverseError::ThreadClosed { id } => HttpResponse::SeeOther()
|
ConverseError::ThreadClosed { id } => HttpResponse::SeeOther()
|
||||||
.header("Location", format!("/thread/{}#edit-post", id))
|
.header("Location", format!("/thread/{}#post-reply", id))
|
||||||
.finish(),
|
.finish(),
|
||||||
_ => HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
|
_ => HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
.body(format!("An error occured: {}", self))
|
.body(format!("An error occured: {}", self))
|
||||||
|
|
Loading…
Reference in a new issue