@@ -130,6 +130,10 @@ type SearchRepoOptions struct {
130
130
// True -> include just collaborative
131
131
// False -> include just non-collaborative
132
132
Collaborate util.OptionalBool
133
+ // What type of unit the user can be collaborative in,
134
+ // it is ignored if Collaborate is False.
135
+ // TypeInvalid means any unit type.
136
+ UnitType unit.Type
133
137
// None -> include forks AND non-forks
134
138
// True -> include just forks
135
139
// False -> include just non-forks
@@ -382,19 +386,25 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
382
386
383
387
if opts .Collaborate != util .OptionalBoolFalse {
384
388
// A Collaboration is:
385
- collaborateCond := builder .And (
386
- // 1. Repository we don't own
387
- builder.Neq {"owner_id" : opts .OwnerID },
388
- // 2. But we can see because of:
389
- builder .Or (
390
- // A. We have unit independent access
391
- UserAccessRepoCond ("`repository`.id" , opts .OwnerID ),
392
- // B. We are in a team for
393
- UserOrgTeamRepoCond ("`repository`.id" , opts .OwnerID ),
394
- // C. Public repositories in organizations that we are member of
395
- userOrgPublicRepoCondPrivate (opts .OwnerID ),
396
- ),
397
- )
389
+
390
+ collaborateCond := builder .NewCond ()
391
+ // 1. Repository we don't own
392
+ collaborateCond = collaborateCond .And (builder.Neq {"owner_id" : opts .OwnerID })
393
+ // 2. But we can see because of:
394
+ {
395
+ userAccessCond := builder .NewCond ()
396
+ // A. We have unit independent access
397
+ userAccessCond = userAccessCond .Or (UserAccessRepoCond ("`repository`.id" , opts .OwnerID ))
398
+ // B. We are in a team for
399
+ if opts .UnitType == unit .TypeInvalid {
400
+ userAccessCond = userAccessCond .Or (UserOrgTeamRepoCond ("`repository`.id" , opts .OwnerID ))
401
+ } else {
402
+ userAccessCond = userAccessCond .Or (userOrgTeamUnitRepoCond ("`repository`.id" , opts .OwnerID , opts .UnitType ))
403
+ }
404
+ // C. Public repositories in organizations that we are member of
405
+ userAccessCond = userAccessCond .Or (userOrgPublicRepoCondPrivate (opts .OwnerID ))
406
+ collaborateCond = collaborateCond .And (userAccessCond )
407
+ }
398
408
if ! opts .Private {
399
409
collaborateCond = collaborateCond .And (builder .Expr ("owner_id NOT IN (SELECT org_id FROM org_user WHERE org_user.uid = ? AND org_user.is_public = ?)" , opts .OwnerID , false ))
400
410
}
0 commit comments