summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-07-09 15:00:07 +0200
committerGitHub <noreply@github.com>2023-07-09 13:00:07 +0000
commit321383db22b19e302aafe59194f0b6539257d90f (patch)
tree135d83b42bffe38082dde5ccf3b7515c9ca2c2b7 /modules/context
parent819aed35bff81574920c2a87eddbebed5ddfda1f (diff)
downloadgitea-321383db22b19e302aafe59194f0b6539257d90f.tar.gz
gitea-321383db22b19e302aafe59194f0b6539257d90f.zip
Revert package access change from #23879 (#25707)
Fixes (?) #25538 Fixes https://codeberg.org/forgejo/forgejo/issues/972 Regression #23879 #23879 introduced a change which prevents read access to packages if a user is not a member of an organization. That PR also contained a change which disallows package access if the team unit is configured with "no access" for packages. I don't think this change makes sense (at the moment). It may be relevant for private orgs. But for public or limited orgs that's useless because an unauthorized user would have more access rights than the team member. This PR restores the old behaviour "If a user has read access for an owner, they can read packages". --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/package.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/modules/context/package.go b/modules/context/package.go
index 8e80fa66ec..be50e0a991 100644
--- a/modules/context/package.go
+++ b/modules/context/package.go
@@ -108,18 +108,28 @@ func determineAccessMode(ctx *Base, pkg *Package, doer *user_model.User) (perm.A
if doer != nil && !doer.IsGhost() {
// 1. If user is logged in, check all team packages permissions
- teams, err := organization.GetUserOrgTeams(ctx, org.ID, doer.ID)
+ var err error
+ accessMode, err = org.GetOrgUserMaxAuthorizeLevel(doer.ID)
if err != nil {
return accessMode, err
}
- for _, t := range teams {
- perm := t.UnitAccessMode(ctx, unit.TypePackages)
- if accessMode < perm {
- accessMode = perm
+ // If access mode is less than write check every team for more permissions
+ // The minimum possible access mode is read for org members
+ if accessMode < perm.AccessModeWrite {
+ teams, err := organization.GetUserOrgTeams(ctx, org.ID, doer.ID)
+ if err != nil {
+ return accessMode, err
+ }
+ for _, t := range teams {
+ perm := t.UnitAccessMode(ctx, unit.TypePackages)
+ if accessMode < perm {
+ accessMode = perm
+ }
}
}
- } else if organization.HasOrgOrUserVisible(ctx, pkg.Owner, doer) {
- // 2. If user is non-login, check if org is visible to non-login user
+ }
+ if accessMode == perm.AccessModeNone && organization.HasOrgOrUserVisible(ctx, pkg.Owner, doer) {
+ // 2. If user is unauthorized or no org member, check if org is visible
accessMode = perm.AccessModeRead
}
} else {