1
0
Fork 0
forked from forgejo/forgejo

Add a SetIssueUpdateDate() function in services/issue.go

That function is used by some API calls to set the NoAutoDate and
UpdatedUnix fields of an Issue if an updated_at date is provided.
This commit is contained in:
fluzz 2023-05-30 18:53:56 +02:00
parent c524d33402
commit f061caa655
2 changed files with 43 additions and 25 deletions

View file

@ -774,31 +774,10 @@ func EditIssue(ctx *context.APIContext) {
return
}
// In order to be set a specific update time, the DB will be updated
// with NoAutoTime. The 'noAutoTime' bool will be propagated down to the
// DB update calls to apply autoupdate or not.
issue.NoAutoTime = false
if form.Updated != nil {
// Check if the poster is allowed to set an update date
perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, ctx.Doer)
if err != nil {
ctx.Status(http.StatusForbidden)
return
}
if !perm.IsAdmin() && !perm.IsOwner() {
ctx.Error(http.StatusUnauthorized, "EditIssue", "user needs to have admin or owner right")
return
}
// A simple guard against potential inconsistent calls
updatedUnix := timeutil.TimeStamp(form.Updated.Unix())
if updatedUnix < issue.CreatedUnix || updatedUnix > timeutil.TimeStampNow() {
ctx.Error(http.StatusForbidden, "EditIssue", "unallowed update date")
return
}
issue.UpdatedUnix = updatedUnix
issue.NoAutoTime = true
err = issue_service.SetIssueUpdateDate(ctx, issue, form.Updated, ctx.Doer)
if err != nil {
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
return
}
oldTitle := issue.Title