Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Mar 17, 2023
1 parent 6753ee2 commit 456ca71
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions x/permission/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ func (k Keeper) VerifyPolicy(ctx sdk.Context, resourceID math.Uint, resourceType
policyGroup := types.PolicyGroup{}
k.cdc.MustUnmarshal(bz, &policyGroup)
allowed := false
var newPolicy *types.Policy
var effect types.Effect
var (
newPolicy *types.Policy
effect types.Effect
)
for _, item := range policyGroup.Items {
// check the group has the right permission of this resource
p := k.MustGetPolicyByID(ctx, item.PolicyId)
Expand All @@ -283,12 +285,11 @@ func (k Keeper) VerifyPolicy(ctx sdk.Context, resourceID math.Uint, resourceType
}
if allowed {
if action == types.ACTION_CREATE_OBJECT && newPolicy != nil && ctx.TxBytes() != nil {
if newPolicy.Statements == nil {
_, err := k.DeletePolicy(ctx, newPolicy.Principal, newPolicy.ResourceType, newPolicy.ResourceId)
panic(err)
} else {
if effect == types.EFFECT_ALLOW && action == types.ACTION_CREATE_OBJECT && newPolicy != nil && ctx.TxBytes() != nil {
_, err := k.PutPolicy(ctx, newPolicy)
panic(err)
if err != nil {
panic(fmt.Sprintf("Update policy error, %s", err))
}
}
}
return types.EFFECT_ALLOW
Expand Down

0 comments on commit 456ca71

Please sign in to comment.