-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(x/circuit): Add validation for permission when an account is assigned and validation for msgURL #22460
Merged
julienrbrt
merged 9 commits into
cosmos:main
from
decentrio:add-validation-for-permission-circuit-module
Nov 7, 2024
+126
−7
Merged
feat(x/circuit): Add validation for permission when an account is assigned and validation for msgURL #22460
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db68f2d
add validation for permission
GNaD13 bda9cae
add validation for msg url
GNaD13 3bc3fe4
add more validation
GNaD13 6d3de88
nit
GNaD13 57c69c2
nit
GNaD13 47242f1
add change log
GNaD13 bd395b9
Merge remote-tracking branch 'origin/main' into add-validation-for-pe…
GNaD13 2b68c2e
nit
GNaD13 542997e
fix test
GNaD13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package types | ||
|
||
import "errors" | ||
|
||
func (p *Permissions) Validation() error { | ||
switch { | ||
case p.Level == Permissions_LEVEL_SOME_MSGS: | ||
// if permission is some msg, LimitTypeUrls array must not be empty | ||
if len(p.LimitTypeUrls) == 0 { | ||
return errors.New("LimitTypeUrls of LEVEL_SOME_MSGS should NOT be empty") | ||
} | ||
|
||
p.LimitTypeUrls = MsgTypeURLValidation(p.LimitTypeUrls) | ||
case p.Level == Permissions_LEVEL_ALL_MSGS || p.Level == Permissions_LEVEL_SUPER_ADMIN: | ||
// if permission is all msg or super addmin, LimitTypeUrls array clear | ||
// all p.LimitTypeUrls since we not use this field | ||
p.LimitTypeUrls = nil | ||
default: | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func MsgTypeURLValidation(urls []string) []string { | ||
for idx, url := range urls { | ||
if len(url) == 0 { | ||
continue | ||
} | ||
if url[0] != '/' { | ||
urls[idx] = "/" + url | ||
} | ||
} | ||
return urls | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error message assertion for SOME_MSGS validation.
The test should verify the specific error message when SOME_MSGS permission is granted with empty LimitTypeUrls.
📝 Committable suggestion