mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
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
This commit is contained in:
parent
4163cdf3ea
commit
9e5d0a09eb
10 changed files with 238 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue