summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-13 16:07:11 +0800
committerUnknwon <u@gogs.io>2015-08-13 16:07:11 +0800
commit133b19d0c5587b7c6d5d9e8057f81bc45a246972 (patch)
tree1cd0e19599d5f9288fb1b2cbf5bf8f48fdf16fd8 /routers
parentd7d72b9e3cc0e536d213d6501244544de8020661 (diff)
downloadgitea-133b19d0c5587b7c6d5d9e8057f81bc45a246972.tar.gz
gitea-133b19d0c5587b7c6d5d9e8057f81bc45a246972.zip
finish view comments on issue page
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/issue.go207
1 files changed, 52 insertions, 155 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 53f5cf5d48..4f3408edda 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -288,7 +288,7 @@ func NewIssuePost(ctx *middleware.Context, form auth.CreateIssueForm) {
}
if setting.AttachmentEnabled {
- attachments = ctx.QueryStrings("attachments")
+ attachments = form.Attachments
}
if ctx.HasError() {
@@ -432,8 +432,6 @@ func ViewIssue(ctx *middleware.Context) {
}
issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink))
- // Attchments.
-
// Metas.
if err = issue.GetLabels(); err != nil {
ctx.Handle(500, "GetLabels", err)
@@ -477,29 +475,14 @@ func ViewIssue(ctx *middleware.Context) {
}
}
- // // Get comments.
- // comments, err := models.GetIssueComments(issue.ID)
- // if err != nil {
- // ctx.Handle(500, "GetIssueComments: %v", err)
- // return
- // }
-
- // // Get posters.
- // for i := range comments {
- // u, err := models.GetUserByID(comments[i].PosterId)
- // if err != nil {
- // ctx.Handle(500, "GetUserById.2: %v", err)
- // return
- // }
- // comments[i].Poster = u
-
- // if comments[i].Type == models.COMMENT_TYPE_COMMENT {
- // comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ctx.Repo.RepoLink))
- // }
- // }
+ // Render comments.
+ for i := range issue.Comments {
+ if issue.Comments[i].Type == models.COMMENT_TYPE_COMMENT {
+ issue.Comments[i].RenderedContent = string(base.RenderMarkdown([]byte(issue.Comments[i].Content), ctx.Repo.RepoLink))
+ }
+ }
ctx.Data["Issue"] = issue
- // ctx.Data["Comments"] = comments
// ctx.Data["IsIssueOwner"] = ctx.Repo.IsOwner() || (ctx.IsSigned && issue.PosterID == ctx.User.Id)
ctx.HTML(200, ISSUE_VIEW)
}
@@ -713,163 +696,76 @@ func UpdateAssignee(ctx *middleware.Context) {
})
}
-func Comment(ctx *middleware.Context) {
- send := func(status int, data interface{}, err error) {
- if err != nil {
- log.Error(4, "issue.Comment(?): %s", err)
-
- ctx.JSON(status, map[string]interface{}{
- "ok": false,
- "status": status,
- "error": err.Error(),
- })
- } else {
- ctx.JSON(status, map[string]interface{}{
- "ok": true,
- "status": status,
- "data": data,
- })
- }
- }
-
- index := com.StrTo(ctx.Query("issueIndex")).MustInt64()
- if index == 0 {
- ctx.Error(404)
- return
- }
-
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, index)
+func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) {
+ issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
- send(404, nil, err)
+ ctx.Handle(404, "GetIssueByIndex", err)
} else {
- send(200, nil, err)
+ ctx.Handle(500, "GetIssueByIndex", err)
}
-
return
}
- // Check if issue owner changes the status of issue.
- var newStatus string
- if ctx.Repo.IsOwner() || issue.PosterID == ctx.User.Id {
- newStatus = ctx.Query("change_status")
+ var attachments []string
+ if setting.AttachmentEnabled {
+ attachments = form.Attachments
}
- if len(newStatus) > 0 {
- if (strings.Contains(newStatus, "Reopen") && issue.IsClosed) ||
- (strings.Contains(newStatus, "Close") && !issue.IsClosed) {
- issue.IsClosed = !issue.IsClosed
- if err = models.UpdateIssue(issue); err != nil {
- send(500, nil, err)
- return
- } else if err = models.UpdateIssueUserPairsByStatus(issue.ID, issue.IsClosed); err != nil {
- send(500, nil, err)
- return
- }
-
- if err = issue.GetLabels(); err != nil {
- send(500, nil, err)
- return
- }
-
- for _, label := range issue.Labels {
- if issue.IsClosed {
- label.NumClosedIssues++
- } else {
- label.NumClosedIssues--
- }
-
- if err = models.UpdateLabel(label); err != nil {
- send(500, nil, err)
- return
- }
- }
-
- // Change open/closed issue counter for the associated milestone
- if issue.MilestoneID > 0 {
- if err = models.ChangeMilestoneIssueStats(issue); err != nil {
- send(500, nil, err)
- }
- }
-
- cmtType := models.COMMENT_TYPE_CLOSE
- if !issue.IsClosed {
- cmtType = models.COMMENT_TYPE_REOPEN
- }
- if _, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.ID, issue.ID, 0, 0, cmtType, "", nil); err != nil {
- send(200, nil, err)
- return
- }
- log.Trace("%s Issue(%d) status changed: %v", ctx.Req.RequestURI, issue.ID, !issue.IsClosed)
- }
+ if ctx.HasError() {
+ ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
+ ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
+ return
}
- var comment *models.Comment
-
- var ms []string
- content := ctx.Query("content")
- // Fix #321. Allow empty comments, as long as we have attachments.
- if len(content) > 0 || len(ctx.Req.MultipartForm.File["attachments"]) > 0 {
- switch ctx.Params(":action") {
- case "new":
- if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.ID, issue.ID, 0, 0, models.COMMENT_TYPE_COMMENT, content, nil); err != nil {
- send(500, nil, err)
- return
- }
-
- // Update mentions.
- ms = base.MentionPattern.FindAllString(issue.Content, -1)
- if len(ms) > 0 {
- for i := range ms {
- ms[i] = ms[i][1:]
- }
-
- if err := models.UpdateMentions(ms, issue.ID); err != nil {
- send(500, nil, err)
- return
- }
- }
-
- log.Trace("%s Comment created: %d", ctx.Req.RequestURI, issue.ID)
- default:
- ctx.Handle(404, "issue.Comment", err)
+ // Check if issue owner/poster changes the status of issue.
+ if (ctx.Repo.IsOwner() || issue.IsPoster(ctx.User.Id)) &&
+ (form.NewStatus == "reopen" || form.NewStatus == "close") {
+ issue.Repo = ctx.Repo.Repository
+ if err = issue.ChangeStatus(ctx.User, form.NewStatus == "close"); err != nil {
+ ctx.Handle(500, "ChangeStatus", err)
return
}
+ log.Trace("%s Issue[%d] status changed: %v", ctx.Req.RequestURI, issue.ID, !issue.IsClosed)
}
- if comment != nil {
- // uploadFiles(ctx, issue.ID, comment.Id)
+ // Fix #321: Allow empty comments, as long as we have attachments.
+ if len(form.Content) == 0 && len(attachments) == 0 {
+ ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
+ return
}
- // Notify watchers.
- act := &models.Action{
- ActUserID: ctx.User.Id,
- ActUserName: ctx.User.LowerName,
- ActEmail: ctx.User.Email,
- OpType: models.COMMENT_ISSUE,
- Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]),
- RepoID: ctx.Repo.Repository.ID,
- RepoUserName: ctx.Repo.Owner.LowerName,
- RepoName: ctx.Repo.Repository.LowerName,
- IsPrivate: ctx.Repo.Repository.IsPrivate,
- }
- if err = models.NotifyWatchers(act); err != nil {
- send(500, nil, err)
+ comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments)
+ if err != nil {
+ ctx.Handle(500, "CreateIssueComment", err)
return
}
+ // Update mentions.
+ mentions := base.MentionPattern.FindAllString(comment.Content, -1)
+ if len(mentions) > 0 {
+ for i := range mentions {
+ mentions[i] = mentions[i][1:]
+ }
+
+ if err := models.UpdateMentions(mentions, issue.ID); err != nil {
+ ctx.Handle(500, "UpdateMentions", err)
+ return
+ }
+ }
+
// Mail watchers and mentions.
if setting.Service.EnableNotifyMail {
- issue.Content = content
+ issue.Content = form.Content
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
if err != nil {
- send(500, nil, err)
+ ctx.Handle(500, "SendIssueNotifyMail", err)
return
}
tos = append(tos, ctx.User.LowerName)
- newTos := make([]string, 0, len(ms))
- for _, m := range ms {
+ newTos := make([]string, 0, len(mentions))
+ for _, m := range mentions {
if com.IsSliceContainsStr(tos, m) {
continue
}
@@ -878,12 +774,13 @@ func Comment(ctx *middleware.Context) {
}
if err = mailer.SendIssueMentionMail(ctx.Render, ctx.User, ctx.Repo.Owner,
ctx.Repo.Repository, issue, models.GetUserEmailsByNames(newTos)); err != nil {
- send(500, nil, err)
+ ctx.Handle(500, "SendIssueMentionMail", err)
return
}
}
- send(200, fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index), nil)
+ log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
+ ctx.Redirect(fmt.Sprintf("%s/issues/%d#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag()))
}
func Labels(ctx *middleware.Context) {