-
-
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
Fix "Dashboard shows deleted comments" #1995
Changes from 23 commits
74774a4
f385727
e05eb96
5cb36ca
2dd674e
716bf81
edaa576
b0e22ab
fd70385
3c6d4fc
36ae732
1826b2b
bb33f2e
3f1c85c
5791853
deddcda
70d8dd9
3b99726
9e18513
0e20e81
8818bc7
3e1241c
3ee3dc3
56a64e3
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"fmt" | ||
"path" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
"time" | ||
"unicode" | ||
|
@@ -70,18 +71,21 @@ func init() { | |
// repository. It implemented interface base.Actioner so that can be | ||
// used in template render. | ||
type Action struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
UserID int64 `xorm:"INDEX"` // Receiver user id. | ||
OpType ActionType | ||
ActUserID int64 `xorm:"INDEX"` // Action user id. | ||
ActUser *User `xorm:"-"` | ||
RepoID int64 `xorm:"INDEX"` | ||
Repo *Repository `xorm:"-"` | ||
RefName string | ||
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` | ||
Content string `xorm:"TEXT"` | ||
Created time.Time `xorm:"-"` | ||
CreatedUnix int64 `xorm:"INDEX"` | ||
ID int64 `xorm:"pk autoincr"` | ||
UserID int64 `xorm:"INDEX"` // Receiver user id. | ||
OpType ActionType | ||
ActUserID int64 `xorm:"INDEX"` // Action user id. | ||
ActUser *User `xorm:"-"` | ||
RepoID int64 `xorm:"INDEX"` | ||
Repo *Repository `xorm:"-"` | ||
CommentID int64 `xorm:"INDEX"` | ||
Comment *Comment `xorm:"-"` | ||
CommentDeleted bool `xorm:"default 0 not null"` | ||
RefName string | ||
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` | ||
Content string `xorm:"TEXT"` | ||
Created time.Time `xorm:"-"` | ||
CreatedUnix int64 `xorm:"INDEX"` | ||
} | ||
|
||
// BeforeInsert will be invoked by XORM before inserting a record | ||
|
@@ -191,6 +195,35 @@ func (a *Action) GetRepoLink() string { | |
return "/" + a.GetRepoPath() | ||
} | ||
|
||
// GetCommentLink returns link to action comment. | ||
func (a *Action) GetCommentLink() string { | ||
if a == nil { | ||
return "#" | ||
} | ||
if a.Comment == nil && a.CommentID != 0 { | ||
a.Comment, _ = GetCommentByID(a.CommentID) | ||
} | ||
if a.Comment != nil { | ||
return a.Comment.HTMLURL() | ||
} | ||
if len(a.GetIssueInfos()) == 0 { | ||
return "#" | ||
} | ||
//Return link to issue | ||
issueIDString := a.GetIssueInfos()[0] | ||
issueID, err := strconv.ParseInt(issueIDString, 10, 64) | ||
if err != nil { | ||
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. Please remove newline before |
||
return "#" | ||
} | ||
|
||
issue, err := GetIssueByID(issueID) | ||
if err != nil { | ||
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. Please remove newline before |
||
return "#" | ||
} | ||
|
||
return issue.HTMLURL() | ||
} | ||
|
||
// GetBranch returns the action's repository branch. | ||
func (a *Action) GetBranch() string { | ||
return a.RefName | ||
|
@@ -674,10 +707,11 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error | |
|
||
// GetFeedsOptions options for retrieving feeds | ||
type GetFeedsOptions struct { | ||
RequestedUser *User | ||
RequestingUserID int64 | ||
IncludePrivate bool // include private actions | ||
OnlyPerformedBy bool // only actions performed by requested user | ||
RequestedUser *User | ||
RequestingUserID int64 | ||
IncludePrivate bool // include private actions | ||
OnlyPerformedBy bool // only actions performed by requested user | ||
IncludeDeletedComments bool // include comments that reference a deleted comment | ||
} | ||
|
||
// GetFeeds returns actions according to the provided options | ||
|
@@ -706,5 +740,11 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) { | |
if opts.RequestedUser.IsOrganization() { | ||
sess.In("repo_id", repoIDs) | ||
} | ||
|
||
if !opts.IncludeDeletedComments { | ||
sess.And("comment_deleted = ?", false) | ||
|
||
} | ||
|
||
return actions, sess.Find(&actions) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,6 +334,8 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err | |
Content: fmt.Sprintf("%d|%s", opts.Issue.Index, strings.Split(opts.Content, "\n")[0]), | ||
RepoID: opts.Repo.ID, | ||
Repo: opts.Repo, | ||
Comment: comment, | ||
CommentID: comment.ID, | ||
IsPrivate: opts.Repo.IsPrivate, | ||
} | ||
|
||
|
@@ -641,5 +643,7 @@ func DeleteComment(comment *Comment) error { | |
} | ||
} | ||
|
||
sess.Exec("UPDATE `action` SET comment_deleted = 1 WHERE comment_id = ?", comment.ID) | ||
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. Use xorm update function |
||
|
||
return sess.Commit() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2017 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" | ||
|
||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
func addCommentIDToAction(x *xorm.Engine) error { | ||
// Action see models/action.go | ||
type Action struct { | ||
CommentID int64 `xorm:"INDEX"` | ||
CommentDeleted bool `xorm:"default 0 not null"` | ||
} | ||
|
||
if err := x.Sync2(new(Action)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
x.Where("comment_id = 0").Update(&Action{ | ||
CommentDeleted: false, | ||
}) | ||
|
||
return 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.
Do not use 0 and 1 but true and false just like it is used in IsPrivate. Cant this field be reused for other optypes also? So maybe is better call it IsDeleted?