-
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.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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") | ||
} | ||
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 | ||
} |