diff --git a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue
index 81c889b21..aa5f5cc12 100644
--- a/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue
+++ b/app/javascript/dashboard/routes/dashboard/conversation/ContactPanel.vue
@@ -1,6 +1,6 @@
diff --git a/app/javascript/dashboard/routes/dashboard/conversation/customAttributes/CustomAttributes.vue b/app/javascript/dashboard/routes/dashboard/conversation/customAttributes/CustomAttributes.vue
index cf54e7087..6dfb85c4b 100644
--- a/app/javascript/dashboard/routes/dashboard/conversation/customAttributes/CustomAttributes.vue
+++ b/app/javascript/dashboard/routes/dashboard/conversation/customAttributes/CustomAttributes.vue
@@ -17,6 +17,12 @@
@delete="onDelete"
@copy="onCopy"
/>
+
+ {{ emptyStateMessage }}
+
= ?', 1.minute.ago).count >= Limits.conversation_message_per_minute_limit
+ Rails.logger.error "Too many message: Account Id - #{account_id} : Conversation id - #{conversation_id}"
+ errors.add(:base, 'Too many messages')
+ end
+ end
+
def ensure_processed_message_content
text_content_quoted = content_attributes.dig(:email, :text_content, :quoted)
html_content_quoted = content_attributes.dig(:email, :html_content, :quoted)
diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb
index 440fc43cb..4b2831ca5 100644
--- a/config/initializers/rack_attack.rb
+++ b/config/initializers/rack_attack.rb
@@ -149,7 +149,7 @@ class Rack::Attack
end
## Prevent abuse of contact search api
- throttle('/api/v1/accounts/:account_id/contacts/search', limit: 5, period: 1.minute) do |req|
+ throttle('/api/v1/accounts/:account_id/contacts/search', limit: ENV.fetch('RATE_LIMIT_CONTACT_SEARCH', '100').to_i, period: 1.minute) do |req|
match_data = %r{/api/v1/accounts/(?\d+)/contacts/search}.match(req.path)
match_data[:account_id] if match_data.present?
end
diff --git a/enterprise/app/controllers/enterprise/public/api/v1/portals/articles_controller.rb b/enterprise/app/controllers/enterprise/public/api/v1/portals/articles_controller.rb
index ec305bfd1..240da0dca 100644
--- a/enterprise/app/controllers/enterprise/public/api/v1/portals/articles_controller.rb
+++ b/enterprise/app/controllers/enterprise/public/api/v1/portals/articles_controller.rb
@@ -3,7 +3,7 @@ module Enterprise::Public::Api::V1::Portals::ArticlesController
def search_articles
if @portal.account.feature_enabled?('help_center_embedding_search')
- @articles = @articles.vector_search(list_params) if list_params.present?
+ @articles = @articles.vector_search(list_params) if list_params[:query].present?
else
super
end
diff --git a/lib/limits.rb b/lib/limits.rb
index 720f302a8..b6b449d0d 100644
--- a/lib/limits.rb
+++ b/lib/limits.rb
@@ -4,4 +4,8 @@ module Limits
URL_LENGTH_LIMIT = 2048 # https://stackoverflow.com/questions/417142
OUT_OF_OFFICE_MESSAGE_MAX_LENGTH = 10_000
GREETING_MESSAGE_MAX_LENGTH = 10_000
+
+ def self.conversation_message_per_minute_limit
+ ENV.fetch('CONVERSATION_MESSAGE_PER_MINUTE_LIMIT', '200').to_i
+ end
end
diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb
index 9f8ea00a1..bb1bdec1a 100644
--- a/spec/models/message_spec.rb
+++ b/spec/models/message_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe Message do
end
describe 'length validations' do
- let(:message) { create(:message) }
+ let!(:message) { create(:message) }
context 'when it validates name length' do
it 'valid when within limit' do
@@ -27,6 +27,17 @@ RSpec.describe Message do
expect(message.errors[:processed_message_content]).to include('is too long (maximum is 150000 characters)')
expect(message.errors[:content]).to include('is too long (maximum is 150000 characters)')
end
+
+ it 'adds error in case of message flooding' do
+ with_modified_env 'CONVERSATION_MESSAGE_PER_MINUTE_LIMIT': '2' do
+ conversation = message.conversation
+ create(:message, conversation: conversation)
+ conv_new_message = build(:message, conversation: message.conversation)
+
+ expect(conv_new_message.valid?).to be false
+ expect(conv_new_message.errors[:base]).to eq(['Too many messages'])
+ end
+ end
end
end