mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 14:53:34 +01:00
Add an updated_at field to the API call for issue's attachment creation
The update date is applied to the issue's comment created to inform about the modification of the issue's content, and is set as the asset creation date.
This commit is contained in:
parent
ea36cf80f5
commit
96150971ca
5 changed files with 45 additions and 6 deletions
|
@ -274,8 +274,12 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er
|
|||
return fmt.Errorf("UpdateIssueCols: %w", err)
|
||||
}
|
||||
|
||||
historyDate := timeutil.TimeStampNow()
|
||||
if issue.NoAutoTime {
|
||||
historyDate = issue.UpdatedUnix
|
||||
}
|
||||
if err = SaveIssueContentHistory(ctx, doer.ID, issue.ID, 0,
|
||||
timeutil.TimeStampNow(), issue.Content, false); err != nil {
|
||||
historyDate, issue.Content, false); err != nil {
|
||||
return fmt.Errorf("SaveIssueContentHistory: %w", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ type Attachment struct {
|
|||
Name string
|
||||
DownloadCount int64 `xorm:"DEFAULT 0"`
|
||||
Size int64 `xorm:"DEFAULT 0"`
|
||||
NoAutoTime bool `xorm:"-"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||
CustomDownloadURL string `xorm:"-"`
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package repo
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
|
@ -141,6 +142,11 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
|||
// description: name of the attachment
|
||||
// type: string
|
||||
// required: false
|
||||
// - name: updated_at
|
||||
// in: query
|
||||
// description: time of the attachment's creation. This is a timestamp in RFC 3339 format
|
||||
// type: string
|
||||
// format: date-time
|
||||
// - name: attachment
|
||||
// in: formData
|
||||
// description: attachment to upload
|
||||
|
@ -163,6 +169,20 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
updatedAt := ctx.Req.FormValue("updated_at")
|
||||
if len(updatedAt) != 0 {
|
||||
updated, err := time.Parse(time.RFC3339, updatedAt)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "time.Parse", err)
|
||||
return
|
||||
}
|
||||
err = issue_service.SetIssueUpdateDate(ctx, issue, &updated, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Get uploaded file from request
|
||||
file, header, err := ctx.Req.FormFile("attachment")
|
||||
if err != nil {
|
||||
|
@ -177,10 +197,12 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
attachment, err := attachment.UploadAttachment(file, setting.Attachment.AllowedTypes, header.Size, &repo_model.Attachment{
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
IssueID: issue.ID,
|
||||
Name: filename,
|
||||
UploaderID: ctx.Doer.ID,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
IssueID: issue.ID,
|
||||
NoAutoTime: issue.NoAutoTime,
|
||||
CreatedUnix: issue.UpdatedUnix,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UploadAttachment", err)
|
||||
|
|
|
@ -32,7 +32,12 @@ func NewAttachment(attach *repo_model.Attachment, file io.Reader, size int64) (*
|
|||
}
|
||||
attach.Size = size
|
||||
|
||||
return db.Insert(ctx, attach)
|
||||
eng := db.GetEngine(ctx)
|
||||
if attach.NoAutoTime {
|
||||
eng.NoAutoTime()
|
||||
}
|
||||
_, err = eng.Insert(attach)
|
||||
return err
|
||||
})
|
||||
|
||||
return attach, err
|
||||
|
|
7
templates/swagger/v1_json.tmpl
generated
7
templates/swagger/v1_json.tmpl
generated
|
@ -6718,6 +6718,13 @@
|
|||
"name": "name",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"description": "time of the attachment's creation. This is a timestamp in RFC 3339 format",
|
||||
"name": "updated_at",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"description": "attachment to upload",
|
||||
|
|
Loading…
Reference in a new issue