From f5773c16e8ddf27220cc0673ac1f38f900bc09e0 Mon Sep 17 00:00:00 2001 From: Animesh Kumar <83393501+kmranimesh@users.noreply.github.com> Date: Fri, 13 Feb 2026 22:49:59 +0530 Subject: [PATCH] Fix CanUserSeeAllTeams to handle Site Admins correctly --- models/organization/org.go | 9 ++++++--- routers/web/org/teams.go | 2 +- services/context/org.go | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/models/organization/org.go b/models/organization/org.go index e60de91691..9f174372a7 100644 --- a/models/organization/org.go +++ b/models/organization/org.go @@ -598,8 +598,11 @@ func getUserTeamIDsQueryBuilder(orgID, userID int64) *builder.Builder { } // CanUserSeeAllTeams returns true if user can see all teams in organization -func (org *Organization) CanUserSeeAllTeams(ctx context.Context, userID int64) (bool, error) { - isOwner, err := org.IsOwnedBy(ctx, userID) +func (org *Organization) CanUserSeeAllTeams(ctx context.Context, user *user_model.User) (bool, error) { + if user.IsAdmin { + return true, nil + } + isOwner, err := org.IsOwnedBy(ctx, user.ID) if err != nil { return false, err } @@ -607,7 +610,7 @@ func (org *Organization) CanUserSeeAllTeams(ctx context.Context, userID int64) ( return true, nil } - teams, err := org.GetUserTeams(ctx, userID) + teams, err := org.GetUserTeams(ctx, user.ID) if err != nil { return false, err } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 1446b848e2..6ec20a79ed 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -67,7 +67,7 @@ func Teams(ctx *context.Context) { }, } - canSeeAllTeams, err := ctx.Org.Organization.CanUserSeeAllTeams(ctx, ctx.Doer.ID) + canSeeAllTeams, err := ctx.Org.Organization.CanUserSeeAllTeams(ctx, ctx.Doer) if err != nil { ctx.ServerError("CanUserSeeAllTeams", err) return diff --git a/services/context/org.go b/services/context/org.go index 69c327ad7c..70df8533c9 100644 --- a/services/context/org.go +++ b/services/context/org.go @@ -173,7 +173,7 @@ func OrgAssignment(orgAssignmentOpts OrgAssignmentOptions) func(ctx *Context) { // Team. if ctx.Org.IsMember { - shouldSeeAllTeams, err := org.CanUserSeeAllTeams(ctx, ctx.Doer.ID) + shouldSeeAllTeams, err := org.CanUserSeeAllTeams(ctx, ctx.Doer) if err != nil { ctx.ServerError("CanUserSeeAllTeams", err) return