Add thread title editing
This commit is contained in:
parent
ec80952ad9
commit
4b13f99df8
|
@ -332,7 +332,7 @@ func BlogPostEditSubmit(c *RequestContext) ResponseData {
|
||||||
}
|
}
|
||||||
defer tx.Rollback(c.Context())
|
defer tx.Rollback(c.Context())
|
||||||
|
|
||||||
post, err := FetchThreadPost(c.Context(), c.Conn, c.CurrentUser, cd.ThreadID, cd.PostID, PostsQuery{
|
post, err := FetchThreadPost(c.Context(), tx, c.CurrentUser, cd.ThreadID, cd.PostID, PostsQuery{
|
||||||
ProjectIDs: []int{c.CurrentProject.ID},
|
ProjectIDs: []int{c.CurrentProject.ID},
|
||||||
ThreadTypes: []models.ThreadType{models.ThreadTypeProjectBlogPost},
|
ThreadTypes: []models.ThreadType{models.ThreadTypeProjectBlogPost},
|
||||||
})
|
})
|
||||||
|
@ -355,6 +355,19 @@ func BlogPostEditSubmit(c *RequestContext) ResponseData {
|
||||||
|
|
||||||
CreatePostVersion(c.Context(), tx, post.Post.ID, unparsed, c.Req.Host, editReason, &c.CurrentUser.ID)
|
CreatePostVersion(c.Context(), tx, post.Post.ID, unparsed, c.Req.Host, editReason, &c.CurrentUser.ID)
|
||||||
|
|
||||||
|
if title != "" {
|
||||||
|
_, err := tx.Exec(c.Context(),
|
||||||
|
`
|
||||||
|
UPDATE handmade_thread SET title = $1 WHERE id = $2
|
||||||
|
`,
|
||||||
|
title,
|
||||||
|
post.Thread.ID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to update thread title"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = tx.Commit(c.Context())
|
err = tx.Commit(c.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to edit blog post"))
|
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to edit blog post"))
|
||||||
|
|
|
@ -686,15 +686,42 @@ func ForumPostEditSubmit(c *RequestContext) ResponseData {
|
||||||
}
|
}
|
||||||
defer tx.Rollback(c.Context())
|
defer tx.Rollback(c.Context())
|
||||||
|
|
||||||
|
post, err := FetchThreadPost(c.Context(), tx, c.CurrentUser, cd.ThreadID, cd.PostID, PostsQuery{
|
||||||
|
ProjectIDs: []int{c.CurrentProject.ID},
|
||||||
|
ThreadTypes: []models.ThreadType{models.ThreadTypeForumPost},
|
||||||
|
})
|
||||||
|
if errors.Is(err, db.NotFound) {
|
||||||
|
return FourOhFour(c)
|
||||||
|
} else if err != nil {
|
||||||
|
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to get forum post to submit edits"))
|
||||||
|
}
|
||||||
|
|
||||||
c.Req.ParseForm()
|
c.Req.ParseForm()
|
||||||
|
title := c.Req.Form.Get("title")
|
||||||
unparsed := c.Req.Form.Get("body")
|
unparsed := c.Req.Form.Get("body")
|
||||||
editReason := c.Req.Form.Get("editreason")
|
editReason := c.Req.Form.Get("editreason")
|
||||||
|
if title != "" && post.Thread.FirstID != post.Post.ID {
|
||||||
|
return RejectRequest(c, "You can only edit the title by editing the first post.")
|
||||||
|
}
|
||||||
if unparsed == "" {
|
if unparsed == "" {
|
||||||
return RejectRequest(c, "You must provide a body for your post.")
|
return RejectRequest(c, "You must provide a body for your post.")
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatePostVersion(c.Context(), tx, cd.PostID, unparsed, c.Req.Host, editReason, &c.CurrentUser.ID)
|
CreatePostVersion(c.Context(), tx, cd.PostID, unparsed, c.Req.Host, editReason, &c.CurrentUser.ID)
|
||||||
|
|
||||||
|
if title != "" {
|
||||||
|
_, err := tx.Exec(c.Context(),
|
||||||
|
`
|
||||||
|
UPDATE handmade_thread SET title = $1 WHERE id = $2
|
||||||
|
`,
|
||||||
|
title,
|
||||||
|
post.Thread.ID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to update thread title"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = tx.Commit(c.Context())
|
err = tx.Commit(c.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to edit forum post"))
|
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to edit forum post"))
|
||||||
|
|
Loading…
Reference in New Issue