mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-28 03:23:25 +08:00
fix(keystone): policy name duplication (#10200)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -138,7 +138,9 @@ func init() {
|
||||
Enabled bool `help:"update policy enabled"`
|
||||
Disabled bool `help:"update policy disabled"`
|
||||
Desc string `help:"Description"`
|
||||
IsSystem *bool `help:"is_system"`
|
||||
IsSystem bool `help:"is_system"`
|
||||
|
||||
IsNotSystem bool `help:"negative is_system"`
|
||||
}
|
||||
updateFunc := func(s *mcclient.ClientSession, args *PolicyPatchOptions) error {
|
||||
policyId, err := modules.Policies.GetId(s, args.ID, nil)
|
||||
@@ -164,14 +166,13 @@ func init() {
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "description")
|
||||
}
|
||||
if args.IsSystem != nil {
|
||||
if *args.IsSystem {
|
||||
params.Add(jsonutils.JSONTrue, "is_system")
|
||||
} else {
|
||||
params.Add(jsonutils.JSONFalse, "is_system")
|
||||
}
|
||||
if args.IsSystem {
|
||||
params.Add(jsonutils.JSONTrue, "is_system")
|
||||
}
|
||||
result, err := modules.Policies.Patch(s, policyId, params)
|
||||
if args.IsNotSystem {
|
||||
params.Add(jsonutils.JSONFalse, "is_system")
|
||||
}
|
||||
result, err := modules.Policies.Update(s, policyId, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
policyman "yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
@@ -476,6 +477,15 @@ func (manager *SPolicyManager) ListItemFilter(
|
||||
q = q.IsFalse("is_system")
|
||||
}
|
||||
}
|
||||
if len(query.Scope) == 0 {
|
||||
query.Scope = string(policyman.PolicyManager.AllowScope(userCred, consts.GetServiceType(), manager.KeywordPlural(), policyman.PolicyActionList))
|
||||
}
|
||||
switch query.Scope {
|
||||
case string(rbacutils.ScopeProject):
|
||||
q = q.Equals("scope", rbacutils.ScopeProject)
|
||||
case string(rbacutils.ScopeDomain):
|
||||
q = q.NotEquals("scope", rbacutils.ScopeSystem)
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -548,12 +558,6 @@ func (policy *SPolicy) GetUsages() []db.IUsage {
|
||||
|
||||
func (manager *SPolicyManager) FilterByOwner(q *sqlchemy.SQuery, owner mcclient.IIdentityProvider, scope rbacutils.TRbacScope) *sqlchemy.SQuery {
|
||||
q = db.SharableManagerFilterByOwner(manager, q, owner, scope)
|
||||
switch scope {
|
||||
case rbacutils.ScopeProject:
|
||||
q = q.Equals("scope", rbacutils.ScopeProject)
|
||||
case rbacutils.ScopeDomain:
|
||||
q = q.NotEquals("scope", rbacutils.ScopeSystem)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user