Browse Source

#1601 support delete issue comment

pull/3333/head
Unknwon 8 years ago
parent
commit
899e799459
  1. 4
      Makefile
  2. 2
      README.md
  3. 5
      cmd/web.go
  4. 3
      conf/locale/locale_en-US.ini
  5. 2
      gogs.go
  6. 26
      models/issue_comment.go
  7. 4
      modules/bindata/bindata.go
  8. 13
      modules/context/context.go
  9. 5
      public/css/gogs.css
  10. 15
      public/js/gogs.js
  11. 11
      public/less/_repository.less
  12. 37
      routers/repo/issue.go
  13. 2
      templates/.VERSION
  14. 11
      templates/repo/issue/view_content.tmpl

4
Makefile

@ -24,6 +24,10 @@ govet:
go tool vet -composites=false -methods=false -structtags=false . go tool vet -composites=false -methods=false -structtags=false .
build-dev: $(GENERATED) govet build-dev: $(GENERATED) govet
go install $(BUILD_FLAGS) -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' .
build-dev-race: $(GENERATED) govet
go install $(BUILD_FLAGS) -race -tags '$(TAGS)' go install $(BUILD_FLAGS) -race -tags '$(TAGS)'
cp '$(GOPATH)/bin/gogs' . cp '$(GOPATH)/bin/gogs' .

2
README.md

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.54 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) ##### Current tip version: 0.9.55 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

5
cmd/web.go

