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