-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x/circuit): Add validation for permission when an account is ass…
…igned and validation for msgURL (#22460)
- Loading branch information
Showing
4 changed files
with
126 additions
and
7 deletions.
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 | ||
} |