diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-03-16 22:04:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-16 22:04:33 +0800 |
commit | 9e5d0a09eb7370daedb1cf572d25ffa150eacf17 (patch) | |
tree | f39cbf6a572bda0e82caec7ef1697ceb70e37f1e /models/repo_list.go | |
parent | 4163cdf3ea6d6ca43b694de0c15cc93659d6c2b3 (diff) | |
download | gitea-9e5d0a09eb7370daedb1cf572d25ffa150eacf17.tar.gz gitea-9e5d0a09eb7370daedb1cf572d25ffa150eacf17.zip |
Global code search support (#3664)
* add global code search on explore
* fix bug when no anyone public repos
* change the icon
* fix typo and add UnitTypeCode check for login non-admin user
* fix ui description when no match
Diffstat (limited to 'models/repo_list.go')
-rw-r--r-- | models/repo_list.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/models/repo_list.go b/models/repo_list.go index bc9b831d30..df6b81cb8d 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -249,3 +249,28 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err return repos, count, nil } + +// FindUserAccessibleRepoIDs find all accessible repositories' ID by user's id +func FindUserAccessibleRepoIDs(userID int64) ([]int64, error) { + var accessCond builder.Cond = builder.Eq{"is_private": false} + + if userID > 0 { + accessCond = accessCond.Or( + builder.Eq{"owner_id": userID}, + builder.And( + builder.Expr("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)", userID), + builder.Neq{"owner_id": userID}, + ), + ) + } + + repoIDs := make([]int64, 0, 10) + if err := x. + Table("repository"). + Cols("id"). + Where(accessCond). + Find(&repoIDs); err != nil { + return nil, fmt.Errorf("FindUserAccesibleRepoIDs: %v", err) + } + return repoIDs, nil +} |