fix: country_code should be checked against the contact (#13186)

This commit is contained in:
Shivam Mishra
2026-01-13 14:47:27 +05:30
committed by GitHub
parent 821a5b85c2
commit 7b51939f07
8 changed files with 53 additions and 33 deletions

View File

@@ -11,7 +11,6 @@ export const CONVERSATION_ATTRIBUTES = {
CAMPAIGN_ID: 'campaign_id',
LABELS: 'labels',
BROWSER_LANGUAGE: 'browser_language',
COUNTRY_CODE: 'country_code',
REFERER: 'referer',
CREATED_AT: 'created_at',
LAST_ACTIVITY_AT: 'last_activity_at',

View File

@@ -7,7 +7,6 @@ import {
buildAttributesFilterTypes,
CONVERSATION_ATTRIBUTES,
} from './helper/filterHelper';
import countries from 'shared/constants/countries.js';
import languages from 'dashboard/components/widgets/conversation/advancedFilterItems/languages.js';
/**
@@ -218,17 +217,6 @@ export function useConversationFilterContext() {
filterOperators: equalityOperators.value,
attributeModel: 'additional',
},
{
attributeKey: CONVERSATION_ATTRIBUTES.COUNTRY_CODE,
value: CONVERSATION_ATTRIBUTES.COUNTRY_CODE,
attributeName: t('FILTER.ATTRIBUTES.COUNTRY_NAME'),
label: t('FILTER.ATTRIBUTES.COUNTRY_NAME'),
inputType: 'searchSelect',
options: countries,
dataType: 'text',
filterOperators: equalityOperators.value,
attributeModel: 'additional',
},
{
attributeKey: CONVERSATION_ATTRIBUTES.REFERER,
value: CONVERSATION_ATTRIBUTES.REFERER,

View File

@@ -78,14 +78,6 @@ const filterTypes = [
filterOperators: OPERATOR_TYPES_1,
attributeModel: 'additional',
},
{
attributeKey: 'country_code',
attributeI18nKey: 'COUNTRY_NAME',
inputType: 'search_select',
dataType: 'text',
filterOperators: OPERATOR_TYPES_1,
attributeModel: 'additional',
},
{
attributeKey: 'referer',
attributeI18nKey: 'REFERER_LINK',
@@ -171,10 +163,6 @@ export const filterAttributeGroups = [
key: 'browser_language',
i18nKey: 'BROWSER_LANGUAGE',
},
{
key: 'country_code',
i18nKey: 'COUNTRY_NAME',
},
{
key: 'referer',
i18nKey: 'REFERER_LINK',

View File

@@ -78,7 +78,6 @@ const getValueFromConversation = (conversation, attributeKey) => {
case 'team_id':
return conversation.meta?.team?.id;
case 'browser_language':
case 'country_code':
case 'referer':
return conversation.additional_attributes?.[attributeKey];
default:

View File

@@ -0,0 +1,32 @@
class RemoveCountryCodeFromConversationFilters < ActiveRecord::Migration[7.1]
def up
CustomFilter.conversation
.where('query::text LIKE ?', '%country_code%')
.find_each do |custom_filter|
query = custom_filter.query || {}
payload = query['payload']
next unless payload.is_a?(Array)
updated_payload = payload.reject do |filter|
filter.is_a?(Hash) && filter['attribute_key'] == 'country_code'
end
next if updated_payload == payload
if updated_payload.empty?
custom_filter.delete
next
end
# rubocop:disable Rails/SkipsModelValidations
# we will skip model validation, since we don't want any callbacks running
custom_filter.update_columns(query: query.merge('payload' => updated_payload))
# rubocop:enable Rails/SkipsModelValidations
end
end
def down
# no-op: removed filters cannot be restored reliably
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2025_12_29_081141) do
ActiveRecord::Schema[7.1].define(version: 2026_01_12_092041) do
# These extensions should be enabled to support this database
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"

View File

@@ -86,12 +86,6 @@ conversations:
filter_operators:
- "equal_to"
- "not_equal_to"
country_code:
attribute_type: "additional_attributes"
data_type: "text"
filter_operators:
- "equal_to"
- "not_equal_to"
referer:
attribute_type: "additional_attributes"
data_type: "link"

View File

@@ -215,5 +215,25 @@ RSpec.describe AutomationRules::ConditionsFilterService do
end
end
end
context 'when conditions based on contact country_code' do
before do
conversation.update(additional_attributes: { country_code: 'US' })
conversation.contact.update(additional_attributes: { country_code: 'IN' })
rule.conditions = [
{ 'values': ['IN'], 'attribute_key': 'country_code', 'query_operator': nil, 'filter_operator': 'equal_to' }
]
rule.save
end
it 'matches against the contact additional_attributes' do
expect(described_class.new(rule, conversation, { changed_attributes: {} }).perform).to be(true)
end
it 'returns false when the contact country_code does not match' do
conversation.contact.update(additional_attributes: { country_code: 'GB' })
expect(described_class.new(rule, conversation, { changed_attributes: {} }).perform).to be(false)
end
end
end
end