Skip to content

Commit 8644dc5

Browse files
committed
fix: filter by unit type
1 parent 79c554d commit 8644dc5

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

models/repo/repo_list.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ type SearchRepoOptions struct {
130130
// True -> include just collaborative
131131
// False -> include just non-collaborative
132132
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
133137
// None -> include forks AND non-forks
134138
// True -> include just forks
135139
// False -> include just non-forks
@@ -382,19 +386,25 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
382386

383387
if opts.Collaborate != util.OptionalBoolFalse {
384388
// 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+
}
398408
if !opts.Private {
399409
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))
400410
}

routers/web/user/home.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,13 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
448448
// - Team org's owns the repository.
449449
// - Team has read permission to repository.
450450
repoOpts := &repo_model.SearchRepoOptions{
451-
Actor: ctx.Doer,
452-
OwnerID: ctx.Doer.ID,
453-
Private: true,
454-
AllPublic: false,
455-
AllLimited: false,
451+
Actor: ctx.Doer,
452+
OwnerID: ctx.Doer.ID,
453+
Private: true,
454+
AllPublic: false,
455+
AllLimited: false,
456+
Collaborate: util.OptionalBoolNone,
457+
UnitType: unitType,
456458
}
457459
if team != nil {
458460
repoOpts.TeamID = team.ID

0 commit comments

Comments
 (0)