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)
|
return fmt.Errorf("UpdateIssueCols: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
historyDate := timeutil.TimeStampNow()
|
||||||
|
if issue.NoAutoTime {
|
||||||
|
historyDate = issue.UpdatedUnix
|
||||||
|
}
|
||||||
if err = SaveIssueContentHistory(ctx, doer.ID, issue.ID, 0,
|
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)
|
return fmt.Errorf("SaveIssueContentHistory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ type Attachment struct {
|
||||||
Name string
|
Name string
|
||||||
DownloadCount int64 `xorm:"DEFAULT 0"`
|
DownloadCount int64 `xorm:"DEFAULT 0"`
|
||||||
Size int64 `xorm:"DEFAULT 0"`
|
Size int64 `xorm:"DEFAULT 0"`
|
||||||
|
NoAutoTime bool `xorm:"-"`
|
||||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||||
CustomDownloadURL string `xorm:"-"`
|
CustomDownloadURL string `xorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -141,6 +142,11 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||||
// description: name of the attachment
|
// description: name of the attachment
|
||||||
// type: string
|
// type: string
|
||||||
// required: false
|
// 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
|
// - name: attachment
|
||||||
// in: formData
|
// in: formData
|
||||||
// description: attachment to upload
|
// description: attachment to upload
|
||||||
|
@ -163,6 +169,20 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||||
return
|
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
|
// Get uploaded file from request
|
||||||
file, header, err := ctx.Req.FormFile("attachment")
|
file, header, err := ctx.Req.FormFile("attachment")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -181,6 +201,8 @@ func CreateIssueAttachment(ctx *context.APIContext) {
|
||||||
UploaderID: ctx.Doer.ID,
|
UploaderID: ctx.Doer.ID,
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
IssueID: issue.ID,
|
IssueID: issue.ID,
|
||||||
|
NoAutoTime: issue.NoAutoTime,
|
||||||
|
CreatedUnix: issue.UpdatedUnix,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UploadAttachment", err)
|
ctx.Error(http.StatusInternalServerError, "UploadAttachment", err)
|
||||||
|
|
|
@ -32,7 +32,12 @@ func NewAttachment(attach *repo_model.Attachment, file io.Reader, size int64) (*
|
||||||
}
|
}
|
||||||
attach.Size = size
|
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
|
return attach, err
|
||||||
|
|
7
templates/swagger/v1_json.tmpl
generated
7
templates/swagger/v1_json.tmpl
generated
|
@ -6718,6 +6718,13 @@
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"in": "query"
|
"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",
|
"type": "file",
|
||||||
"description": "attachment to upload",
|
"description": "attachment to upload",
|
||||||
|
|
Loading…
Reference in a new issue