@ -464,7 +464,10 @@ func runWeb(ctx *cli.Context) error {
m.Post("/content", repo.UpdateIssueContent) m.Post("/content", repo.UpdateIssueContent)
}) })
}) })
m.Post("/comments/:id", repo.UpdateCommentContent) m.Group("/comments/:id", func() {
m.Post("", repo.UpdateCommentContent)
m.Post("/delete", repo.DeleteComment)
})
m.Group("/labels", func() { m.Group("/labels", func() {
m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel) m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)

3
conf/locale/locale_en-US.ini

@ -466,7 +466,8 @@ issues.next = Next
issues.open_title = Open issues.open_title = Open
issues.closed_title = Closed issues.closed_title = Closed
issues.num_comments = %d comments issues.num_comments = %d comments
issues.commented_at = `commented <a id="%[1]s" href="#%[1]s">%[2]s</a>` issues.commented_at = `commented <a href="#%s">%s</a>`
issues.delete_comment_confirm = Are you sure you want to delete this comment?
issues.no_content = There is no content yet. issues.no_content = There is no content yet.
issues.close_issue = Close issues.close_issue = Close
issues.close_comment_issue = Comment and close issues.close_comment_issue = Comment and close

2
gogs.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.54.0724" const APP_VER = "0.9.55.0726"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

26
models/issue_comment.go

@ -345,3 +345,29 @@ func UpdateComment(c *Comment) error {
_, err := x.Id(c.ID).AllCols().Update(c) _, err := x.Id(c.ID).AllCols().Update(c)
return err return err
} }
// DeleteCommentByID deletes a comment by given ID.
func DeleteCommentByID(id int64) error {
comment, err := GetCommentByID(id)
if err != nil {
return err
}
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
if _, err = sess.Id(comment.ID).Delete(new(Comment)); err != nil {
return err
}
if comment.Type == COMMENT_TYPE_COMMENT {
if _, err = sess.Exec("UPDATE `issue` SET num_comments = num_comments - 1 WHERE id = ?", comment.IssueID); err != nil {
return err
}
}
return sess.Commit()
}

4
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

13
modules/context/context.go

@ -105,6 +105,19 @@ func (ctx *Context) Handle(status int, title string, err error) {
ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status)))
} }
// HandleError use error check function to determine if server should
// response as client input error or server internal error.
// It responses with given status code for client error,
// or error context description for logging purpose of server error.
func (ctx *Context) HandleError(title string, errck func(error) bool, err error, status int) {
if errck(err) {
ctx.Error(status, err.Error())
return
}
ctx.Handle(500, title, err)
}
func (ctx *Context) HandleText(status int, title string) { func (ctx *Context) HandleText(status int, title string) {
if (status/100 == 4) || (status/100 == 5) { if (status/100 == 4) || (status/100 == 5) {
log.Error(4, "%s", title) log.Error(4, "%s", title)

5
public/css/gogs.css

@ -1452,7 +1452,10 @@ footer .ui.language .menu {
.repository.view.issue .comment-list .comment .actions .item { .repository.view.issue .comment-list .comment .actions .item {
float: left; float: left;
} }
.repository.view.issue .comment-list .comment .actions a.item { .repository.view.issue .comment-list .comment .actions .item.tag {
margin-right: 5px;
}
.repository.view.issue .comment-list .comment .actions .item.action {
margin-top: 6px; margin-top: 6px;
margin-left: 10px; margin-left: 10px;
} }

15
public/js/gogs.js

@ -342,7 +342,7 @@ function initRepository() {
// Edit issue or comment content // Edit issue or comment content
$('.edit-content').click(function () { $('.edit-content').click(function () {
var $segment = $(this).parent().parent().next(); var $segment = $(this).parent().parent().parent().next();
var $edit_content_zone = $segment.find('.edit-content-zone'); var $edit_content_zone = $segment.find('.edit-content-zone');
var $render_content = $segment.find('.render-content'); var $render_content = $segment.find('.render-content');
var $raw_content = $segment.find('.raw-content'); var $raw_content = $segment.find('.raw-content');
@ -404,6 +404,19 @@ function initRepository() {
return false; return false;
}); });
// Delete comment
$('.delete-comment').click(function () {
var $this = $(this);
if (confirm($this.data('locale'))) {
$.post($this.data('url'), {
"_csrf": csrf
}).success(function() {
$('#' + $this.data('comment-id')).remove();
})
}
return false;
});
// Change status // Change status
var $status_btn = $('#status-button'); var $status_btn = $('#status-button');
$('#content').keyup(function () { $('#content').keyup(function () {

11
public/less/_repository.less

@ -393,10 +393,13 @@
.actions { .actions {
.item { .item {
float: left; float: left;
} &.tag {
a.item { margin-right: 5px;
margin-top: 6px; }
margin-left: 10px; &.action {
margin-top: 6px;
margin-left: 10px;
}
} }
} }
.content { .content {

37
routers/repo/issue.go

@ -803,11 +803,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
func NewComment(ctx *context.Context, form auth.CreateCommentForm) { func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
if models.IsErrIssueNotExist(err) { ctx.HandleError("GetIssueByIndex", models.IsErrIssueNotExist, err, 404)
ctx.Handle(404, "GetIssueByIndex", err)
} else {
ctx.Handle(500, "GetIssueByIndex", err)
}
return return
} }
if issue.IsPull { if issue.IsPull {
@ -899,11 +895,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
func UpdateCommentContent(ctx *context.Context) { func UpdateCommentContent(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if models.IsErrCommentNotExist(err) { ctx.HandleError("GetCommentByID", models.IsErrCommentNotExist, err, 404)
ctx.Error(404, "GetCommentByID")
} else {
ctx.Handle(500, "GetCommentByID", err)
}
return return
} }
@ -922,7 +914,7 @@ func UpdateCommentContent(ctx *context.Context) {
}) })
return return
} }
if err := models.UpdateComment(comment); err != nil { if err = models.UpdateComment(comment); err != nil {
ctx.Handle(500, "UpdateComment", err) ctx.Handle(500, "UpdateComment", err)
return return
} }
@ -932,6 +924,29 @@ func UpdateCommentContent(ctx *context.Context) {
}) })
} }
func DeleteComment(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
ctx.HandleError("GetCommentByID", models.IsErrCommentNotExist, err, 404)
return
}
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
ctx.Error(403)
return
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
ctx.Error(204)
return
}
if err = models.DeleteCommentByID(comment.ID); err != nil {
ctx.Handle(500, "DeleteCommentByID", err)
return
}
ctx.Status(200)
}
func Labels(ctx *context.Context) { func Labels(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.labels") ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true

2
templates/.VERSION

@ -1 +1 @@
0.9.54.0724 0.9.55.0726

11
templates/repo/issue/view_content.tmpl

@ -20,7 +20,9 @@
<span class="text grey"><a {{if gt .Issue.Poster.ID 0}}href="{{.Issue.Poster.HomeLink}}"{{end}}>{{.Issue.Poster.Name}}</a> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}</span> <span class="text grey"><a {{if gt .Issue.Poster.ID 0}}href="{{.Issue.Poster.HomeLink}}"{{end}}>{{.Issue.Poster.Name}}</a> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}</span>
<div class="ui right actions"> <div class="ui right actions">
{{if .IsIssueOwner}} {{if .IsIssueOwner}}
<a class="edit-content item" href="#"><i class="octicon octicon-pencil"></i></a> <div class="item action">
<a class="edit-content" href="#"><i class="octicon octicon-pencil"></i></a>
</div>
{{end}} {{end}}
</div> </div>
</div> </div>
@ -52,7 +54,7 @@
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF --> <!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF -->
{{if eq .Type 0}} {{if eq .Type 0}}
<div class="comment"> <div class="comment" id="{{.HashTag}}">
<a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}> <a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
<img src="{{.Poster.AvatarLink}}"> <img src="{{.Poster.AvatarLink}}">
</a> </a>
@ -72,7 +74,10 @@
</div> </div>
{{end}} {{end}}
{{if or $.IsRepositoryAdmin (eq .Poster.ID $.SignedUserID)}} {{if or $.IsRepositoryAdmin (eq .Poster.ID $.SignedUserID)}}
<a class="edit-content item" href="#"><i class="octicon octicon-pencil"></i></a> <div class="item action">
<a class="edit-content" href="#"><i class="octicon octicon-pencil"></i></a>
<a class="delete-comment" href="#" data-comment-id={{.HashTag}} data-url="{{$.RepoLink}}/comments/{{.ID}}/delete" data-locale="{{$.i18n.Tr "repo.issues.delete_comment_confirm"}}"><i class="octicon octicon-x"></i></a>
</div>
{{end}} {{end}}
</div> </div>
</div> </div>

Loading…
Cancel
Save