diff --git a/app/models/message.rb b/app/models/message.rb index 06be665d8..dbab19df3 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -244,8 +244,16 @@ class Message < ApplicationRecord def should_index? return false unless ChatwootApp.advanced_search_allowed? - return false unless account.feature_enabled?('advanced_search') return false unless incoming? || outgoing? + # For Chatwoot Cloud: + # - Enable indexing only if the account is paid. + # - The `advanced_search_indexing` feature flag is used only in the cloud. + # + # For Self-hosted: + # - Adding an extra feature flag here would cause confusion. + # - If the user has configured Elasticsearch, enabling `advanced_search` + # should automatically work without any additional flags. + return false if ChatwootApp.chatwoot_cloud? && !account.feature_enabled?('advanced_search_indexing') true end diff --git a/config/features.yml b/config/features.yml index 181284784..40083812a 100644 --- a/config/features.yml +++ b/config/features.yml @@ -209,3 +209,8 @@ display_name: SAML enabled: false premium: true +- name: advanced_search_indexing + display_name: Advanced Search Indexing + enabled: false + premium: true + chatwoot_internal: true diff --git a/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb b/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb index a21afff3c..18dc9e69f 100644 --- a/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb +++ b/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb @@ -15,6 +15,7 @@ class Enterprise::Billing::HandleStripeEventService channel_email channel_instagram captain_integration + advanced_search_indexing ].freeze # Additional features available starting with the Business plan diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index 2234c1ad6..a0bd48e39 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -621,7 +621,7 @@ RSpec.describe Message do before do allow(ChatwootApp).to receive(:advanced_search_allowed?).and_return(true) - account.enable_features('advanced_search') + account.enable_features('advanced_search_indexing') end context 'when advanced search is not allowed globally' do @@ -634,9 +634,10 @@ RSpec.describe Message do end end - context 'when advanced search feature is not enabled for account' do + context 'when advanced search feature is not enabled for account on chatwoot cloud' do before do - account.disable_features('advanced_search') + allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true) + account.disable_features('advanced_search_indexing') end it 'returns false' do @@ -644,6 +645,17 @@ RSpec.describe Message do end end + context 'when advanced search feature is not enabled for account on self-hosted' do + before do + allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(false) + account.disable_features('advanced_search_indexing') + end + + it 'returns true' do + expect(message.should_index?).to be true + end + end + context 'when message type is not incoming or outgoing' do before do message.message_type = 'activity'