diff --git a/app/models/account.rb b/app/models/account.rb index eabaa5c26..85754a395 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -85,11 +85,13 @@ class Account < ApplicationRecord validates_with JsonSchemaValidator, schema: SETTINGS_PARAMS_SCHEMA, attribute_resolver: ->(record) { record.settings } + validate :validate_reporting_timezone store_accessor :settings, :auto_resolve_after, :auto_resolve_message, :auto_resolve_ignore_waiting store_accessor :settings, :audio_transcriptions, :auto_resolve_label store_accessor :settings, :captain_models, :captain_features + store_accessor :settings, :reporting_timezone store_accessor :settings, :keep_pending_on_bot_failure store_accessor :settings, :captain_disable_auto_resolve @@ -214,6 +216,12 @@ class Account < ApplicationRecord # method overridden in enterprise module end + def validate_reporting_timezone + return if reporting_timezone.blank? || ActiveSupport::TimeZone[reporting_timezone].present? + + errors.add(:reporting_timezone, I18n.t('errors.account.reporting_timezone.invalid')) + end + def remove_account_sequences ActiveRecord::Base.connection.exec_query("drop sequence IF EXISTS camp_dpid_seq_#{id}") ActiveRecord::Base.connection.exec_query("drop sequence IF EXISTS conv_dpid_seq_#{id}") diff --git a/config/features.yml b/config/features.yml index 41515ff64..894d94ef0 100644 --- a/config/features.yml +++ b/config/features.yml @@ -241,3 +241,6 @@ display_name: Advanced Assignment enabled: false premium: true +- name: reporting_events_rollup + display_name: Reporting Events Rollup + enabled: false diff --git a/config/locales/en.yml b/config/locales/en.yml index 68bea856e..b0f1f4e2e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,6 +48,9 @@ en: inbox_deletetion_response: Your inbox deletion request will be processed in some time. errors: + account: + reporting_timezone: + invalid: is not a valid timezone validations: presence: must not be blank webhook: diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 5ccff6517..3da958188 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -217,6 +217,21 @@ RSpec.describe Account do expect(described_class.with_auto_resolve.pluck(:id)).not_to include(account.id) end end + + context 'when reporting_timezone is set' do + it 'allows valid timezone names' do + account.reporting_timezone = 'America/New_York' + + expect(account).to be_valid + end + + it 'rejects invalid timezone names' do + account.reporting_timezone = 'Invalid/Timezone' + + expect(account).not_to be_valid + expect(account.errors[:reporting_timezone]).to include(I18n.t('errors.account.reporting_timezone.invalid')) + end + end end describe 'captain_preferences' do