0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-10 09:41:52 +02:00

refactor: update groupAssignment func

ensure that groups that have private parents remain inaccessible
This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2026-05-08 18:32:48 -04:00
parent d9c8a28a5f
commit 496140d537
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C

View File

@ -120,6 +120,11 @@ func groupAssignment(ctx commonCtx, doer *user_model.User, isSigned bool, handle
handleOtherError("error checking group access", err)
return
}
privateBecauseOfParent, err := group.IsPrivateBecauseOfParentPermissions(ctx, doer)
if err != nil {
handleOtherError("error checking group access", err)
return
}
if group.Owner == nil {
err = group.LoadOwner(ctx)
if err != nil {
@ -255,6 +260,9 @@ func groupAssignment(ctx commonCtx, doer *user_model.User, isSigned bool, handle
}
repoGroup.IsGroupAdmin = repoGroup.IsGroupAdmin || isAdmin
}
if !repoGroup.IsOwner && !repoGroup.IsGroupAdmin {
canAccess = canAccess && !privateBecauseOfParent
}
assign(repoGroup, canAccess)
}
@ -296,7 +304,7 @@ func GroupAssignmentWeb(args GroupAssignmentOptions) func(ctx *Context) {
is, _ := organization.IsPublicMembership(ctx, ctx.Org.Organization.ID, uid)
return is
}
ctx.Data["CanReadProjects"] = repoGroup.CanReadUnit(ctx, unit.TypeProjects)
ctx.Data["CanReadProjects"] = repoGroup.CanReadUnit(ctx, ctx.Doer, unit.TypeProjects)
ctx.Data["CanCreateOrgRepo"] = repoGroup.CanCreateRepoOrGroup
ctx.Data["IsGroupAdmin"] = repoGroup.IsGroupAdmin
@ -356,10 +364,14 @@ func GroupAssignmentAPI() func(ctx *APIContext) {
ctx.APIErrorNotFound(nil)
return
}
if !canAccess && group.Visibility != structs.VisibleTypePublic {
if ctx.IsSigned {
if !canAccess && group.Visibility != structs.VisibleTypePublic {
ctx.APIErrorNotFound(nil)
return
}
}
if !canAccess {
ctx.APIErrorNotFound(nil)
return
}
ctx.RepoGroup = repoGroup
})