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

Fix "Dashboard shows deleted comments" #1995

Merged
merged 24 commits into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
74774a4
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
f385727
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
e05eb96
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
5cb36ca
Added comment's hashtag to url for mail notifications.
jonasfranz May 4, 2017
2dd674e
Replacing in-line link generation with HTMLURL. (+gofmt)
jonasfranz May 4, 2017
716bf81
Replaced action-based model with nil-based model. (+gofmt)
jonasfranz May 4, 2017
edaa576
Replaced mailIssueActionToParticipants with mailIssueCommentToPartici…
jonasfranz May 4, 2017
b0e22ab
Updating comment for mailIssueCommentToParticipants
jonasfranz May 4, 2017
fd70385
Merge branch 'master' of github.com:JonasFranzDEV/gitea
jonasfranz Jun 13, 2017
3c6d4fc
Merge branch 'master' of https://github.com/JonasFranzDEV/gitea
jonasfranz Jun 15, 2017
36ae732
Added link to comment in "Dashboard"
jonasfranz Jun 15, 2017
1826b2b
Added migration
jonasfranz Jun 17, 2017
bb33f2e
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
3f1c85c
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
5791853
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
deddcda
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
70d8dd9
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
3b99726
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
9e18513
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
0e20e81
Added improved migration to add a CommentID column to action.
jonasfranz Jun 17, 2017
8818bc7
Added improved links to comments in feed entries. (+ gofmt) Signed-o…
jonasfranz Jun 18, 2017
3e1241c
Fixes #1956 by filtering for deleted comments that are referenced in …
jonasfranz Jun 22, 2017
3ee3dc3
Fixes #1956 by filtering for deleted comments.
jonasfranz Jun 23, 2017
56a64e3
Fixes #1956 by filtering for deleted comments.
jonasfranz Jun 25, 2017
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
72 changes: 56 additions & 16 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"path"
"regexp"
"strconv"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -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"`
Copy link
Member

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?

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
Expand Down Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove newline before if err != nil {

return "#"
}

issue, err := GetIssueByID(issueID)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove newline before if err != nil {

return "#"
}

return issue.HTMLURL()
}

// GetBranch returns the action's repository branch.
func (a *Action) GetBranch() string {
return a.RefName
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
27 changes: 15 additions & 12 deletions models/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ func TestGetFeeds(t *testing.T) {
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)

actions, err := GetFeeds(GetFeedsOptions{
RequestedUser: user,
RequestingUserID: user.ID,
IncludePrivate: true,
OnlyPerformedBy: false,
RequestedUser: user,
RequestingUserID: user.ID,
IncludePrivate: true,
OnlyPerformedBy: false,
IncludeDeletedComments: true,
})
assert.NoError(t, err)
assert.Len(t, actions, 1)
Expand All @@ -333,21 +334,23 @@ func TestGetFeeds2(t *testing.T) {
userID := AssertExistsAndLoadBean(t, &OrgUser{OrgID: org.ID, IsOwner: true}).(*OrgUser).UID

actions, err := GetFeeds(GetFeedsOptions{
RequestedUser: org,
RequestingUserID: userID,
IncludePrivate: true,
OnlyPerformedBy: false,
RequestedUser: org,
RequestingUserID: userID,
IncludePrivate: true,
OnlyPerformedBy: false,
IncludeDeletedComments: true,
})
assert.NoError(t, err)
assert.Len(t, actions, 1)
assert.EqualValues(t, 2, actions[0].ID)
assert.EqualValues(t, org.ID, actions[0].UserID)

actions, err = GetFeeds(GetFeedsOptions{
RequestedUser: org,
RequestingUserID: userID,
IncludePrivate: false,
OnlyPerformedBy: false,
RequestedUser: org,
RequestingUserID: userID,
IncludePrivate: false,
OnlyPerformedBy: false,
IncludeDeletedComments: true,
})
assert.NoError(t, err)
assert.Len(t, actions, 0)
Expand Down
4 changes: 4 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -641,5 +643,7 @@ func DeleteComment(comment *Comment) error {
}
}

sess.Exec("UPDATE `action` SET comment_deleted = 1 WHERE comment_id = ?", comment.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use xorm update function


return sess.Commit()
}
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ var migrations = []Migration{
NewMigration("remove columns from action", removeActionColumns),
// v34 -> v35
NewMigration("give all units to owner teams", giveAllUnitsToOwnerTeams),
// v35 -> v36
NewMigration("adds comment to an action", addCommentIDToAction),
}

// Migrate database to current version
Expand Down
29 changes: 29 additions & 0 deletions models/migrations/v35.go
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
}
13 changes: 7 additions & 6 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
}

// retrieveFeeds loads feeds for the specified user
func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isProfile bool) {
func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isProfile bool, includeDeletedComments bool) {
var requestingID int64
if ctx.User != nil {
requestingID = ctx.User.ID
}
actions, err := models.GetFeeds(models.GetFeedsOptions{
RequestedUser: user,
RequestingUserID: requestingID,
IncludePrivate: includePrivate,
OnlyPerformedBy: isProfile,
RequestedUser: user,
RequestingUserID: requestingID,
IncludePrivate: includePrivate,
OnlyPerformedBy: isProfile,
IncludeDeletedComments: includeDeletedComments,
})
if err != nil {
ctx.Handle(500, "GetFeeds", err)
Expand Down Expand Up @@ -186,7 +187,7 @@ func Dashboard(ctx *context.Context) {
ctx.Data["MirrorCount"] = len(mirrors)
ctx.Data["Mirrors"] = mirrors

retrieveFeeds(ctx, ctxUser, true, false)
retrieveFeeds(ctx, ctxUser, true, false, false)
if ctx.Written() {
return
}
Expand Down
2 changes: 1 addition & 1 deletion routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Profile(ctx *context.Context) {
ctx.Data["Keyword"] = keyword
switch tab {
case "activity":
retrieveFeeds(ctx, ctxUser, showPrivate, true)
retrieveFeeds(ctx, ctxUser, showPrivate, true, false)
if ctx.Written() {
return
}
Expand Down
2 changes: 1 addition & 1 deletion templates/user/dashboard/feeds.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{{else if eq .GetOpType 7}}
<span class="text truncate issue title has-emoji">{{index .GetIssueInfos 1}}</span>
{{else if eq .GetOpType 10}}
<span class="text truncate issue title has-emoji">{{.GetIssueTitle}}</span>
<a href="{{.GetCommentLink}}" class="text truncate issue title has-emoji">{{.GetIssueTitle}}</a>
<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
{{else if eq .GetOpType 11}}
<p class="text light grey has-emoji">{{index .GetIssueInfos 1}}</p>
Expand Down