Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display problems of members and teams unit #26363

Merged
15 changes: 15 additions & 0 deletions modules/context/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
yp05327 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["NumMembers"], err = organization.CountOrgMembers(opts)
if err != nil {
ctx.ServerError("CountOrgMembers", err)
return
}

// Team.
if ctx.Org.IsMember {
shouldSeeAllTeams := false
Expand Down Expand Up @@ -203,6 +217,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
return
}
}
ctx.Data["NumTeams"] = len(ctx.Org.Teams)
}

teamName := ctx.Params(":team")
Expand Down
16 changes: 3 additions & 13 deletions routers/web/org/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this code block again, if we already checked it in HandleOrgAssignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3ade541


members, _, err := organization.FindOrgMembers(opts)
Expand All @@ -138,20 +133,13 @@ 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)
}

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
Expand All @@ -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
yp05327 marked this conversation as resolved.
Show resolved Hide resolved

ctx.HTML(http.StatusOK, tplOrgHome)
}
29 changes: 16 additions & 13 deletions templates/org/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@

<div class="ui container">
<div class="ui mobile reversed stackable grid">
<div class="ui eleven wide column">
<div class="ui {{if .ShowMemberTeamBoard}}eleven wide{{end}} column">
{{template "explore/repo_search" .}}
{{template "explore/repo_list" .}}
{{template "base/paginate" .}}
</div>

{{if .ShowMemberTeamBoard}}
<div class="ui five wide column">
{{if .CanCreateOrgRepo}}
<div class="center aligned">
Expand All @@ -53,19 +54,20 @@
</div>
<div class="divider"></div>
{{end}}
<h4 class="ui top attached header gt-df">
<strong class="gt-f1">{{.locale.Tr "org.members"}}</strong>
<a class="text grey gt-dif gt-ac" href="{{.OrgLink}}/members"><span>{{.MembersTotal}}</span> {{svg "octicon-chevron-right"}}</a>
</h4>
<div class="ui attached segment members">
{{$isMember := .IsOrganizationMember}}
{{range .Members}}
{{if or $isMember (call $.IsPublicMember .ID)}}
<a href="{{.HomeLink}}" title="{{.Name}}{{if .FullName}} ({{.FullName}}){{end}}">{{avatar $.Context . 48}}</a>
{{if gt .NumMembers 0}}
yp05327 marked this conversation as resolved.
Show resolved Hide resolved
<h4 class="ui top attached header gt-df">
<strong class="gt-f1">{{.locale.Tr "org.members"}}</strong>
<a class="text grey gt-dif gt-ac" href="{{.OrgLink}}/members"><span>{{.NumMembers}}</span> {{svg "octicon-chevron-right"}}</a>
</h4>
<div class="ui attached segment members">
{{$isMember := .IsOrganizationMember}}
{{range .Members}}
{{if or $isMember (call $.IsPublicMember .ID)}}
<a href="{{.HomeLink}}" title="{{.Name}}{{if .FullName}} ({{.FullName}}){{end}}">{{avatar $.Context . 48}}</a>
{{end}}
{{end}}
{{end}}
</div>

</div>
{{end}}
{{if .IsOrganizationMember}}
<div class="ui top attached header gt-df">
<strong class="gt-f1">{{.locale.Tr "org.teams"}}</strong>
Expand All @@ -89,6 +91,7 @@
{{end}}
{{end}}
</div>
{{end}}
</div>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions templates/org/menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
{{svg "octicon-code"}}&nbsp;{{$.locale.Tr "org.code"}}
</a>
{{end}}
{{if .IsOrganizationMember}}
{{if .NumMembers}}
<a class="{{if $.PageIsOrgMembers}}active {{end}}item" href="{{$.OrgLink}}/members">
{{svg "octicon-person"}}&nbsp;{{$.locale.Tr "org.members"}}
{{if .NumMembers}}
<div class="ui small label">{{.NumMembers}}</div>
{{end}}
<div class="ui small label">{{.NumMembers}}</div>
</a>
{{end}}
{{if .IsOrganizationMember}}
<a class="{{if $.PageIsOrgTeams}}active {{end}}item" href="{{$.OrgLink}}/teams">
{{svg "octicon-people"}}&nbsp;{{$.locale.Tr "org.teams"}}
{{if .NumTeams}}
Expand Down