feat: fix the Email provider fails to match bug in GetProviderByCategoryAndRule()

This commit is contained in:
Yang Luo 2024-05-01 09:44:19 +08:00
parent bafa80513b
commit 43393f034b
2 changed files with 21 additions and 10 deletions

View File

@ -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
}

View File

@ -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 (
<Select virtual={false} style={{width: "100%"}}
value={text}
defaultValue="all"
defaultValue="All"
onChange={value => {
this.updateField(table, index, "rule", value);
}}>