Add an updated_at field to the API call for issue's comment edition

The update date is used as the comment update date, and is applied to
the issue as an update date.
This commit is contained in:
fluzz 2023-07-20 11:35:10 +02:00
parent 76c8faecdc
commit cf787ad7fd
5 changed files with 29 additions and 4 deletions

View file

@ -1106,9 +1106,12 @@ func UpdateComment(c *Comment, doer *user_model.User) error {
return err
}
defer committer.Close()
sess := db.GetEngine(ctx)
if _, err := sess.ID(c.ID).AllCols().Update(c); err != nil {
sess := db.GetEngine(ctx).ID(c.ID).AllCols()
if c.Issue.NoAutoTime {
c.UpdatedUnix = c.Issue.UpdatedUnix
sess = sess.NoAutoTime()
}
if _, err := sess.Update(c); err != nil {
return err
}
if err := c.LoadIssue(ctx); err != nil {

View file

@ -36,6 +36,8 @@ type CreateIssueCommentOption struct {
type EditIssueCommentOption struct {
// required: true
Body string `json:"body" binding:"Required"`
// swagger:strfmt date-time
Updated *time.Time `json:"updated_at"`
}
// TimelineComment represents a timeline comment (comment of any type) on a commit or issue

View file

@ -560,6 +560,17 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
return
}
err = comment.LoadIssue(ctx)
if err != nil {
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
return
}
err = issue_service.SetIssueUpdateDate(ctx, comment.Issue, form.Updated, ctx.Doer)
if err != nil {
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
return
}
oldContent := comment.Content
comment.Content = form.Body
if err := issue_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil {

View file

@ -89,7 +89,11 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode
}
if needsContentHistory {
err := issues_model.SaveIssueContentHistory(ctx, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
historyDate := timeutil.TimeStampNow()
if c.Issue.NoAutoTime {
historyDate = c.Issue.UpdatedUnix
}
err := issues_model.SaveIssueContentHistory(ctx, doer.ID, c.IssueID, c.ID, historyDate, c.Content, false)
if err != nil {
return err
}

View file

@ -18075,6 +18075,11 @@
"body": {
"type": "string",
"x-go-name": "Body"
},
"updated_at": {
"type": "string",
"format": "date-time",
"x-go-name": "Updated"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"