-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 repo search result #2600
Fix repo search result #2600
Conversation
14ae44a
to
c35c3a9
Compare
4a60099
to
e4f1f1e
Compare
Codecov Report
@@ Coverage Diff @@
## master #2600 +/- ##
=========================================
+ Coverage 27.32% 27.4% +0.08%
=========================================
Files 86 86
Lines 17143 17165 +22
=========================================
+ Hits 4684 4704 +20
- Misses 11781 11782 +1
- Partials 678 679 +1
Continue to review full report at Codecov.
|
First, you are using my (older) tests, while PR with my tests is still pending (#2575). Second, you had problem with review of my changes to repo search because PR was too big but now you are doing the same. I am dividing that PR to multiple PRs one by one, now blocked only by aprooving and merging... So I don't understand (and don't like) this. |
@Morlinest As I told you in a PM in discord. Your tests are great. And instead of pushing a whole refactoring and fix I only did a fix. Your refactoring should be added after this and all is fine. |
But why you are adding tests when I've already posted PR with tests only? |
Because these are tests for the old code with |
@daviian That tests contain it too. I think you missed it:
It should be same (old vs new version), only rewritten to |
@Morlinest It was important for me to leave existing code as it is. Just to make it more easier to see that nothing has changed. A rewriting of tests doesn't necessarily mean that tests haven't changed. And as you can see it was important for me to give credits to you too. |
I've created that tests, they are not in codebase, they have same results and improved. I haven't spent a little amount of time to do it. Nor first version of tests, nor second one. |
e4f1f1e
to
866c5cf
Compare
@Morlinest Changed PR such that it totally uses your commit. And if that doesn't please you I can offer you to take my code from that PR and create your own PR. Or i remove your tests from this PR. What would you like? |
@@ -46,6 +46,220 @@ func TestAPISearchRepoNotLogin(t *testing.T) { | |||
assert.Contains(t, repo.Name, keyword) | |||
assert.False(t, repo.Private) | |||
} | |||
|
|||
// Should return all (max 50) public repositories | |||
req = NewRequest(t, "GET", "/api/v1/repos/search?limit=50") |
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 a lot of duplicated code. Maybe we should add a helper function
func apiRepoSearchResult(t testing.T, params string, expectedLen int) *api.SearchResults
...
apiRepoSearchResult(t, "?limit=50", 12)
Even better, add a session parameter, so you can use it for the logged-in tests too.
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.
@ethantkoenig If you want that you can review #2575 as it rewrites tests. I wanted to change as few as possible to make reviewing easier, but if it is desired the mentioned PR does this ;-)
@@ -350,8 +350,11 @@ func GetOrgsByUserID(userID int64, showAll bool) ([]*User, error) { | |||
return getOrgsByUserID(sess, userID, showAll) | |||
} | |||
|
|||
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) { | |||
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64, showAll bool) ([]*User, error) { |
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.
nit: could we call it includePrivate
or something similar so it is clearer what is included and unincluded when the parameter is false
?
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 called it showAll to be consistent with other methods used similarly. But I can change that at least for my PR.
assert.Len(t, repos, 3) | ||
|
||
// Get all public repositories by name | ||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{ |
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 a lot of duplicated code, maybe we should make this a table-driven test.
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.
Same as above ;-)
@daviian You know I have PR for solving problems with this function :). Anyway, regardless of tests. I looked at your changes to implementation. It looks like something I was doing in first version of my PR, see dae998e. You are making same authorization decisions inside that shouldn't be there. I think more changes to current implementation with My opinion: |
@Morlinest And last but not least and as I said multiple times: This PR doesn't replace your refactoring, which includes changing search behaviour. It is only an interim step to fix permission problems. |
opts.Searcher.ID, opts.Searcher.ID)) | ||
} | ||
} else if opts.OwnerID > 0 { |
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.
Not needed. It's already inside opts.OwnerID > 0
block.
return nil, 0, fmt.Errorf("User: %v", err) | ||
} | ||
|
||
err = owner.GetOwnedOrganizations(false) |
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.
Authorization decision making.
if err != nil { | ||
return nil, 0, fmt.Errorf("Organization: %v", err) | ||
} | ||
|
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.
Missing collaborate
repos.
} | ||
searcherReposCond = searcherReposCond.Or(builder.In("owner_id", ownerIds)) |
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.
Already in condition, line 157.
Closing PR as there exist scenarios in which this only solves a small portion of the search problem. But I want to point out that search should be fixed asap it is a massive security issue IMO. |
Targets #2562, #2399, #1794 and #2595 too.
fixes wrong search result.
Most of the changes are adding tests from @Morlinest