mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
Calculate PublicOnly
for org membership only once (#32234)
Refactoring of #32211 this move the PublicOnly() filter calcuation next to the DB querys and let it be decided by the Doer --- *Sponsored by Kithara Software GmbH* (cherry picked from commit 43c252dfeaf9ab03c4db3e7ac5169bc0d69901ac) Conflicts: models/organization/org_test.go models/organization/org_user_test.go routers/web/org/home.go rather simple conflict resolution but not trivial tests/integration/user_count_test.go had to be adapted (simple) because it does not exist in Gitea and uses the modified model
This commit is contained in:
parent
45435a8789
commit
7751bb64cb
8 changed files with 76 additions and 56 deletions
|
@ -18,11 +18,12 @@ import (
|
|||
)
|
||||
|
||||
// listMembers list an organization's members
|
||||
func listMembers(ctx *context.APIContext, publicOnly bool) {
|
||||
func listMembers(ctx *context.APIContext, isMember bool) {
|
||||
opts := &organization.FindOrgMembersOpts{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
PublicOnly: publicOnly,
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
Doer: ctx.Doer,
|
||||
IsDoerMember: isMember,
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
}
|
||||
|
||||
count, err := organization.CountOrgMembers(ctx, opts)
|
||||
|
@ -73,16 +74,19 @@ func ListMembers(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
publicOnly := true
|
||||
var (
|
||||
isMember bool
|
||||
err error
|
||||
)
|
||||
|
||||
if ctx.Doer != nil {
|
||||
isMember, err := ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
isMember, err = ctx.Org.Organization.IsOrgMember(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "IsOrgMember", err)
|
||||
return
|
||||
}
|
||||
publicOnly = !isMember && !ctx.Doer.IsAdmin
|
||||
}
|
||||
listMembers(ctx, publicOnly)
|
||||
listMembers(ctx, isMember)
|
||||
}
|
||||
|
||||
// ListPublicMembers list an organization's public members
|
||||
|
@ -112,7 +116,7 @@ func ListPublicMembers(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
listMembers(ctx, true)
|
||||
listMembers(ctx, false)
|
||||
}
|
||||
|
||||
// IsMember check if a user is a member of an organization
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue