From 7f8028e5a1ee5e99ef491bf037a7171998322bd2 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 15 Aug 2023 23:00:35 +0900 Subject: [PATCH] Fix display problems of members and teams unit (#26363) Fix: - display member count and team count in the menu bar ![image](https://github.com/go-gitea/gitea/assets/18380374/7f03ced4-67e2-41ce-b19f-a992823726bb) - Also display member unit in the menu bar if there are no hidden members in public org ![image](https://github.com/go-gitea/gitea/assets/18380374/31422ad6-7190-438d-8e99-8a4af9cce908) - hidden member board when there's no seeable members. In this org, we only have hidden members: ![image](https://github.com/go-gitea/gitea/assets/18380374/d749420b-554a-4483-8cd2-221df61b5ca7) We will hidden the member board when doer is not the member of this org ![image](https://github.com/go-gitea/gitea/assets/18380374/93bb782e-7d4d-4ad3-a096-133afbc51f8a) Before: ![image](https://github.com/go-gitea/gitea/assets/18380374/eafc0b3e-6218-42ab-a892-39645d08a5eb) If you click the number in the members board, you will access the members page, which is not expected. ![image](https://github.com/go-gitea/gitea/assets/18380374/73d6dadc-0ef2-4ca9-8485-c5f4211bffb2) --------- Co-authored-by: delvh Co-authored-by: Giteabot --- modules/context/org.go | 14 ++++++++++++++ routers/web/org/home.go | 21 +++------------------ templates/org/home.tmpl | 29 ++++++++++++++++------------- templates/org/menu.tmpl | 8 ++++---- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/modules/context/org.go b/modules/context/org.go index 835c76137..2d7cf5185 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -24,6 +24,7 @@ type Organization struct { Organization *organization.Organization OrgLink string CanCreateOrgRepo bool + PublicMemberOnly bool // Only display public members Team *organization.Team Teams []*organization.Team @@ -172,6 +173,18 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { ctx.Org.OrgLink = org.AsUser().OrganisationLink() ctx.Data["OrgLink"] = ctx.Org.OrgLink + // Member + ctx.Org.PublicMemberOnly = ctx.Doer == nil || !ctx.Org.IsMember && !ctx.Doer.IsAdmin + opts := &organization.FindOrgMembersOpts{ + OrgID: org.ID, + PublicOnly: ctx.Org.PublicMemberOnly, + } + ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts) + if err != nil { + ctx.ServerError("CountOrgMembers", err) + return + } + // Team. if ctx.Org.IsMember { shouldSeeAllTeams := false @@ -203,6 +216,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { return } } + ctx.Data["NumTeams"] = len(ctx.Org.Teams) } teamName := ctx.Params(":team") diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 9104c15f9..613dff218 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -120,31 +120,15 @@ func Home(ctx *context.Context) { opts := &organization.FindOrgMembersOpts{ OrgID: org.ID, - PublicOnly: true, + PublicOnly: ctx.Org.PublicMemberOnly, ListOptions: db.ListOptions{Page: 1, PageSize: 25}, } - - if ctx.Doer != nil { - isMember, err := org.IsOrgMember(ctx.Doer.ID) - if err != nil { - ctx.Error(http.StatusInternalServerError, "IsOrgMember") - return - } - opts.PublicOnly = !isMember && !ctx.Doer.IsAdmin - } - members, _, err := organization.FindOrgMembers(opts) if err != nil { ctx.ServerError("FindOrgMembers", err) return } - membersCount, err := organization.CountOrgMembers(opts) - if err != nil { - ctx.ServerError("CountOrgMembers", err) - return - } - var isFollowing bool if ctx.Doer != nil { isFollowing = user_model.IsFollowing(ctx.Doer.ID, ctx.ContextUser.ID) @@ -152,7 +136,6 @@ func Home(ctx *context.Context) { ctx.Data["Repos"] = repos ctx.Data["Total"] = count - ctx.Data["MembersTotal"] = membersCount ctx.Data["Members"] = members ctx.Data["Teams"] = ctx.Org.Teams ctx.Data["DisableNewPullMirrors"] = setting.Mirror.DisableNewPull @@ -171,5 +154,7 @@ func Home(ctx *context.Context) { ctx.Data["Page"] = pager ctx.Data["ContextUser"] = ctx.ContextUser + ctx.Data["ShowMemberAndTeamTab"] = ctx.Org.IsMember || len(members) > 0 + ctx.HTML(http.StatusOK, tplOrgHome) } diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 766dd5b7a..0bd744d2b 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -37,12 +37,13 @@
-
+
{{template "explore/repo_search" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}
+ {{if .ShowMemberAndTeamTab}}
{{if .CanCreateOrgRepo}}
@@ -53,19 +54,20 @@
{{end}} -

- {{.locale.Tr "org.members"}} - {{.MembersTotal}} {{svg "octicon-chevron-right"}} -

-
- {{$isMember := .IsOrganizationMember}} - {{range .Members}} - {{if or $isMember (call $.IsPublicMember .ID)}} - {{ctx.AvatarUtils.Avatar . 48}} + {{if .NumMembers}} +

+ {{.locale.Tr "org.members"}} + {{.NumMembers}} {{svg "octicon-chevron-right"}} +

+
+ {{$isMember := .IsOrganizationMember}} + {{range .Members}} + {{if or $isMember (call $.IsPublicMember .ID)}} + {{ctx.AvatarUtils.Avatar . 48}} + {{end}} {{end}} - {{end}} -
- +
+ {{end}} {{if .IsOrganizationMember}}
{{.locale.Tr "org.teams"}} @@ -89,6 +91,7 @@ {{end}} {{end}}
+ {{end}}
diff --git a/templates/org/menu.tmpl b/templates/org/menu.tmpl index a4f602730..26c9f980a 100644 --- a/templates/org/menu.tmpl +++ b/templates/org/menu.tmpl @@ -21,13 +21,13 @@ {{svg "octicon-code"}} {{$.locale.Tr "org.code"}} {{end}} - {{if .IsOrganizationMember}} + {{if .NumMembers}} {{svg "octicon-person"}} {{$.locale.Tr "org.members"}} - {{if .NumMembers}} -
{{.NumMembers}}
- {{end}} +
{{.NumMembers}}
+ {{end}} + {{if .IsOrganizationMember}} {{svg "octicon-people"}} {{$.locale.Tr "org.teams"}} {{if .NumTeams}}