aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2022-10-11 02:12:03 +0300
committerGitHub <noreply@github.com>2022-10-11 00:12:03 +0100
commitb59b0cad0a550223f74add109ff13c0d2f4309f3 (patch)
tree4c4d0482ca8740390b5939c3979d1fef35cb9047 /models
parent3ccebf7f4044b85eef975e4544785893da763bd2 (diff)
downloadgitea-b59b0cad0a550223f74add109ff13c0d2f4309f3.tar.gz
gitea-b59b0cad0a550223f74add109ff13c0d2f4309f3.zip
Add user/organization code search (#19977)
Fixes #19925 Screenshots: ![attels](https://user-images.githubusercontent.com/165205/173864718-fe789429-55bc-4cad-808c-9f02f335cddf.png)
Diffstat (limited to 'models')
-rw-r--r--models/repo/repo_list.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go
index ee72dc6ee7..cc524a417e 100644
--- a/models/repo/repo_list.go
+++ b/models/repo/repo_list.go
@@ -593,6 +593,16 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
return sess, count, nil
}
+// SearchRepositoryIDsByCondition search repository IDs by given condition.
+func SearchRepositoryIDsByCondition(ctx context.Context, cond builder.Cond) ([]int64, error) {
+ repoIDs := make([]int64, 0, 10)
+ return repoIDs, db.GetEngine(ctx).
+ Table("repository").
+ Cols("id").
+ Where(cond).
+ Find(&repoIDs)
+}
+
// AccessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
func AccessibleRepositoryCondition(user *user_model.User, unitType unit.Type) builder.Cond {
cond := builder.NewCond()
@@ -680,16 +690,16 @@ func AccessibleRepoIDsQuery(user *user_model.User) *builder.Builder {
}
// FindUserCodeAccessibleRepoIDs finds all at Code level accessible repositories' ID by the user's id
-func FindUserCodeAccessibleRepoIDs(user *user_model.User) ([]int64, error) {
- repoIDs := make([]int64, 0, 10)
- if err := db.GetEngine(db.DefaultContext).
- Table("repository").
- Cols("id").
- Where(AccessibleRepositoryCondition(user, unit.TypeCode)).
- Find(&repoIDs); err != nil {
- return nil, fmt.Errorf("FindUserCodeAccesibleRepoIDs: %v", err)
- }
- return repoIDs, nil
+func FindUserCodeAccessibleRepoIDs(ctx context.Context, user *user_model.User) ([]int64, error) {
+ return SearchRepositoryIDsByCondition(ctx, AccessibleRepositoryCondition(user, unit.TypeCode))
+}
+
+// FindUserCodeAccessibleOwnerRepoIDs finds all repository IDs for the given owner whose code the user can see.
+func FindUserCodeAccessibleOwnerRepoIDs(ctx context.Context, ownerID int64, user *user_model.User) ([]int64, error) {
+ return SearchRepositoryIDsByCondition(ctx, builder.NewCond().And(
+ builder.Eq{"owner_id": ownerID},
+ AccessibleRepositoryCondition(user, unit.TypeCode),
+ ))
}
// GetUserRepositories returns a list of repositories of given user.