aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2024-11-11 01:38:30 +0100
committerGitHub <noreply@github.com>2024-11-11 01:38:30 +0100
commit43c252dfeaf9ab03c4db3e7ac5169bc0d69901ac (patch)
tree0fdac424af8a41ad804a2f6385666e48e7f12520 /routers/api/v1
parentb1f42a0cdddc8db9eef87041d6bcb328b2ef35fc (diff)
downloadgitea-43c252dfeaf9ab03c4db3e7ac5169bc0d69901ac.tar.gz
gitea-43c252dfeaf9ab03c4db3e7ac5169bc0d69901ac.zip
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*
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/org/member.go22
1 files changed, 13 insertions, 9 deletions
diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go
index 9db9ad964b..edcee1e207 100644
--- a/routers/api/v1/org/member.go
+++ b/routers/api/v1/org/member.go
@@ -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