Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to mark Conversation (code comment) resolved #11037

Merged
merged 18 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ func (c *Comment) LoadResolveDoer() (err error) {
}
c.ResolveDoer, err = getUserByID(x, c.ResolveDoerID)
if err != nil {
return
if IsErrUserNotExist(err) {
c.ResolveDoerID = -1
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
c.ResolveDoer = NewGhostUser()
err = nil
}
}
return
}
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ var migrations = []Migration{
NewMigration("Refix merge base for merged pull requests", refixMergeBase),
// v135 -> 136
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
NewMigration("Add OrgID column to Labels table", addOrgIDLabelColumn),
// v136 -> 137
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
NewMigration("Add ResolveDoerID to Comment table", addResolveDoerIDCommentColumn),
}

// GetCurrentDBVersion returns the current db version
Expand Down
22 changes: 22 additions & 0 deletions models/migrations/v136.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"

"xorm.io/xorm"
)

func addResolveDoerIDCommentColumn(x *xorm.Engine) error {
type Comment struct {
ResolveDoerID int64
}

if err := x.Sync2(new(Comment)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
return nil
}
8 changes: 3 additions & 5 deletions models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,9 @@ func CanMarkConversation(issue *Issue, doer *User) (permResult bool, err error)
}

if doer.ID != issue.PosterID {
if issue.Repo == nil {
err = issue.LoadRepo()
if err != nil {
return false, err
}
err = issue.LoadRepo()
if err != nil {
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
return false, err
}

perm, err := GetUserRepoPermission(issue.Repo, doer)
Expand Down
25 changes: 11 additions & 14 deletions routers/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,31 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
// UpdateResolveConversation add or remove an Conversation resolved mark
func UpdateResolveConversation(ctx *context.Context) {
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
action := ctx.Query("action")
issueID := ctx.QueryInt64("issue_id")
commentID := ctx.QueryInt64("comment_id")
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved

issue, err := models.GetIssueByID(issueID)
comment, err := models.GetCommentByID(commentID)
if err != nil {
ctx.ServerError("GetIssueByID", err)
return
}

if err = comment.LoadIssue(); err != nil {
ctx.ServerError("comment.LoadIssue", err)
return
}

var permResult bool
if permResult, err = models.CanMarkConversation(issue, ctx.User); err != nil {
if permResult, err = models.CanMarkConversation(comment.Issue, ctx.User); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
if !permResult {
ctx.ServerError("UpdateResolveConversation",
fmt.Errorf("doer can't permission [usser_id: %d, issue_id: %d]",
ctx.User.ID, issue.ID))
return
}

if !issue.IsPull {
ctx.Error(403)
return
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
}

comment, err := models.GetCommentByID(commentID)
if err != nil {
ctx.ServerError("GetCommentByID", err)
if !comment.Issue.IsPull {
ctx.Error(400)
return
}

Expand All @@ -102,7 +99,7 @@ func UpdateResolveConversation(ctx *context.Context) {
return
}
} else {
ctx.ServerError("UpdateResolveConversation", fmt.Errorf("error action : %s", action))
ctx.Error(400)
return
}

Expand Down
9 changes: 5 additions & 4 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
{{if gt (len $line.Comments) 0}}
{{$resolved := (index $line.Comments 0).IsResolved}}
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
<tr class="add-code-comment">
<td class="lines-num"></td>
<td class="lines-type-marker"></td>
Expand All @@ -174,8 +175,8 @@
</ui>
</div>
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
{{if $.CanMarkConversation }}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-issue-id="{{$.Issue.ID}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
{{if and $.CanMarkConversation $isNotPending}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
{{if $resolved}}
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
{{else}}
Expand Down Expand Up @@ -210,8 +211,8 @@
</ui>
</div>
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
{{if $.CanMarkConversation}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-issue-id="{{$.Issue.ID}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
{{if and $.CanMarkConversation $isNotPending}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
{{if $resolved}}
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
{{else}}
Expand Down
5 changes: 3 additions & 2 deletions templates/repo/diff/section_unified.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{{if gt (len $line.Comments) 0}}
{{$resolved := (index $line.Comments 0).IsResolved}}
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
<tr>
<td colspan="2" class="lines-num"></td>
<td class="lines-type-marker"></td>
Expand All @@ -49,8 +50,8 @@
</ui>
</div>
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index $line.Comments 0).ReviewID "root" $.root "comment" (index $line.Comments 0)}}
{{if $.root.CanMarkConversation}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-issue-id="{{$.root.Issue.ID}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.root.RepoLink}}/issues/resolve_conversation" >
{{if and $.root.CanMarkConversation $isNotPending}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.root.RepoLink}}/issues/resolve_conversation" >
{{if $resolved}}
{{$.root.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
{{else}}
Expand Down
5 changes: 3 additions & 2 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@
{{$invalid := (index $comms 0).Invalidated}}
{{$resolved := (index $comms 0).IsResolved}}
{{$resolveDoer := (index $comms 0).ResolveDoer}}
{{$isNotPending := (not (eq (index $comms 0).Review.Type 0))}}
{{if or $invalid $resolved}}
<button id="show-outdated-{{(index $comms 0).ID}}" data-comment="{{(index $comms 0).ID}}" class="ui compact right labeled button show-outdated">
{{svg "octicon-unfold" 16}}
Expand Down Expand Up @@ -457,8 +458,8 @@
</div>
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index $comms 0).ReviewID "root" $ "comment" (index $comms 0)}}

{{if $.CanMarkConversation}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-issue-id="{{$.Issue.ID}}" data-comment-id="{{(index $comms 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
{{if and $.CanMarkConversation $isNotPending}}
<button class="ui green icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $comms 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
{{if $resolved}}
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
{{else}}
Expand Down
2 changes: 0 additions & 2 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2569,13 +2569,11 @@ $(document).ready(async () => {
e.preventDefault();
const id = $(this).data('comment-id');
const action = $(this).data('action');
const issue_id = $(this).data('issue-id');
const url = $(this).data('update-url');

$.post(url, {
_csrf: csrf,
action,
issue_id,
comment_id: id,
}).then(reload);
});
Expand Down