diff options
author | Unknwon <u@gogs.io> | 2017-03-13 04:32:20 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-03-13 04:32:20 -0400 |
commit | 1df54ea0cde038e2057d083078f952c072d0dc67 (patch) | |
tree | c5466e010f5ed8e236f5b021e669f9aa37ea0047 /routers/repo/issue.go | |
parent | e6df2259abdeb75545f53a5ca4c247491b5c3d7f (diff) |
release: able to add attchments to release (#1614)
Added new config section '[release.attachment]’.
Diffstat (limited to 'routers/repo/issue.go')
-rw-r--r-- | routers/repo/issue.go | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 3b1d9305..3305b8ed 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -348,7 +348,7 @@ func NewIssue(ctx *context.Context) { ctx.HTML(200, ISSUE_NEW) } -func ValidateRepoMetas(ctx *context.Context, f form.CreateIssue) ([]int64, int64, int64) { +func ValidateRepoMetas(ctx *context.Context, f form.NewIssue) ([]int64, int64, int64) { var ( repo = ctx.Repo.Repository err error @@ -402,34 +402,30 @@ func ValidateRepoMetas(ctx *context.Context, f form.CreateIssue) ([]int64, int64 return labelIDs, milestoneID, assigneeID } -func NewIssuePost(ctx *context.Context, f form.CreateIssue) { +func NewIssuePost(ctx *context.Context, f form.NewIssue) { ctx.Data["Title"] = ctx.Tr("repo.issues.new") ctx.Data["PageIsIssueList"] = true ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireSimpleMDE"] = true renderAttachmentSettings(ctx) - var ( - repo = ctx.Repo.Repository - attachments []string - ) - labelIDs, milestoneID, assigneeID := ValidateRepoMetas(ctx, f) if ctx.Written() { return } - if setting.AttachmentEnabled { - attachments = f.Files - } - if ctx.HasError() { ctx.HTML(200, ISSUE_NEW) return } + var attachments []string + if setting.AttachmentEnabled { + attachments = f.Files + } + issue := &models.Issue{ - RepoID: repo.ID, + RepoID: ctx.Repo.Repository.ID, Title: f.Title, PosterID: ctx.User.ID, Poster: ctx.User, @@ -437,21 +433,16 @@ func NewIssuePost(ctx *context.Context, f form.CreateIssue) { AssigneeID: assigneeID, Content: f.Content, } - if err := models.NewIssue(repo, issue, labelIDs, attachments); err != nil { + if err := models.NewIssue(ctx.Repo.Repository, issue, labelIDs, attachments); err != nil { ctx.Handle(500, "NewIssue", err) return } - log.Trace("Issue created: %d/%d", repo.ID, issue.ID) + log.Trace("Issue created: %d/%d", ctx.Repo.Repository.ID, issue.ID) ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index)) } -func UploadIssueAttachment(ctx *context.Context) { - if !setting.AttachmentEnabled { - ctx.Error(404, "attachment is not enabled") - return - } - +func uploadAttachment(ctx *context.Context, allowedTypes []string) { file, header, err := ctx.Req.FormFile("file") if err != nil { ctx.Error(500, fmt.Sprintf("FormFile: %v", err)) @@ -466,7 +457,6 @@ func UploadIssueAttachment(ctx *context.Context) { } fileType := http.DetectContentType(buf) - allowedTypes := strings.Split(setting.AttachmentAllowedTypes, ",") allowed := false for _, t := range allowedTypes { t := strings.Trim(t, " ") @@ -493,6 +483,15 @@ func UploadIssueAttachment(ctx *context.Context) { }) } +func UploadIssueAttachment(ctx *context.Context) { + if !setting.AttachmentEnabled { + ctx.NotFound() + return + } + + uploadAttachment(ctx, strings.Split(setting.AttachmentAllowedTypes, ",")) +} + func ViewIssue(ctx *context.Context) { ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireDropzone"] = true |