-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
fix: Admin can see all private repositories on Explore page. #1026
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1231,7 +1231,7 @@ func CountUserRepositories(userID int64, private bool) int64 { | |
} | ||
|
||
// Repositories returns all repositories | ||
func Repositories(opts *SearchRepoOptions) (_ RepositoryList, err error) { | ||
func Repositories(opts *SearchRepoOptions) (_ RepositoryList, count int64, err error) { | ||
if len(opts.OrderBy) == 0 { | ||
opts.OrderBy = "id ASC" | ||
} | ||
|
@@ -1242,14 +1242,16 @@ func Repositories(opts *SearchRepoOptions) (_ RepositoryList, err error) { | |
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). | ||
OrderBy(opts.OrderBy). | ||
Find(&repos); err != nil { | ||
return nil, fmt.Errorf("Repo: %v", err) | ||
return nil, 0, fmt.Errorf("Repo: %v", err) | ||
} | ||
|
||
if err = repos.loadAttributes(x); err != nil { | ||
return nil, fmt.Errorf("LoadAttributes: %v", err) | ||
return nil, 0, fmt.Errorf("LoadAttributes: %v", err) | ||
} | ||
|
||
return repos, nil | ||
count = countRepositories(-1, opts.Private) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, we check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can create another PR to refactor the codes according to your suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I suppose I could do it too. Either way, it's outside the scope of this PR. |
||
|
||
return repos, count, nil | ||
} | ||
|
||
// RepoPath returns repository path by given user and repository name. | ||
|
@@ -1757,40 +1759,54 @@ func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { | |
} | ||
|
||
// GetRecentUpdatedRepositories returns the list of repositories that are recently updated. | ||
func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList, err error) { | ||
func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList, _ int64, _ error) { | ||
var cond = builder.NewCond() | ||
|
||
if len(opts.OrderBy) == 0 { | ||
opts.OrderBy = "updated_unix DESC" | ||
} | ||
|
||
sess := x.Where("is_private=?", false). | ||
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). | ||
Limit(opts.PageSize) | ||
if !opts.Private { | ||
cond = builder.Eq{ | ||
"is_private": false, | ||
} | ||
} | ||
|
||
if opts.Searcher != nil { | ||
sess.Or("owner_id = ?", opts.Searcher.ID) | ||
if opts.Searcher != nil && !opts.Searcher.IsAdmin { | ||
var ownerIds []int64 | ||
|
||
ownerIds = append(ownerIds, opts.Searcher.ID) | ||
err := opts.Searcher.GetOrganizations(true) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Organization: %v", err) | ||
return nil, 0, fmt.Errorf("Organization: %v", err) | ||
} | ||
|
||
for _, org := range opts.Searcher.Orgs { | ||
sess.Or("owner_id = ?", org.ID) | ||
ownerIds = append(ownerIds, org.ID) | ||
} | ||
|
||
cond = cond.Or(builder.In("owner_id", ownerIds)) | ||
} | ||
|
||
if err = sess. | ||
count, err := x.Where(cond).Count(new(Repository)) | ||
if err != nil { | ||
return nil, 0, fmt.Errorf("Count: %v", err) | ||
} | ||
|
||
if err = x.Where(cond). | ||
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). | ||
Limit(opts.PageSize). | ||
OrderBy(opts.OrderBy). | ||
Find(&repos); err != nil { | ||
return nil, fmt.Errorf("Repo: %v", err) | ||
return nil, 0, fmt.Errorf("Repo: %v", err) | ||
} | ||
|
||
if err = repos.loadAttributes(x); err != nil { | ||
return nil, fmt.Errorf("LoadAttributes: %v", err) | ||
return nil, 0, fmt.Errorf("LoadAttributes: %v", err) | ||
} | ||
|
||
return repos, nil | ||
return repos, count, nil | ||
} | ||
|
||
func getRepositoryCount(e Engine, u *User) (int64, error) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
EDITED: Why does this function not examine the contents of
opts.Searcher
, and exclude repos accordingly (likeGetRecentUpdateRepositories(..)~
)?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.
Why need to examine the contents of
opts.Searcher
?https://github.com/go-gitea/gitea/blob/master/models/issue_indexer.go#L119
https://github.com/go-gitea/gitea/blob/master/routers/admin/repos.go#L28
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 meant like
GetRecentUpdateRepsitories(..)
; sorry if that caused any confusion.Even if every codepath that calls
Repositories(..)
hasopts.Searcher
set tonil
, someone might in the future add a changes that callsRepositories(..)
, haveopts.Searcher
not benil
, and expectRepositories
to filter accordingly.Uh oh!
There was an error while loading. Please reload this page.
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.
Since
Repositories(..)
only looks atopts.PageSize
,opts.Page
, andopts.OrderBy
, would it be better to have it take those 3 values as separate arguments?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.
NO. I think using
SearchRepoOptions
would be better than take 3 arguments if we want to extend the function.