1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Merge pull request '[v9.0/forgejo] fix: correct permission loading for limited organisation' (#6149) from bp-v9.0/forgejo-bc9f1e2 into v9.0/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6149
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
This commit is contained in:
Gusted 2024-12-04 20:54:15 +00:00
commit ad1aad7b1a
2 changed files with 35 additions and 1 deletions

View file

@ -264,7 +264,7 @@ func (org *Organization) UnitPermission(ctx context.Context, doer *user_model.Us
}
}
if org.Visibility.IsPublic() {
if org.Visibility.IsPublic() || (org.Visibility.IsLimited() && doer != nil) {
return perm.AccessModeRead
}

View file

@ -8,7 +8,9 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/structs"
@ -512,3 +514,35 @@ func TestCreateOrganization4(t *testing.T) {
assert.True(t, db.IsErrNameReserved(err))
unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{})
}
func TestUnitPermission(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
publicOrg := &organization.Organization{ID: 1001, Visibility: structs.VisibleTypePublic}
limitedOrg := &organization.Organization{ID: 1001, Visibility: structs.VisibleTypeLimited}
privateOrg := &organization.Organization{ID: 1001, Visibility: structs.VisibleTypePrivate}
user := &user_model.User{ID: 1001}
t.Run("Anonymous", func(t *testing.T) {
t.Run("Public", func(t *testing.T) {
assert.EqualValues(t, perm.AccessModeRead, publicOrg.UnitPermission(db.DefaultContext, nil, unit.TypeCode))
})
t.Run("Limited", func(t *testing.T) {
assert.EqualValues(t, perm.AccessModeNone, limitedOrg.UnitPermission(db.DefaultContext, nil, unit.TypeCode))
})
t.Run("Private", func(t *testing.T) {
assert.EqualValues(t, perm.AccessModeNone, privateOrg.UnitPermission(db.DefaultContext, nil, unit.TypeCode))
})
})
t.Run("Logged in", func(t *testing.T) {
t.Run("Public", func(t *testing.T) {
assert.EqualValues(t, perm.AccessModeRead, publicOrg.UnitPermission(db.DefaultContext, user, unit.TypeCode))
})
t.Run("Limited", func(t *testing.T) {
assert.EqualValues(t, perm.AccessModeRead, limitedOrg.UnitPermission(db.DefaultContext, user, unit.TypeCode))
})
t.Run("Private", func(t *testing.T) {
assert.EqualValues(t, perm.AccessModeNone, privateOrg.UnitPermission(db.DefaultContext, user, unit.TypeCode))
})
})
}