mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
backport #38871 Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -303,7 +303,7 @@ func (org *Organization) UnitPermission(ctx context.Context, doer *user_model.Us
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if org.Visibility.IsPublic() {
|
if ownerVisibilitySatisfiesDoer(org.AsUser(), doer) {
|
||||||
return perm.AccessModeRead
|
return perm.AccessModeRead
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,8 +445,7 @@ func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) (map[int64]*u
|
|||||||
And("team_user.org_id = ?", orgID).Find(&users)
|
And("team_user.org_id = ?", orgID).Find(&users)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasOrgOrUserVisible tells if the given user can see the given org or user
|
func ownerVisibilitySatisfiesDoer(orgOrUser, user *user_model.User) bool {
|
||||||
func HasOrgOrUserVisible(ctx context.Context, orgOrUser, user *user_model.User) bool {
|
|
||||||
// If user is nil, it's an anonymous user/request.
|
// If user is nil, it's an anonymous user/request.
|
||||||
// The Ghost user is handled like an anonymous user.
|
// The Ghost user is handled like an anonymous user.
|
||||||
if user == nil || user.IsGhost() {
|
if user == nil || user.IsGhost() {
|
||||||
@@ -461,10 +460,13 @@ func HasOrgOrUserVisible(ctx context.Context, orgOrUser, user *user_model.User)
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orgOrUser.Visibility == structs.VisibleTypePrivate || user.IsRestricted) && !OrgFromUser(orgOrUser).hasMemberWithUserID(ctx, user.ID) {
|
return orgOrUser.Visibility != structs.VisibleTypePrivate && !user.IsRestricted
|
||||||
return false
|
}
|
||||||
}
|
|
||||||
return true
|
// HasOrgOrUserVisible tells if the given user can see the given org or user
|
||||||
|
func HasOrgOrUserVisible(ctx context.Context, owner, doer *user_model.User) bool {
|
||||||
|
return ownerVisibilitySatisfiesDoer(owner, doer) ||
|
||||||
|
(doer != nil && OrgFromUser(owner).HasMemberWithUserID(ctx, doer.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasOrgsVisible tells if the given user can see at least one of the orgs provided
|
// HasOrgsVisible tells if the given user can see at least one of the orgs provided
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import (
|
|||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/models/db"
|
||||||
"gitea.dev/models/organization"
|
"gitea.dev/models/organization"
|
||||||
|
"gitea.dev/models/perm"
|
||||||
repo_model "gitea.dev/models/repo"
|
repo_model "gitea.dev/models/repo"
|
||||||
|
"gitea.dev/models/unit"
|
||||||
"gitea.dev/models/unittest"
|
"gitea.dev/models/unittest"
|
||||||
user_model "gitea.dev/models/user"
|
user_model "gitea.dev/models/user"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
@@ -626,3 +628,10 @@ func TestCreateOrganization4(t *testing.T) {
|
|||||||
assert.True(t, db.IsErrNameReserved(err))
|
assert.True(t, db.IsErrNameReserved(err))
|
||||||
unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{})
|
unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOrAnyRepoUnitPermission(t *testing.T) {
|
||||||
|
defer test.MockVariableValue(&setting.Service.RequireSignInViewStrict, true)()
|
||||||
|
org := organization.Organization{Visibility: structs.VisibleTypeLimited}
|
||||||
|
assert.Equal(t, perm.AccessModeNone, org.UnitPermission(t.Context(), nil, unit.TypeWiki))
|
||||||
|
assert.Equal(t, perm.AccessModeRead, org.UnitPermission(t.Context(), &user_model.User{}, unit.TypeWiki))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user