Permission check

This commit is contained in:
2024-05-17 19:24:14 +08:00
parent 7d3b804516
commit 4e4fbb8ba9
5 changed files with 50 additions and 33 deletions

View File

@ -104,7 +104,7 @@ func ConfirmAccount(code string) error {
for k, v := range viper.GetStringMap("permissions.verified") {
if val, ok := user.PermNodes[k]; !ok {
user.PermNodes[k] = v
} else if !HasPermNode(val, v) {
} else if !ComparePermNode(val, v) {
user.PermNodes[k] = v
}
}

View File

@ -6,7 +6,14 @@ import (
"strings"
)
func HasPermNode(held any, required any) bool {
func HasPermNode(perms map[string]any, requiredKey string, requiredValue any) bool {
if heldValue, ok := perms[requiredKey]; ok {
return ComparePermNode(heldValue, requiredValue)
}
return false
}
func ComparePermNode(held any, required any) bool {
heldValue := reflect.ValueOf(held)
requiredValue := reflect.ValueOf(required)