Skip to content

Commit a6f1d33

Browse files
a1012112796zeripath
authored andcommitted
Allow access to the Public Organization Member lists with minimal permissions (go-gitea#20330)
Examining Organization membership should not necessarily require sign-in if the organization is public and the members are public. Therefore we should adjust `/org/{org}/members` to not require login. Fix go-gitea#7501 Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: zeripath <art27@cantab.net>
1 parent c759cb9 commit a6f1d33

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

modules/context/org.go

+15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models/perm"
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/modules/structs"
1516
)
1617

1718
// Organization contains organization context
@@ -69,6 +70,20 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
6970
return
7071
}
7172
org := ctx.Org.Organization
73+
74+
// Handle Visibility
75+
if org.Visibility != structs.VisibleTypePublic && !ctx.IsSigned {
76+
// We must be signed in to see limited or private organizations
77+
ctx.NotFound("OrgAssignment", err)
78+
return
79+
}
80+
81+
if org.Visibility == structs.VisibleTypePrivate {
82+
requireMember = true
83+
} else if ctx.IsSigned && ctx.Doer.IsRestricted {
84+
requireMember = true
85+
}
86+
7287
ctx.ContextUser = org.AsUser()
7388
ctx.Data["Org"] = org
7489

routers/web/org/home.go

-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ func Home(ctx *context.Context) {
3939

4040
org := ctx.Org.Organization
4141

42-
if !organization.HasOrgOrUserVisible(ctx, org.AsUser(), ctx.Doer) {
43-
ctx.NotFound("HasOrgOrUserVisible", nil)
44-
return
45-
}
46-
4742
ctx.Data["PageIsUserProfile"] = true
4843
ctx.Data["Title"] = org.DisplayName()
4944
if len(org.Description) != 0 {

routers/web/web.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,12 @@ func RegisterRoutes(m *web.Route) {
610610
}
611611

612612
// ***** START: Organization *****
613+
m.Group("/org", func() {
614+
m.Group("/{org}", func() {
615+
m.Get("/members", org.Members)
616+
}, context.OrgAssignment())
617+
}, ignSignIn)
618+
613619
m.Group("/org", func() {
614620
m.Group("", func() {
615621
m.Get("/create", org.Create)
@@ -625,7 +631,6 @@ func RegisterRoutes(m *web.Route) {
625631
m.Get("/pulls/{team}", user.Pulls)
626632
m.Get("/milestones", reqMilestonesDashboardPageEnabled, user.Milestones)
627633
m.Get("/milestones/{team}", reqMilestonesDashboardPageEnabled, user.Milestones)
628-
m.Get("/members", org.Members)
629634
m.Post("/members/action/{action}", org.MembersAction)
630635
m.Get("/teams", org.Teams)
631636
}, context.OrgAssignment(true, false, true))

templates/org/home.tmpl

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@
4141
{{end}}
4242
<h4 class="ui top attached header df">
4343
<strong class="f1">{{.locale.Tr "org.people"}}</strong>
44-
{{if .IsOrganizationMember}}
45-
<div class="ui">
46-
<a class="text grey dif ac" href="{{.OrgLink}}/members"><span>{{.Org.NumMembers}}</span> {{svg "octicon-chevron-right"}}</a>
47-
</div>
48-
{{end}}
44+
<div class="ui">
45+
<a class="text grey dif ac" href="{{.OrgLink}}/members"><span>{{.MembersTotal}}</span> {{svg "octicon-chevron-right"}}</a>
46+
</div>
4947
</h4>
5048
<div class="ui attached segment members">
5149
{{$isMember := .IsOrganizationMember}}

0 commit comments

Comments
 (0)