mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
fix: guard against accidental payment config wipe + cleanup from review
- Skip UpdatePaymentConfig when no payment fields provided (prevents wipe) - Remove unused defaultMinRechargeAmount/defaultMaxRechargeAmount constants - Fix mergeConfig comment to match actual behavior
This commit is contained in:
@@ -1 +1 @@
|
||||
0.1.108.60
|
||||
0.1.108.61
|
||||
|
||||
@@ -660,8 +660,9 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Update payment configuration (integrated into system settings)
|
||||
if h.paymentConfigService != nil {
|
||||
// Update payment configuration (integrated into system settings).
|
||||
// Skip if no payment fields were provided (prevents accidental wipe).
|
||||
if h.paymentConfigService != nil && hasPaymentFields(req) {
|
||||
paymentReq := service.UpdatePaymentConfigRequest{
|
||||
Enabled: req.PaymentEnabled,
|
||||
MinAmount: req.PaymentMinAmount,
|
||||
@@ -780,6 +781,17 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// hasPaymentFields returns true if any payment-related field was explicitly provided.
|
||||
func hasPaymentFields(req UpdateSettingsRequest) bool {
|
||||
return req.PaymentEnabled != nil || req.PaymentMinAmount != nil ||
|
||||
req.PaymentMaxAmount != nil || req.PaymentDailyLimit != nil ||
|
||||
req.PaymentOrderTimeoutMin != nil || req.PaymentMaxPendingOrders != nil ||
|
||||
req.PaymentEnabledTypes != nil || req.PaymentBalanceDisabled != nil ||
|
||||
req.PaymentLoadBalanceStrat != nil || req.PaymentProductNamePrefix != nil ||
|
||||
req.PaymentProductNameSuffix != nil || req.PaymentHelpImageURL != nil ||
|
||||
req.PaymentHelpText != nil
|
||||
}
|
||||
|
||||
func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.SystemSettings, after *service.SystemSettings, req UpdateSettingsRequest) {
|
||||
if before == nil || after == nil {
|
||||
return
|
||||
|
||||
@@ -38,10 +38,8 @@ const (
|
||||
|
||||
// Default values for payment configuration settings.
|
||||
const (
|
||||
defaultMinRechargeAmount = 1
|
||||
defaultMaxRechargeAmount = 99999999.99
|
||||
defaultOrderTimeoutMin = 30
|
||||
defaultMaxPendingOrders = 3
|
||||
defaultOrderTimeoutMin = 30
|
||||
defaultMaxPendingOrders = 3
|
||||
)
|
||||
|
||||
// PaymentConfig holds the payment system configuration.
|
||||
@@ -464,8 +462,9 @@ func (s *PaymentConfigService) UpdateProviderInstance(ctx context.Context, id in
|
||||
return u.Save(ctx)
|
||||
}
|
||||
|
||||
// mergeConfig merges new config with existing config, preserving sensitive
|
||||
// fields that were not re-submitted (frontend skips masked ••••••••).
|
||||
// mergeConfig merges new config with existing config. All keys from newConfig
|
||||
// overwrite existing values (including empty strings to clear a field).
|
||||
// Keys not present in newConfig are preserved from existing config.
|
||||
func (s *PaymentConfigService) mergeConfig(ctx context.Context, id int64, newConfig map[string]string) (map[string]string, error) {
|
||||
inst, err := s.entClient.PaymentProviderInstance.Get(ctx, id)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user