-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Changes from 15 commits
b95fb6f
f962c5e
aa3bae7
b99c2ac
b27c8ad
fdd4b5e
2276cee
a2fa3ee
87672ff
4907d7f
bbbd8b5
982bd6f
3fbc628
655e2b6
6ecd910
4776c11
b7b4c0a
1ae80d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||||||||||||||||||||||||||||||||||||||||
package models | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
"code.gitea.io/gitea/modules/timeutil" | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -594,3 +595,62 @@ func RemoveRewiewRequest(issue *Issue, reviewer *User, doer *User) (comment *Com | |||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
return comment, sess.Commit() | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// MarkConversation Add or remove Conversation mark for a code comment | ||||||||||||||||||||||||||||||||||||||||||||
func MarkConversation(comment *Comment, doer *User, isResolve bool) (err error) { | ||||||||||||||||||||||||||||||||||||||||||||
if comment.Type != CommentTypeCode { | ||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if isResolve { | ||||||||||||||||||||||||||||||||||||||||||||
if comment.ResolveDoerID != 0 { | ||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if _, err = x.Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||
if comment.ResolveDoerID == 0 { | ||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if _, err = x.Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// CanMarkConversation Add or remove Conversation mark for a code comment permission check | ||||||||||||||||||||||||||||||||||||||||||||
// the PR writer , offfcial reviewer and poster can do it | ||||||||||||||||||||||||||||||||||||||||||||
func CanMarkConversation(issue *Issue, doer *User) (permResult bool, err error) { | ||||||||||||||||||||||||||||||||||||||||||||
if doer == nil || issue == nil { | ||||||||||||||||||||||||||||||||||||||||||||
return false, fmt.Errorf("issue or doer is nil") | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if doer.ID != issue.PosterID { | ||||||||||||||||||||||||||||||||||||||||||||
if err = issue.LoadRepo(); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return false, err | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
perm, err := GetUserRepoPermission(issue.Repo, doer) | ||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return false, err | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
permResult = perm.CanAccess(AccessModeWrite, UnitTypePullRequests) | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check if this PR's base branch is protected. If it's protected, we should check if it's official review, otherwise we should check if it's the writer of the pull request unit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, I think I also have done what you say, because Lines 185 to 205 in cc07b9c
|
||||||||||||||||||||||||||||||||||||||||||||
if !permResult { | ||||||||||||||||||||||||||||||||||||||||||||
if permResult, err = IsOfficialReviewer(issue, doer); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||
return false, err | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
if !permResult { | ||||||||||||||||||||||||||||||||||||||||||||
return false, nil | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
return true, nil | ||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user deleted, but the comment should be still loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, But It willn't be error if user is deleted now, it will load an default user to replace it, but the name to show will be not right , that's the thing what I think now. maybe shold save user name instead of user id, then it willn't be a problem , do you think so ? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny If understand what you mean, that's taken care of in
LoadResolveDoer
:gitea/models/issue_comment.go
Lines 430 to 437 in a2fa3ee