diff --git a/object/application_item.go b/object/application_item.go index b5ce5bee..abe376d0 100644 --- a/object/application_item.go +++ b/object/application_item.go @@ -38,6 +38,19 @@ func (application *Application) GetProviderByCategory(category string) (*Provide return nil, nil } +func isProviderItemCountryCodeMatched(providerItem *ProviderItem, countryCode string) bool { + if len(providerItem.CountryCode) == 0 { + return true + } + + for _, countryCode2 := range providerItem.CountryCode { + if countryCode2 == "" || countryCode2 == "All" || countryCode2 == "all" || countryCode2 == countryCode { + return true + } + } + return false +} + func (application *Application) GetProviderByCategoryAndRule(category string, method string, countryCode string) (*Provider, error) { providers, err := GetProviders(application.Organization) if err != nil { @@ -54,15 +67,13 @@ func (application *Application) GetProviderByCategoryAndRule(category string, me } for _, providerItem := range application.Providers { - includeCode := false - if providerItem.CountryCode != nil { - for _, item := range providerItem.CountryCode { - if item == countryCode || item == "All" || item == "" { - includeCode = true - } + if providerItem.Provider != nil && providerItem.Provider.Category == "SMS" { + if !isProviderItemCountryCodeMatched(providerItem, countryCode) { + continue } } - if (providerItem.Rule == method || (providerItem.Rule == "All" || providerItem.Rule == "" || providerItem.Rule == "None")) && includeCode { + + if providerItem.Rule == method || providerItem.Rule == "" || providerItem.Rule == "All" || providerItem.Rule == "all" || providerItem.Rule == "None" { if provider, ok := m[providerItem.Name]; ok { return provider, nil } diff --git a/web/src/table/ProviderTable.js b/web/src/table/ProviderTable.js index d5256f73..cc4c5689 100644 --- a/web/src/table/ProviderTable.js +++ b/web/src/table/ProviderTable.js @@ -84,7 +84,7 @@ class ProviderTable extends React.Component { // If the provider is email or SMS, set the rule to "all" instead of the default "None" if (provider.category === "Email" || provider.category === "SMS") { - this.updateField(table, index, "rule", "all"); + this.updateField(table, index, "rule", "All"); } }} > { @@ -259,12 +259,12 @@ class ProviderTable extends React.Component { ); } else if (record.provider?.category === "SMS" || record.provider?.category === "Email") { if (text === "None") { - text = "all"; + text = "All"; } return (