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 collaborative repositories to the dashboard #2205

Merged
merged 3 commits into from
Aug 23, 2017

Conversation

Bwko
Copy link
Member

@Bwko Bwko commented Jul 23, 2017

Remove some unused code from the Dashboard func
Fixes #2114

@andreynering
Copy link
Contributor

LGTM

@andreynering andreynering added modifies/api This PR adds API routes or modifies them type/bug topic/ui Change the appearance of the Gitea UI labels Jul 23, 2017
@lafriks
Copy link
Member

lafriks commented Jul 23, 2017

LGTM

@lafriks lafriks added this to the 1.2.0 milestone Jul 23, 2017
@lafriks lafriks added the lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. label Jul 23, 2017
@lafriks
Copy link
Member

lafriks commented Jul 23, 2017

One more thing - integration test for this would be great

@@ -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))
Copy link
Member

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, ...)

Copy link
Member

Choose a reason for hiding this comment

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

^

@@ -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) {
Copy link
Member

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.

@lafriks
Copy link
Member

lafriks commented Jul 26, 2017

Make LG-TM work

models/action.go Outdated
@@ -746,5 +747,8 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {

}

if opts.Collaborate {
Copy link
Member

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.

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

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

^

@Bwko Bwko force-pushed the collaborate branch 3 times, most recently from 6de7ed7 to 47e8494 Compare July 28, 2017 20:13
@Bwko
Copy link
Member Author

Bwko commented Jul 28, 2017

Fixed

models/action.go Outdated

}

return actions, sess.Find(&actions)
if opts.Collaborate {
Copy link
Member

@lunny lunny Jul 29, 2017

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}
}

@lunny
Copy link
Member

lunny commented Aug 7, 2017

@Bwko do you have time to fix this PR?

@Bwko
Copy link
Member Author

Bwko commented Aug 9, 2017

@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).
Copy link
Member

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.

@@ -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),
Copy link
Member

@ethantkoenig ethantkoenig Aug 10, 2017

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)

Copy link
Member

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.

Copy link
Member

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)

@lafriks
Copy link
Member

lafriks commented Aug 16, 2017

@Bwko do you have time to fix this?

@lunny
Copy link
Member

lunny commented Aug 17, 2017

Since #2285 has refactored the dashboard and fix #2114. This PR will only affect others places. I will move this to v1.3

@lunny lunny modified the milestones: 1.3.0, 1.2.0 Aug 17, 2017
@lafriks lafriks modified the milestones: 1.2.0, 1.3.0 Aug 17, 2017
Remove some unused code from the Dashboard func
@andreynering
Copy link
Contributor

Trusted LGTM

@lunny lunny merged commit 1a5fe43 into go-gitea:master Aug 23, 2017
Copy link
Member

@ethantkoenig ethantkoenig left a 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}
Copy link
Member

@ethantkoenig ethantkoenig Aug 23, 2017

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.

Copy link
Member

Choose a reason for hiding this comment

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

good catch

@Morlinest
Copy link
Member

@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?

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All collaborative repositories disappeared from the dashboard
6 participants