|
|
@ -5,7 +5,11 @@ |
|
|
|
package repo |
|
|
|
package repo |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"io" |
|
|
|
|
|
|
|
"io/ioutil" |
|
|
|
|
|
|
|
"mime" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
@ -32,6 +36,11 @@ const ( |
|
|
|
MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit" |
|
|
|
MILESTONE_EDIT base.TplName = "repo/issue/milestone_edit" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
ErrFileTypeForbidden = errors.New("File type is not allowed") |
|
|
|
|
|
|
|
ErrTooManyFiles = errors.New("Maximum number of files to upload exceeded") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func Issues(ctx *middleware.Context) { |
|
|
|
func Issues(ctx *middleware.Context) { |
|
|
|
ctx.Data["Title"] = "Issues" |
|
|
|
ctx.Data["Title"] = "Issues" |
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true |
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true |
|
|
@ -151,6 +160,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) { |
|
|
|
ctx.Data["Title"] = "Create issue" |
|
|
|
ctx.Data["Title"] = "Create issue" |
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true |
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true |
|
|
|
ctx.Data["IsRepoToolbarIssuesList"] = false |
|
|
|
ctx.Data["IsRepoToolbarIssuesList"] = false |
|
|
|
|
|
|
|
ctx.Data["AttachmentsEnabled"] = setting.AttachmentEnabled |
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
var err error |
|
|
|
// Get all milestones.
|
|
|
|
// Get all milestones.
|
|
|
@ -170,7 +180,10 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) { |
|
|
|
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) |
|
|
|
ctx.Handle(500, "issue.CreateIssue(GetCollaborators)", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["AllowedTypes"] = setting.AttachmentAllowedTypes |
|
|
|
ctx.Data["Collaborators"] = us |
|
|
|
ctx.Data["Collaborators"] = us |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, ISSUE_CREATE) |
|
|
|
ctx.HTML(200, ISSUE_CREATE) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -178,6 +191,7 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C |
|
|
|
ctx.Data["Title"] = "Create issue" |
|
|
|
ctx.Data["Title"] = "Create issue" |
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true |
|
|
|
ctx.Data["IsRepoToolbarIssues"] = true |
|
|
|
ctx.Data["IsRepoToolbarIssuesList"] = false |
|
|
|
ctx.Data["IsRepoToolbarIssuesList"] = false |
|
|
|
|
|
|
|
ctx.Data["AttachmentsEnabled"] = setting.AttachmentEnabled |
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
var err error |
|
|
|
// Get all milestones.
|
|
|
|
// Get all milestones.
|
|
|
@ -227,6 +241,10 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if setting.AttachmentEnabled { |
|
|
|
|
|
|
|
uploadFiles(ctx, issue.Id, 0) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update mentions.
|
|
|
|
// Update mentions.
|
|
|
|
ms := base.MentionPattern.FindAllString(issue.Content, -1) |
|
|
|
ms := base.MentionPattern.FindAllString(issue.Content, -1) |
|
|
|
if len(ms) > 0 { |
|
|
|
if len(ms) > 0 { |
|
|
@ -298,6 +316,8 @@ func checkLabels(labels, allLabels []*models.Label) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ViewIssue(ctx *middleware.Context, params martini.Params) { |
|
|
|
func ViewIssue(ctx *middleware.Context, params martini.Params) { |
|
|
|
|
|
|
|
ctx.Data["AttachmentsEnabled"] = setting.AttachmentEnabled |
|
|
|
|
|
|
|
|
|
|
|
idx, _ := base.StrTo(params["index"]).Int64() |
|
|
|
idx, _ := base.StrTo(params["index"]).Int64() |
|
|
|
if idx == 0 { |
|
|
|
if idx == 0 { |
|
|
|
ctx.Handle(404, "issue.ViewIssue", nil) |
|
|
|
ctx.Handle(404, "issue.ViewIssue", nil) |
|
|
@ -398,6 +418,8 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["AllowedTypes"] = setting.AttachmentAllowedTypes |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Title"] = issue.Name |
|
|
|
ctx.Data["Title"] = issue.Name |
|
|
|
ctx.Data["Issue"] = issue |
|
|
|
ctx.Data["Issue"] = issue |
|
|
|
ctx.Data["Comments"] = comments |
|
|
|
ctx.Data["Comments"] = comments |
|
|
@ -610,6 +632,71 @@ func UpdateAssignee(ctx *middleware.Context) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func uploadFiles(ctx *middleware.Context, issueId, commentId int64) { |
|
|
|
|
|
|
|
if !setting.AttachmentEnabled { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allowedTypes := strings.Split(setting.AttachmentAllowedTypes, "|") |
|
|
|
|
|
|
|
attachments := ctx.Req.MultipartForm.File["attachments"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(attachments) > setting.AttachmentMaxFiles { |
|
|
|
|
|
|
|
ctx.Handle(400, "issue.Comment", ErrTooManyFiles) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, header := range attachments { |
|
|
|
|
|
|
|
file, err := header.Open() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "issue.Comment(header.Open)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer file.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allowed := false |
|
|
|
|
|
|
|
fileType := mime.TypeByExtension(header.Filename) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, t := range allowedTypes { |
|
|
|
|
|
|
|
t := strings.Trim(t, " ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if t == "*/*" || t == fileType { |
|
|
|
|
|
|
|
allowed = true |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !allowed { |
|
|
|
|
|
|
|
ctx.Handle(400, "issue.Comment", ErrFileTypeForbidden) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out, err := ioutil.TempFile(setting.AttachmentPath, "attachment_") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "issue.Comment(ioutil.TempFile)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer out.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err = io.Copy(out, file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "issue.Comment(io.Copy)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err = models.CreateAttachment(issueId, commentId, header.Filename, out.Name()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "issue.Comment(io.Copy)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Comment(ctx *middleware.Context, params martini.Params) { |
|
|
|
func Comment(ctx *middleware.Context, params martini.Params) { |
|
|
|
index, err := base.StrTo(ctx.Query("issueIndex")).Int64() |
|
|
|
index, err := base.StrTo(ctx.Query("issueIndex")).Int64() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -656,7 +743,7 @@ func Comment(ctx *middleware.Context, params martini.Params) { |
|
|
|
cmtType = models.REOPEN |
|
|
|
cmtType = models.REOPEN |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, cmtType, ""); err != nil { |
|
|
|
if _, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, cmtType, "", nil); err != nil { |
|
|
|
ctx.Handle(200, "issue.Comment(create status change comment)", err) |
|
|
|
ctx.Handle(200, "issue.Comment(create status change comment)", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -664,12 +751,14 @@ func Comment(ctx *middleware.Context, params martini.Params) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var comment *models.Comment |
|
|
|
|
|
|
|
|
|
|
|
var ms []string |
|
|
|
var ms []string |
|
|
|
content := ctx.Query("content") |
|
|
|
content := ctx.Query("content") |
|
|
|
if len(content) > 0 { |
|
|
|
if len(content) > 0 { |
|
|
|
switch params["action"] { |
|
|
|
switch params["action"] { |
|
|
|
case "new": |
|
|
|
case "new": |
|
|
|
if err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, models.COMMENT, content); err != nil { |
|
|
|
if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, issue.Id, 0, 0, models.COMMENT, content, nil); err != nil { |
|
|
|
ctx.Handle(500, "issue.Comment(create comment)", err) |
|
|
|
ctx.Handle(500, "issue.Comment(create comment)", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -694,6 +783,10 @@ func Comment(ctx *middleware.Context, params martini.Params) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if comment != nil { |
|
|
|
|
|
|
|
uploadFiles(ctx, issue.Id, comment.Id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Notify watchers.
|
|
|
|
// Notify watchers.
|
|
|
|
act := &models.Action{ |
|
|
|
act := &models.Action{ |
|
|
|
ActUserId: ctx.User.Id, |
|
|
|
ActUserId: ctx.User.Id, |
|
|
@ -970,3 +1063,21 @@ func UpdateMilestonePost(ctx *middleware.Context, params martini.Params, form au |
|
|
|
|
|
|
|
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/issues/milestones") |
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/issues/milestones") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func IssueGetAttachment(ctx *middleware.Context, params martini.Params) { |
|
|
|
|
|
|
|
id, err := base.StrTo(params["id"]).Int64() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(400, "issue.IssueGetAttachment(base.StrTo.Int64)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachment, err := models.GetAttachmentById(id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.Handle(404, "issue.IssueGetAttachment(models.GetAttachmentById)", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.ServeFile(attachment.Path, attachment.Name) |
|
|
|
|
|
|
|
} |
|
|
|