-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add collaborative repositories to the dashboard #2205
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
Conversation
LGTM |
LGTM |
One more thing - integration test for this would be great |
models/repo_list.go
Outdated
@@ -153,6 +154,10 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | |||
} | |||
|
|||
cond = cond.Or(builder.And(builder.Like{"lower_name", opts.Keyword}, builder.In("owner_id", ownerIds))) | |||
|
|||
if opts.Collaborate { | |||
cond = cond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, opts.Searcher.ID, opts.Searcher.ID)) |
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.
This will match all collaborative repos, even ones that do not match the other options (e.g. opts.Private
, opts.Keyword
, ...)
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.
^
routers/user/home.go
Outdated
@@ -54,7 +54,7 @@ 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, includeDeletedComments bool) { | |||
func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isProfile, includeCollaborate bool, includeDeletedComments bool) { |
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.
It might be time to add an options type for this function. If I see something like retrieveFeeds(ctx, ctxUser, true, false, true, false)
, I'll have no idea what it means without further investigating.
We could also reuse the GetFeedsOptions
type instead of introducing a new options type, since most of the current argument map directly to GetFeedsOptions
fields.
Make LG-TM work |
models/action.go
Outdated
@@ -746,5 +747,8 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) { | |||
|
|||
} | |||
|
|||
if opts.Collaborate { |
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.
This will drop other conditions like opts.IncludeDeleted
. I think this method should refactor via builder
otherwise it's still not correct.
models/repo_list.go
Outdated
@@ -153,6 +154,10 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | |||
} | |||
|
|||
cond = cond.Or(builder.And(builder.Like{"lower_name", opts.Keyword}, builder.In("owner_id", ownerIds))) | |||
|
|||
if opts.Collaborate { | |||
cond = cond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, opts.Searcher.ID, opts.Searcher.ID)) |
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.
^
6de7ed7
to
47e8494
Compare
Fixed |
models/action.go
Outdated
|
||
} | ||
|
||
return actions, sess.Find(&actions) | ||
if opts.Collaborate { |
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.
I mean maybe we should move these 3 lines to line 737 ?
if opts.Collaborate {
cond = builder.Eq{"user_id": opts.RequestedUser.ID}.Or(
builder.Expr(`repo_id IN (SELECT repo_id FROM "access" WHERE access.user_id = ?)`, opts.RequestedUser.ID)
)
} else {
cond = builder.Eq{"user_id": opts.RequestedUser.ID}
}
@Bwko do you have time to fix this PR? |
@lunny Done |
models/action.go
Outdated
@@ -728,23 +730,31 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) { | |||
} | |||
|
|||
actions := make([]*Action, 0, 20) | |||
cond := builder.NewCond() | |||
sess := x.Limit(20). |
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.
Put this line to the end of the function is perfect.
models/repo_list.go
Outdated
@@ -153,6 +154,11 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | |||
} | |||
|
|||
cond = cond.Or(builder.And(builder.Like{"lower_name", opts.Keyword}, builder.In("owner_id", ownerIds))) | |||
|
|||
if opts.Collaborate { | |||
cond = cond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, opts.Searcher.ID, opts.Searcher.ID), |
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.
This is still not correct. This will match repos that do not match the opts.Starred
or opts.OwnerID
options.
Apologies if I wasn't clear in my previous comment. Instead of relisting all the other conditions (which is fragile if we add more options), I think we should do something like
// compute ownerIds, existing code up to line 154 is fine
searcherReposCond := builder.In("owner_id", ownerIds)
if opts.Collaborate {
searcherReposCond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, opts.Searcher.ID, opts.Searcher.ID)
}
cond.And(searcherReposCond)
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.
That's what I want to say.
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.
But some bug
searcherReposCond := builder.In("owner_id", ownerIds)
if opts.Collaborate {
searcherReposCond = searcherReposCond.Or(builder.Expr(`id IN (SELECT repo_id FROM "access" WHERE access.user_id = ? AND owner_id != ?)`, opts.Searcher.ID, opts.Searcher.ID)
}
cond = cond.And(searcherReposCond)
@Bwko do you have time to fix this? |
Remove some unused code from the Dashboard func
Trusted LGTM |
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.
cond = builder.Eq{"user_id": opts.RequestedUser.ID}.Or( | ||
builder.Expr(`repo_id IN (SELECT repo_id FROM "access" WHERE access.user_id = ?)`, opts.RequestedUser.ID)) | ||
} else { | ||
cond = builder.Eq{"user_id": opts.RequestedUser.ID} |
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.
I don't think this is right. The assignments on lines 737 and 740 will overwrite the assignment on line 733.
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.
good catch
@lunny @lafriks @andreynering @Bwko Hi, don't know if I am doing something wrong, but it looks like this PR actually removed all collaborative repositories instead of adding any (nice paradox :D) and doubled some feeds. Did anyone test it? |
Remove some unused code from the Dashboard func
Fixes #2114