@@ -155,26 +155,44 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun
155
155
// Append conditions
156
156
if ! opts .Starred && opts .OwnerID > 0 {
157
157
var searcherReposCond builder.Cond = builder.Eq {"owner_id" : opts .OwnerID }
158
+ var ownerIds []int64
159
+ // Searcher == Owner
158
160
if opts .Searcher != nil {
159
- var ownerIds []int64
160
-
161
161
ownerIds = append (ownerIds , opts .Searcher .ID )
162
- err = opts .Searcher .GetOrganizations (true )
162
+ err = opts .Searcher .GetOwnedOrganizations (true )
163
163
164
164
if err != nil {
165
165
return nil , 0 , fmt .Errorf ("Organization: %v" , err )
166
166
}
167
167
168
- for _ , org := range opts .Searcher .Orgs {
168
+ for _ , org := range opts .Searcher .OwnedOrgs {
169
169
ownerIds = append (ownerIds , org .ID )
170
170
}
171
171
172
- searcherReposCond = searcherReposCond .Or (builder .In ("owner_id" , ownerIds ))
173
172
if opts .Collaborate {
174
- searcherReposCond = searcherReposCond .Or (builder .Expr ("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ? AND owner_id != ?) " ,
173
+ searcherReposCond = searcherReposCond .Or (builder .Expr ("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?) AND owner_id != ?" ,
175
174
opts .Searcher .ID , opts .Searcher .ID ))
176
175
}
176
+ } else if opts .OwnerID > 0 {
177
+ ownerIds = append (ownerIds , opts .OwnerID )
178
+
179
+ owner , err := GetUserByID (opts .OwnerID )
180
+ if err != nil {
181
+ return nil , 0 , fmt .Errorf ("User: %v" , err )
182
+ }
183
+
184
+ err = owner .GetOwnedOrganizations (false )
185
+
186
+ for _ , org := range owner .OwnedOrgs {
187
+ ownerIds = append (ownerIds , org .ID )
188
+ }
189
+
190
+ if err != nil {
191
+ return nil , 0 , fmt .Errorf ("Organization: %v" , err )
192
+ }
193
+
177
194
}
195
+ searcherReposCond = searcherReposCond .Or (builder .In ("owner_id" , ownerIds ))
178
196
cond = cond .And (searcherReposCond )
179
197
}
180
198
@@ -268,17 +286,21 @@ func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList
268
286
var ownerIds []int64
269
287
270
288
ownerIds = append (ownerIds , opts .Searcher .ID )
271
- err := opts .Searcher .GetOrganizations (true )
289
+ err := opts .Searcher .GetOwnedOrganizations (true )
272
290
273
291
if err != nil {
274
292
return nil , 0 , fmt .Errorf ("Organization: %v" , err )
275
293
}
276
294
277
- for _ , org := range opts .Searcher .Orgs {
295
+ for _ , org := range opts .Searcher .OwnedOrgs {
278
296
ownerIds = append (ownerIds , org .ID )
279
297
}
280
298
281
299
cond = cond .Or (builder .In ("owner_id" , ownerIds ))
300
+ if opts .Collaborate {
301
+ cond = cond .Or (builder .Expr ("id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?) AND owner_id != ?" ,
302
+ opts .Searcher .ID , opts .Searcher .ID ))
303
+ }
282
304
}
283
305
284
306
count , err := x .Where (cond ).Count (new (Repository ))
0 commit comments