mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Merge pull request #7303 from swordqiu/hotfix/qj-domain-resource-default-share-to-system
fix: domain resource domain share to system when non_default_domain_projects off
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
@@ -248,6 +249,15 @@ func (model *SInfrasResourceBase) SaveSharedInfo(src apis.TOwnerSource, ctx cont
|
||||
}
|
||||
|
||||
func (model *SInfrasResourceBase) SyncShareState(ctx context.Context, userCred mcclient.TokenCredential, shareInfo apis.SAccountShareInfo) {
|
||||
if !consts.GetNonDefaultDomainProjects() {
|
||||
if model.PublicSrc != string(apis.OWNER_SOURCE_LOCAL) {
|
||||
model.SaveSharedInfo(apis.OWNER_SOURCE_CLOUD, ctx, userCred, apis.SShareInfo{
|
||||
IsPublic: true,
|
||||
PublicScope: rbacutils.ScopeSystem,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
si := shareInfo.GetDomainShareInfo()
|
||||
if model.PublicSrc != string(apis.OWNER_SOURCE_LOCAL) {
|
||||
model.SaveSharedInfo(apis.OWNER_SOURCE_CLOUD, ctx, userCred, si)
|
||||
|
||||
@@ -195,8 +195,10 @@ func SharableManagerValidateCreateData(
|
||||
input.PublicScope = "" // string(rbacutils.ScopeNone)
|
||||
}
|
||||
} else {
|
||||
input.IsPublic = nil
|
||||
input.PublicScope = string(rbacutils.ScopeNone)
|
||||
// if non_default_domain_projects turned off, all domain resources shared to system
|
||||
input.IsPublic = &isPublic
|
||||
input.PublicScope = string(rbacutils.ScopeSystem)
|
||||
reqScope = rbacutils.ScopeSystem
|
||||
}
|
||||
default:
|
||||
return input, errors.Wrap(httperrors.ErrInputParameter, "the resource is not sharable")
|
||||
@@ -494,6 +496,11 @@ func SharablePerformPrivate(model ISharableBaseModel, ctx context.Context, userC
|
||||
return nil
|
||||
}
|
||||
|
||||
resourceScope := model.GetModelManager().ResourceScope()
|
||||
if resourceScope == rbacutils.ScopeDomain && !consts.GetNonDefaultDomainProjects() {
|
||||
return errors.Wrap(httperrors.ErrForbidden, "not allow to private domain resource")
|
||||
}
|
||||
|
||||
requireIds := model.GetRequiredSharedDomainIds()
|
||||
if len(requireIds) == 0 {
|
||||
return errors.Wrap(httperrors.ErrForbidden, "require to be shared to system")
|
||||
|
||||
Reference in New Issue
Block a user