From 4529d343e31084cdf8a0e770c024e5e5da46bc7e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 7 Aug 2023 06:41:30 +0000 Subject: [PATCH 1/5] fix --- modules/context/org.go | 15 +++++++++++++++ routers/web/org/home.go | 16 +++------------- templates/org/home.tmpl | 29 ++++++++++++++++------------- templates/org/menu.tmpl | 8 ++++---- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/modules/context/org.go b/modules/context/org.go index 835c761372fa9..2415567f0c48a 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -172,6 +172,20 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { ctx.Org.OrgLink = org.AsUser().OrganisationLink() ctx.Data["OrgLink"] = ctx.Org.OrgLink + // Member + opts := &organization.FindOrgMembersOpts{ + OrgID: org.ID, + PublicOnly: true, + } + if ctx.Doer != nil { + opts.PublicOnly = !ctx.Org.IsMember && !ctx.Doer.IsAdmin + } + ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts) + if err != nil { + ctx.ServerError("CountOrgMembers", err) + return + } + // Team. if ctx.Org.IsMember { shouldSeeAllTeams := false @@ -203,6 +217,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 7f38ec51ba6e2..ca86317c04b67 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -124,12 +124,7 @@ func Home(ctx *context.Context) { } 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 + opts.PublicOnly = !ctx.Org.IsMember && !ctx.Doer.IsAdmin } members, _, err := organization.FindOrgMembers(opts) @@ -138,12 +133,6 @@ func Home(ctx *context.Context) { 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) @@ -151,7 +140,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 @@ -164,5 +152,7 @@ func Home(ctx *context.Context) { ctx.Data["Page"] = pager ctx.Data["ContextUser"] = ctx.ContextUser + ctx.Data["ShowMemberTeamBoard"] = ctx.Org.IsMember || len(members) > 0 + ctx.HTML(http.StatusOK, tplOrgHome) } diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 445df520a9f32..af1627b743316 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 .ShowMemberTeamBoard}}
{{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)}} - {{avatar $.Context . 48}} + {{if gt .NumMembers 0}} +

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

+
+ {{$isMember := .IsOrganizationMember}} + {{range .Members}} + {{if or $isMember (call $.IsPublicMember .ID)}} + {{avatar $.Context . 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 6492e5e668eb1..8eaa381fa2b6c 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}} From dce94dd62b2e5c43f86fd348a435361e503e8651 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 8 Aug 2023 09:06:49 +0900 Subject: [PATCH 2/5] Update modules/context/org.go Co-authored-by: delvh --- modules/context/org.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/context/org.go b/modules/context/org.go index 2415567f0c48a..53c46d6b9eb5c 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -177,9 +177,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { OrgID: org.ID, PublicOnly: true, } - if ctx.Doer != nil { - opts.PublicOnly = !ctx.Org.IsMember && !ctx.Doer.IsAdmin - } + opts.PublicOnly = ctx.Doer == nil || !ctx.Org.IsMember && !ctx.Doer.IsAdmin ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts) if err != nil { ctx.ServerError("CountOrgMembers", err) From 5effed4f021a7567220693bf1fafc743eefd76bf Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 8 Aug 2023 09:09:26 +0900 Subject: [PATCH 3/5] Update templates/org/home.tmpl Co-authored-by: delvh --- templates/org/home.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index af1627b743316..3108432d095e5 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -54,7 +54,7 @@
{{end}} - {{if gt .NumMembers 0}} + {{if .NumMembers}}

{{.locale.Tr "org.members"}} {{.NumMembers}} {{svg "octicon-chevron-right"}} From 3ade54150a18ed88465a910a2b3f8b98e9e798b7 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 8 Aug 2023 00:15:22 +0000 Subject: [PATCH 4/5] improve --- modules/context/org.go | 5 +++-- routers/web/org/home.go | 7 +------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/context/org.go b/modules/context/org.go index 53c46d6b9eb5c..2d7cf5185c506 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 @@ -173,11 +174,11 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { 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: true, + PublicOnly: ctx.Org.PublicMemberOnly, } - opts.PublicOnly = ctx.Doer == nil || !ctx.Org.IsMember && !ctx.Doer.IsAdmin ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts) if err != nil { ctx.ServerError("CountOrgMembers", err) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index ca86317c04b67..1261922ba6f1d 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -119,14 +119,9 @@ 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 { - opts.PublicOnly = !ctx.Org.IsMember && !ctx.Doer.IsAdmin - } - members, _, err := organization.FindOrgMembers(opts) if err != nil { ctx.ServerError("FindOrgMembers", err) From 553472bcfc1dff883eb6bf433ffde44eabe2a9a7 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 8 Aug 2023 00:21:20 +0000 Subject: [PATCH 5/5] rename to ShowMemberAndTeamTab --- routers/web/org/home.go | 2 +- templates/org/home.tmpl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 1261922ba6f1d..3334043e0cf0a 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -147,7 +147,7 @@ func Home(ctx *context.Context) { ctx.Data["Page"] = pager ctx.Data["ContextUser"] = ctx.ContextUser - ctx.Data["ShowMemberTeamBoard"] = ctx.Org.IsMember || len(members) > 0 + 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 3108432d095e5..249a5a0842dd1 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -37,13 +37,13 @@
-
+
{{template "explore/repo_search" .}} {{template "explore/repo_list" .}} {{template "base/paginate" .}}
- {{if .ShowMemberTeamBoard}} + {{if .ShowMemberAndTeamTab}}
{{if .CanCreateOrgRepo}}