fix mobile task rules and feature availability

This commit is contained in:
richjohnrambo
2026-10-18 20:53:33 +08:00
parent b79b781f15
commit 5a0fe67027
11 changed files with 144 additions and 130 deletions
+14 -8
View File
@@ -803,7 +803,10 @@ func (s *Service) ensureWithdrawalEnabled(ctx context.Context, tenantID int64) e
return err
}
var config map[string]any
if json.Unmarshal(raw, &config) != nil || !findBool(config, "withdrawal_enabled", "withdrawalEnabled", "WITHDRAWAL") {
if json.Unmarshal(raw, &config) != nil {
config = map[string]any{}
}
if enabled, found := findBoolValue(config, "withdrawal_enabled", "withdrawalEnabled", "WITHDRAWAL"); found && !enabled {
return store.ErrWithdrawalDisabled
}
return nil
@@ -1142,25 +1145,28 @@ func allDigits(value string) bool {
return value != ""
}
func findBool(config map[string]any, keys ...string) bool {
func findBoolValue(config map[string]any, keys ...string) (bool, bool) {
for _, key := range keys {
for candidate, value := range config {
if strings.EqualFold(candidate, key) {
switch typed := value.(type) {
case bool:
return typed
return typed, true
case float64:
return typed == 1
return typed == 1, true
case string:
return typed == "1" || strings.EqualFold(typed, "true") || strings.EqualFold(typed, "on")
return typed == "1" || strings.EqualFold(typed, "true") || strings.EqualFold(typed, "on"), true
}
return false, true
}
}
}
for _, value := range config {
if nested, ok := value.(map[string]any); ok && findBool(nested, keys...) {
return true
if nested, ok := value.(map[string]any); ok {
if result, found := findBoolValue(nested, keys...); found {
return result, true
}
}
}
return false
return false, false
}