diff --git a/modules/context/org.go b/modules/context/org.go index 835c761372..2d7cf5185c 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 9104c15f94..613dff2182 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 766dd5b7a6..0bd744d2b8 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -37,12 +37,13 @@