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:
yunion-ci-robot
2020-07-23 20:31:34 +08:00
committed by GitHub
2 changed files with 19 additions and 2 deletions
+10
View File
@@ -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)
+9 -2
View File
@@ -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")