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 repository search function #2689

Merged

Conversation

Morlinest
Copy link
Member

@Morlinest Morlinest commented Oct 11, 2017

Rewrite of models.SearchRepositoryByName:

  1. Adds respect of organizations membership visibility
  2. Removes redudant where conditions in search (that was causing showing private repositories not available to OwnerID)
  3. Includes "collaborative" repositories only if opts.Collaborate is set (true)
  4. Removes need for Searcher as this option is confusing (you can't know, if found repository is related to OwnerID or Searcher) and not used if OwnerID is not set
  5. Fixes FIXME parts mentioned in unit and integration tests (integrations/api_repo_test.go and models/repo_list_test.go)
  6. Adds unit tests to test organizations membership visibility
  7. Adds integration tests

Important files are routers/api/v1/repo/repo.go and models/repo_list.go, other files are for tests.

Fixes #2399, #2593.

Main/final part of #2371.

@codecov-io
Copy link

codecov-io commented Oct 11, 2017

Codecov Report

Merging #2689 into master will decrease coverage by 0.05%.
The diff coverage is 64.7%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2689      +/-   ##
==========================================
- Coverage   26.96%   26.91%   -0.06%     
==========================================
  Files          87       87              
  Lines       17297    17285      -12     
==========================================
- Hits         4664     4652      -12     
- Misses      11953    11954       +1     
+ Partials      680      679       -1
Impacted Files Coverage Δ
models/repo_list.go 53.44% <64.7%> (+0.32%) ⬆️
models/user.go 18.24% <0%> (-0.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af4a094...7686465. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 11, 2017
@Morlinest
Copy link
Member Author

One thing I found when testing is that team with read access to public repository is not listed because members are not added in access table. I think we should disable this option (team with read access) when repository is public.

@lunny lunny added this to the 1.3.0 milestone Oct 11, 2017
@lunny lunny added the type/bug label Oct 11, 2017
@Morlinest Morlinest force-pushed the fix/missing-collaborative-repositories branch from b127b46 to d26bdeb Compare October 11, 2017 14:33
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.

It seems that opts.Searcher is no longer used? If this is intentional, then we should remove it from the struct.

}

if !opts.Private {
cond = cond.And(builder.Eq{"is_private": false})
if 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.

This is a duplicate of lines 183-186

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed (rebase doesn't work always as expected :D)

@Morlinest Morlinest force-pushed the fix/missing-collaborative-repositories branch from d26bdeb to 4b584d0 Compare October 11, 2017 22:24
@Morlinest
Copy link
Member Author

@ethantkoenig I wanted to completely remove Searcher from code in another PR.

@ethantkoenig
Copy link
Member

@Morlinest why?

@Morlinest
Copy link
Member Author

Was not point of this PR, but as this is last function that was using it and it's only few lines to remove I can do it here.

@Morlinest
Copy link
Member Author

@ethantkoenig Searcher removed from code completely

@Morlinest
Copy link
Member Author

@ethantkoenig Is it OK now? Can you aproove changes?

@Morlinest Morlinest force-pushed the fix/missing-collaborative-repositories branch from 38a6d76 to 46a5037 Compare October 16, 2017 17:55
@lafriks
Copy link
Member

lafriks commented Oct 16, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 16, 2017
@lafriks
Copy link
Member

lafriks commented Oct 16, 2017

@ethantkoenig your approval needed

@ethantkoenig
Copy link
Member

@Morlinest @lafriks I will take a look tonight

} else {
u, err := models.GetUserByID(opts.OwnerID)
var err error
repoOwner, err = models.GetUserByID(opts.OwnerID)
if err != nil {
ctx.JSON(500, api.SearchError{
Copy link
Member

Choose a reason for hiding this comment

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

Should it be 404 if user doesn't exist?

Copy link
Member

Choose a reason for hiding this comment

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

@ethantkoenig don't thinks so

Copy link
Member

Choose a reason for hiding this comment

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

@lafriks IMO, it doesn't make sense to return a 500 if the client provides a bad user ID

Copy link
Member

Choose a reason for hiding this comment

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

@ethantkoenig yes but not 404. It should be some other error or just empty repo list

Copy link
Member

Choose a reason for hiding this comment

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

@lafriks @ethantkoenig Sounds like a usual 400 Bad Request for me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't change it as it is current behaviour. I'll change it to "bad request".

Copy link
Member Author

Choose a reason for hiding this comment

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

@ethantkoenig @daviian I see problem, this response is defined in api (swagger):

	//     Responses:
	//       200: SearchResults
	//       500: SearchError

Copy link
Member Author

@Morlinest Morlinest Oct 17, 2017

Choose a reason for hiding this comment

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

I would keep it as it is now and make changes in v2 api. I can fix only leaking internal information from response. Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

@Morlinest @ethantkoenig as this is documented so let's not introduce breaking changes in API

Copy link
Member

Choose a reason for hiding this comment

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

IMO, calling this a breaking change seems like a stretch, but I don't want to block this PR so I'll accept

unit_types: '[1,2,3,4,5,6,7]'

Copy link
Member

Choose a reason for hiding this comment

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

nit: remove trailing space

@Morlinest Morlinest force-pushed the fix/missing-collaborative-repositories branch from 46a5037 to 7686465 Compare October 17, 2017 07:53
@ethantkoenig
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 17, 2017
@lunny lunny merged commit ccd3577 into go-gitea:master Oct 17, 2017
@Morlinest Morlinest deleted the fix/missing-collaborative-repositories branch October 17, 2017 16:04
@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. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dashboard shows all organization repositories, not respecting access rights
7 participants