From bfe5233aefa0eaef23e99bcb346bfbba5c107422 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 26 Feb 2022 14:09:08 +0100 Subject: [PATCH 1/3] Allow adminstrator teams to see other teams - Allow team members with adminstrator access, to view other teams. - Resolves #18885 --- modules/context/org.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/context/org.go b/modules/context/org.go index 585a5fd762c6d..6678558a6c921 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -129,7 +129,11 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { // Team. if ctx.Org.IsMember { - if ctx.Org.IsOwner { + maxPerm, err := org.GetOrgUserMaxAuthorizeLevel(ctx.User.ID) + if err != nil { + ctx.ServerError("GetOrgUserMaxAuthorizeLevel", err) + } + if ctx.Org.IsOwner || maxPerm >= perm.AccessModeAdmin { ctx.Org.Teams, err = org.LoadTeams() if err != nil { ctx.ServerError("LoadTeams", err) From 97628bed4402c23b160e27e89bac8d15b836fd2e Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 26 Feb 2022 19:23:49 +0100 Subject: [PATCH 2/3] Make condition more robust --- modules/context/org.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/context/org.go b/modules/context/org.go index 6678558a6c921..4002d28c5e5c3 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -129,11 +129,23 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { // Team. if ctx.Org.IsMember { - maxPerm, err := org.GetOrgUserMaxAuthorizeLevel(ctx.User.ID) - if err != nil { - ctx.ServerError("GetOrgUserMaxAuthorizeLevel", err) + shouldSeeAllTeams := false + if ctx.Org.IsOwner { + shouldSeeAllTeams = true + } else { + teams, err := org.GetUserTeams(ctx.User.ID) + if err != nil { + ctx.ServerError("GetOrgUserMaxAuthorizeLevel", err) + return + } + for _, team := range teams { + if team.IncludesAllRepositories && team.AccessMode >= perm.AccessModeAdmin { + shouldSeeAllTeams = true + break + } + } } - if ctx.Org.IsOwner || maxPerm >= perm.AccessModeAdmin { + if shouldSeeAllTeams { ctx.Org.Teams, err = org.LoadTeams() if err != nil { ctx.ServerError("LoadTeams", err) From 0d27db904d91c0a2162f0691c35cdfb004e65567 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 26 Feb 2022 18:36:01 +0000 Subject: [PATCH 3/3] Update modules/context/org.go Co-authored-by: wxiaoguang --- modules/context/org.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/context/org.go b/modules/context/org.go index 4002d28c5e5c3..824f22b2f3305 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -135,7 +135,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { } else { teams, err := org.GetUserTeams(ctx.User.ID) if err != nil { - ctx.ServerError("GetOrgUserMaxAuthorizeLevel", err) + ctx.ServerError("GetUserTeams", err) return } for _, team := range teams {