mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-15 09:58:28 -07:00
#1601 support delete issue comment
This commit is contained in:
parent
2295fafb34
commit
899e799459
4
Makefile
4
Makefile
@ -24,6 +24,10 @@ govet:
|
||||
go tool vet -composites=false -methods=false -structtags=false .
|
||||
|
||||
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)'
|
||||
cp '$(GOPATH)/bin/gogs' .
|
||||
|
||||
|
@ -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)
|
||||
|
||||
##### 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 |
|
||||
|:-------------:|:-------:|:-------:|
|
||||
|
@ -464,7 +464,10 @@ func runWeb(ctx *cli.Context) error {
|
||||
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.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
|
||||
m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
|
||||
|
@ -466,7 +466,8 @@ issues.next = Next
|
||||
issues.open_title = Open
|
||||
issues.closed_title = Closed
|
||||
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.close_issue = Close
|
||||
issues.close_comment_issue = Comment and close
|
||||
|
2
gogs.go
2
gogs.go
@ -17,7 +17,7 @@ import (
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.9.54.0724"
|
||||
const APP_VER = "0.9.55.0726"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -345,3 +345,29 @@ func UpdateComment(c *Comment) error {
|
||||
_, err := x.Id(c.ID).AllCols().Update(c)
|
||||
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()
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -105,6 +105,19 @@ func (ctx *Context) Handle(status int, title string, err error) {
|
||||
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) {
|
||||
if (status/100 == 4) || (status/100 == 5) {
|
||||
log.Error(4, "%s", title)
|
||||
|
@ -1452,7 +1452,10 @@ footer .ui.language .menu {
|
||||
.repository.view.issue .comment-list .comment .actions .item {
|
||||
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-left: 10px;
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ function initRepository() {
|
||||
|
||||
// Edit issue or comment content
|
||||
$('.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 $render_content = $segment.find('.render-content');
|
||||
var $raw_content = $segment.find('.raw-content');
|
||||
@ -404,6 +404,19 @@ function initRepository() {
|
||||
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
|
||||
var $status_btn = $('#status-button');
|
||||
$('#content').keyup(function () {
|
||||
|
@ -393,10 +393,13 @@
|
||||
.actions {
|
||||
.item {
|
||||
float: left;
|
||||
}
|
||||
a.item {
|
||||
margin-top: 6px;
|
||||
margin-left: 10px;
|
||||
&.tag {
|
||||
margin-right: 5px;
|
||||
}
|
||||
&.action {
|
||||
margin-top: 6px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.content {
|
||||
|
@ -803,11 +803,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
||||
func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.Handle(404, "GetIssueByIndex", err)
|
||||
} else {
|
||||
ctx.Handle(500, "GetIssueByIndex", err)
|
||||
}
|
||||
ctx.HandleError("GetIssueByIndex", models.IsErrIssueNotExist, err, 404)
|
||||
return
|
||||
}
|
||||
if issue.IsPull {
|
||||
@ -899,11 +895,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
||||
func UpdateCommentContent(ctx *context.Context) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrCommentNotExist(err) {
|
||||
ctx.Error(404, "GetCommentByID")
|
||||
} else {
|
||||
ctx.Handle(500, "GetCommentByID", err)
|
||||
}
|
||||
ctx.HandleError("GetCommentByID", models.IsErrCommentNotExist, err, 404)
|
||||
return
|
||||
}
|
||||
|
||||
@ -922,7 +914,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
if err := models.UpdateComment(comment); err != nil {
|
||||
if err = models.UpdateComment(comment); err != nil {
|
||||
ctx.Handle(500, "UpdateComment", err)
|
||||
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) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.labels")
|
||||
ctx.Data["PageIsIssueList"] = true
|
||||
|
@ -1 +1 @@
|
||||
0.9.54.0724
|
||||
0.9.55.0726
|
@ -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>
|
||||
<div class="ui right actions">
|
||||
{{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}}
|
||||
</div>
|
||||
</div>
|
||||
@ -52,7 +54,7 @@
|
||||
|
||||
<!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF -->
|
||||
{{if eq .Type 0}}
|
||||
<div class="comment">
|
||||
<div class="comment" id="{{.HashTag}}">
|
||||
<a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
|
||||
<img src="{{.Poster.AvatarLink}}">
|
||||
</a>
|
||||
@ -72,7 +74,10 @@
|
||||
</div>
|
||||
{{end}}
|
||||
{{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}}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user