mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-28 02:41:37 +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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update payment configuration (integrated into system settings)
|
// Update payment configuration (integrated into system settings).
|
||||||
if h.paymentConfigService != nil {
|
// Skip if no payment fields were provided (prevents accidental wipe).
|
||||||
|
if h.paymentConfigService != nil && hasPaymentFields(req) {
|
||||||
paymentReq := service.UpdatePaymentConfigRequest{
|
paymentReq := service.UpdatePaymentConfigRequest{
|
||||||
Enabled: req.PaymentEnabled,
|
Enabled: req.PaymentEnabled,
|
||||||
MinAmount: req.PaymentMinAmount,
|
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) {
|
func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.SystemSettings, after *service.SystemSettings, req UpdateSettingsRequest) {
|
||||||
if before == nil || after == nil {
|
if before == nil || after == nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ const (
|
|||||||
|
|
||||||
// Default values for payment configuration settings.
|
// Default values for payment configuration settings.
|
||||||
const (
|
const (
|
||||||
defaultMinRechargeAmount = 1
|
defaultOrderTimeoutMin = 30
|
||||||
defaultMaxRechargeAmount = 99999999.99
|
defaultMaxPendingOrders = 3
|
||||||
defaultOrderTimeoutMin = 30
|
|
||||||
defaultMaxPendingOrders = 3
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PaymentConfig holds the payment system configuration.
|
// PaymentConfig holds the payment system configuration.
|
||||||
@@ -464,8 +462,9 @@ func (s *PaymentConfigService) UpdateProviderInstance(ctx context.Context, id in
|
|||||||
return u.Save(ctx)
|
return u.Save(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeConfig merges new config with existing config, preserving sensitive
|
// mergeConfig merges new config with existing config. All keys from newConfig
|
||||||
// fields that were not re-submitted (frontend skips masked ••••••••).
|
// 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) {
|
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)
|
inst, err := s.entClient.PaymentProviderInstance.Get(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user