From 0974aea30071ce464e7ef4a749b8957b383cca1e Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Mon, 6 Oct 2025 23:11:26 +0530 Subject: [PATCH] chore: Increase custom filter limit from 50 to 1000 per user (#12603) # Pull Request Template ## Description This PR increases the custom filter limit from 50 to 1000 per user ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? ### Screenshot image ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --- app/models/custom_filter.rb | 3 +-- config/locales/en.yml | 2 +- lib/limits.rb | 1 + .../api/v1/accounts/custom_filters_controller_spec.rb | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index b3d58fd17..6d64c0447 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -17,7 +17,6 @@ # index_custom_filters_on_user_id (user_id) # class CustomFilter < ApplicationRecord - MAX_FILTER_PER_USER = 50 belongs_to :user belongs_to :account @@ -25,7 +24,7 @@ class CustomFilter < ApplicationRecord validate :validate_number_of_filters def validate_number_of_filters - return true if account.custom_filters.where(user_id: user_id).size < MAX_FILTER_PER_USER + return true if account.custom_filters.where(user_id: user_id).size < Limits::MAX_CUSTOM_FILTERS_PER_USER errors.add :account_id, I18n.t('errors.custom_filters.number_of_records') end diff --git a/config/locales/en.yml b/config/locales/en.yml index c106531a0..0c76f8beb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -100,7 +100,7 @@ en: validations: name: should not start or end with symbols, and it should not have < > / \ @ characters. custom_filters: - number_of_records: Limit reached. The maximum number of allowed custom filters for a user per account is 50. + number_of_records: Limit reached. The maximum number of allowed custom filters for a user per account is 1000. invalid_attribute: Invalid attribute key - [%{key}]. The key should be one of [%{allowed_keys}] or a custom attribute defined in the account. invalid_operator: Invalid operator. The allowed operators for %{attribute_name} are [%{allowed_keys}]. invalid_query_operator: Query operator must be either "AND" or "OR". diff --git a/lib/limits.rb b/lib/limits.rb index 7a2371207..5da178bf4 100644 --- a/lib/limits.rb +++ b/lib/limits.rb @@ -6,6 +6,7 @@ module Limits GREETING_MESSAGE_MAX_LENGTH = 10_000 CATEGORIES_PER_PAGE = 1000 AUTO_ASSIGNMENT_BULK_LIMIT = 100 + MAX_CUSTOM_FILTERS_PER_USER = 1000 def self.conversation_message_per_minute_limit ENV.fetch('CONVERSATION_MESSAGE_PER_MINUTE_LIMIT', '200').to_i diff --git a/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb b/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb index 760100cf3..9c9469090 100644 --- a/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb @@ -93,9 +93,9 @@ RSpec.describe 'Custom Filters API', type: :request do expect(json_response['name']).to eq 'vip-customers' end - it 'gives the error for 51st record' do + it 'gives the error for 1001st record' do CustomFilter.delete_all - CustomFilter::MAX_FILTER_PER_USER.times do + Limits::MAX_CUSTOM_FILTERS_PER_USER.times do create(:custom_filter, user: user, account: account) end @@ -107,7 +107,7 @@ RSpec.describe 'Custom Filters API', type: :request do expect(response).to have_http_status(:unprocessable_entity) json_response = response.parsed_body expect(json_response['message']).to include( - 'Account Limit reached. The maximum number of allowed custom filters for a user per account is 50.' + 'Account Limit reached. The maximum number of allowed custom filters for a user per account is 1000.' ) end end