diff --git a/.circleci/config.yml b/.circleci/config.yml index fbb4fea9074e9..e6394ccde2126 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ defaults: &defaults working_directory: ~/build docker: # specify the version you desire here - - image: cimg/ruby:3.0.4-browsers + - image: cimg/ruby:3.1.3-browsers # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images @@ -38,6 +38,18 @@ jobs: name: Which bundler? command: bundle -v + - run: + name: Swap node versions + command: | + set +e + wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" + nvm install v16 + echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV + echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV + # Run bundler # Load installed gems from cache if possible, bundle install then save cache # Multiple caches are used to increase the chance of a cache hit @@ -193,4 +205,3 @@ workflows: - upload-coverage: requires: - build - diff --git a/.github/workflows/run_foss_spec.yml b/.github/workflows/run_foss_spec.yml index 39df7aa3de745..98fae5c8efb74 100644 --- a/.github/workflows/run_foss_spec.yml +++ b/.github/workflows/run_foss_spec.yml @@ -47,7 +47,6 @@ jobs: - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0.4 # Not needed with a .ruby-version file bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: yarn diff --git a/.rubocop.yml b/.rubocop.yml index dafd9a620b7d3..426989bd6c9ea 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -86,6 +86,10 @@ Style/ClassAndModuleChildren: - 'config/application.rb' Style/MapToHash: Enabled: false +Style/HashSyntax: + Enabled: true + EnforcedStyle: no_mixed_keys + EnforcedShorthandSyntax: never RSpec/NestedGroups: Enabled: true Max: 4 diff --git a/.ruby-version b/.ruby-version index b0f2dcb32fc28..ff365e06b9577 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.4 +3.1.3 diff --git a/Gemfile b/Gemfile index 1d9c50cb62bd4..3f520988b214f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '3.0.4' +ruby '3.1.3' ##-- base gems for rails --## gem 'rack-cors', require: 'rack/cors' @@ -107,7 +107,12 @@ gem 'sidekiq-cron', '~> 1.3' ##-- Push notification service --## gem 'fcm' -gem 'webpush' + +# Ref: https://github.com/mastodon/mastodon/pull/18449 +# ref: https://github.com/zaru/webpush/pull/106 +# lets switch to web-push gem once the above PR is merged +# https://github.com/zaru/webpush/pull/106#issuecomment-1342925261 +gem 'webpush', git: 'https://github.com/ClearlyClaire/webpush.git', ref: 'f14a4d52e201128b1b00245d11b6de80d6cfdcd9' ##-- geocoding / parse location from ip --## # http://www.rubygeocoder.com/ @@ -137,6 +142,11 @@ gem 'stripe' ## to populate db with sample data gem 'faker' +# Can remove this in rails 7 +gem 'net-imap', require: false +gem 'net-pop', require: false +gem 'net-smtp', require: false + group :production, :staging do # we dont want request timing out in development while using byebug gem 'rack-timeout' diff --git a/Gemfile.lock b/Gemfile.lock index 1fcc64446dadc..fee18814a8f3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,12 @@ +GIT + remote: https://github.com/ClearlyClaire/webpush.git + revision: f14a4d52e201128b1b00245d11b6de80d6cfdcd9 + ref: f14a4d52e201128b1b00245d11b6de80d6cfdcd9 + specs: + webpush (0.3.8) + hkdf (~> 0.2) + jwt (~> 2.0) + GIT remote: https://github.com/chatwoot/devise-secure_password revision: d777b04f12652d576b1272b8f39857e3e0b3fc26 @@ -73,8 +82,8 @@ GEM zeitwerk (~> 2.3) acts-as-taggable-on (9.0.1) activerecord (>= 6.0, < 7.1) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) administrate (0.17.0) actionpack (>= 5.0) actionview (>= 5.0) @@ -360,7 +369,7 @@ GEM hana (~> 1.3) regexp_parser (~> 2.0) uri_template (~> 0.7) - jwt (2.4.1) + jwt (2.5.0) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -426,6 +435,14 @@ GEM multipart-post (2.2.3) net-http-persistent (4.0.1) connection_pool (~> 2.2) + net-imap (0.3.1) + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol netrc (0.11.0) newrelic_rpm (8.9.0) nio4r (2.5.8) @@ -469,7 +486,7 @@ GEM method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.7) + public_suffix (5.0.1) puma (5.6.4) nio4r (~> 2.0) pundit (2.2.0) @@ -662,6 +679,7 @@ GEM time_diff (0.3.0) activesupport i18n + timeout (0.3.1) trailblazer-option (0.1.2) twilio-ruby (5.68.0) faraday (>= 0.9, < 3.0) @@ -693,7 +711,7 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webmock (3.14.0) + webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -702,9 +720,6 @@ GEM rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) - webpush (1.1.0) - hkdf (~> 0.2) - jwt (~> 2.0) webrick (1.7.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) @@ -779,6 +794,9 @@ DEPENDENCIES listen maxminddb mock_redis + net-imap + net-pop + net-smtp newrelic_rpm omniauth-oauth2 pg @@ -826,12 +844,12 @@ DEPENDENCIES web-console webmock webpacker (~> 5.4, >= 5.4.3) - webpush + webpush! wisper (= 2.0.0) working_hours RUBY VERSION - ruby 3.0.4p208 + ruby 3.1.3p185 BUNDLED WITH - 2.3.16 + 2.3.26 diff --git a/app/controllers/concerns/switch_locale.rb b/app/controllers/concerns/switch_locale.rb index 5f308b8abb5ca..744a70da9485d 100644 --- a/app/controllers/concerns/switch_locale.rb +++ b/app/controllers/concerns/switch_locale.rb @@ -3,25 +3,25 @@ module SwitchLocale private - def switch_locale(&action) + def switch_locale(&) # priority is for locale set in query string (mostly for widget/from js sdk) locale ||= locale_from_params # if locale is not set in account, let's use DEFAULT_LOCALE env variable locale ||= locale_from_env_variable - set_locale(locale, &action) + set_locale(locale, &) end - def switch_locale_using_account_locale(&action) + def switch_locale_using_account_locale(&) locale = locale_from_account(@current_account) - set_locale(locale, &action) + set_locale(locale, &) end - def set_locale(locale, &action) + def set_locale(locale, &) # if locale is empty, use default_locale locale ||= I18n.default_locale # Ensure locale won't bleed into other requests # https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests - I18n.with_locale(locale, &action) + I18n.with_locale(locale, &) end def locale_from_params diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 58f12e4b5a887..18fd2b83ec6fd 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -69,11 +69,11 @@ def ensure_current_account(account) Current.account = account if account.present? end - def switch_locale(&action) + def switch_locale(&) locale ||= locale_from_account(Current.account) locale ||= I18n.default_locale # ensure locale won't bleed into other requests # https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests - I18n.with_locale(locale, &action) + I18n.with_locale(locale, &) end end diff --git a/app/models/dashboard_app.rb b/app/models/dashboard_app.rb index c8558fb4ca138..7316dd344fbc4 100644 --- a/app/models/dashboard_app.rb +++ b/app/models/dashboard_app.rb @@ -33,7 +33,7 @@ def validate_content 'required' => %w[url type], 'properties' => { 'type' => { 'enum': ['frame'] }, - 'url' => { 'type': 'string', 'format' => 'uri' } + 'url' => { :type => 'string', 'format' => 'uri' } } }, 'additionalProperties' => false, diff --git a/app/services/whatsapp/providers/whatsapp_cloud_service.rb b/app/services/whatsapp/providers/whatsapp_cloud_service.rb index a0c5917830bd4..8ca1a9672960a 100644 --- a/app/services/whatsapp/providers/whatsapp_cloud_service.rb +++ b/app/services/whatsapp/providers/whatsapp_cloud_service.rb @@ -78,7 +78,7 @@ def send_attachment_message(phone_number, message) "#{phone_id_path}/messages", headers: api_headers, body: { - messaging_product: 'whatsapp', + :messaging_product => 'whatsapp', 'to' => phone_number, 'type' => type, type.to_s => type_content diff --git a/deployment/chatwoot-web.1.service b/deployment/chatwoot-web.1.service index 15d70e1bf3835..d3650b977f430 100644 --- a/deployment/chatwoot-web.1.service +++ b/deployment/chatwoot-web.1.service @@ -16,10 +16,10 @@ KillMode=mixed StandardInput=null SyslogIdentifier=%p -Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4/bin:/home/chatwoot/.rvm/gems/ruby-3.0.4@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.0.4/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin" +Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3/bin:/home/chatwoot/.rvm/gems/ruby-3.1.3@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.1.3/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin" Environment="PORT=3000" Environment="RAILS_ENV=production" Environment="NODE_ENV=production" Environment="RAILS_LOG_TO_STDOUT=true" -Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.0.4" -Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4:/home/chatwoot/.rvm/gems/ruby-3.0.4@global" +Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.1.3" +Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3:/home/chatwoot/.rvm/gems/ruby-3.1.3@global" diff --git a/deployment/chatwoot-worker.1.service b/deployment/chatwoot-worker.1.service index b3f8804ce0b9c..5d4ac95126092 100644 --- a/deployment/chatwoot-worker.1.service +++ b/deployment/chatwoot-worker.1.service @@ -16,10 +16,10 @@ KillMode=mixed StandardInput=null SyslogIdentifier=%p -Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4/bin:/home/chatwoot/.rvm/gems/ruby-3.0.4@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.0.4/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin" +Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3/bin:/home/chatwoot/.rvm/gems/ruby-3.1.3@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.1.3/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin" Environment="PORT=3000" Environment="RAILS_ENV=production" Environment="NODE_ENV=production" Environment="RAILS_LOG_TO_STDOUT=true" -Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.0.4" -Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4:/home/chatwoot/.rvm/gems/ruby-3.0.4@global" +Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.1.3" +Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3:/home/chatwoot/.rvm/gems/ruby-3.1.3@global" diff --git a/deployment/setup_20.04.sh b/deployment/setup_20.04.sh index 29b742bbfa98f..82f4aca40b26c 100644 --- a/deployment/setup_20.04.sh +++ b/deployment/setup_20.04.sh @@ -172,7 +172,7 @@ EOF function install_dependencies() { apt update && apt upgrade -y apt install -y curl - curl -sL https://deb.nodesource.com/setup_14.x | bash - + curl -sL https://deb.nodesource.com/setup_16.x | bash - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list apt update @@ -328,8 +328,8 @@ function setup_chatwoot() { sudo -i -u chatwoot << EOF rvm --version rvm autolibs disable - rvm install "ruby-3.0.4" - rvm use 3.0.4 --default + rvm install "ruby-3.1.3" + rvm use 3.1.3 --default git clone https://github.com/chatwoot/chatwoot.git cd chatwoot diff --git a/docker/Dockerfile b/docker/Dockerfile index ca689a38b9b61..aaa48b5a9852e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # pre-build stage -FROM ruby:3.0.4-alpine AS pre-builder +FROM ruby:3.1.3-alpine3.16 AS pre-builder # ARG default to production settings # For development docker-compose file overrides ARGS @@ -61,11 +61,12 @@ RUN if [ "$RAILS_ENV" = "production" ]; then \ fi # Remove unnecessary files -RUN rm -rf /gems/ruby/3.0.0/cache/*.gem \ - && find /gems/ruby/3.0.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete +RUN rm -rf /gems/ruby/3.1.0/cache/*.gem \ + && find /gems/ruby/3.1.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete # final build stage -FROM ruby:3.0.4-alpine +FROM ruby:3.1.3-alpine3.16 + ARG BUNDLE_WITHOUT="development:test" ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT} diff --git a/spec/controllers/api/v1/accounts/macros_controller_spec.rb b/spec/controllers/api/v1/accounts/macros_controller_spec.rb index 77229afaad528..7fbe6b54ecbe8 100644 --- a/spec/controllers/api/v1/accounts/macros_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/macros_controller_spec.rb @@ -278,7 +278,7 @@ { 'action_name' => 'snooze_conversation' }, { 'action_name' => 'assign_agent', 'action_params' => [user_1.id] }, { 'action_name' => 'send_message', 'action_params' => ['Send this message.'] }, - { 'action_name' => 'add_private_note', 'action_params': ['We are sending greeting message to customer.'] } + { 'action_name' => 'add_private_note', :action_params => ['We are sending greeting message to customer.'] } ]) end diff --git a/spec/factories/twitter/twitter_message_create_event.rb b/spec/factories/twitter/twitter_message_create_event.rb index 35cd735cd5f0b..79c7bd6932b2d 100644 --- a/spec/factories/twitter/twitter_message_create_event.rb +++ b/spec/factories/twitter/twitter_message_create_event.rb @@ -8,7 +8,7 @@ 'type' => 'message_create', 'id' => '123', 'message_create' => { - target: { 'recipient_id' => '1' }, + :target => { 'recipient_id' => '1' }, 'sender_id' => '2', 'source_app_id' => '268278', 'message_data' => { diff --git a/spec/jobs/webhooks/line_events_job_spec.rb b/spec/jobs/webhooks/line_events_job_spec.rb index 10da5602a81c1..e8d69939ef254 100644 --- a/spec/jobs/webhooks/line_events_job_spec.rb +++ b/spec/jobs/webhooks/line_events_job_spec.rb @@ -4,7 +4,7 @@ subject(:job) { described_class.perform_later(params: params) } let!(:line_channel) { create(:channel_line) } - let!(:params) { { line_channel_id: line_channel.line_channel_id, 'line' => { test: 'test' } } } + let!(:params) { { :line_channel_id => line_channel.line_channel_id, 'line' => { test: 'test' } } } let(:post_body) { params.to_json } let(:signature) { Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), line_channel.line_channel_secret, post_body)) } diff --git a/spec/jobs/webhooks/telegram_events_job_spec.rb b/spec/jobs/webhooks/telegram_events_job_spec.rb index 9f45955e6d6f0..815b7e9dc6529 100644 --- a/spec/jobs/webhooks/telegram_events_job_spec.rb +++ b/spec/jobs/webhooks/telegram_events_job_spec.rb @@ -4,7 +4,7 @@ subject(:job) { described_class.perform_later(params) } let!(:telegram_channel) { create(:channel_telegram) } - let!(:params) { { bot_token: telegram_channel.bot_token, 'telegram' => { test: 'test' } } } + let!(:params) { { :bot_token => telegram_channel.bot_token, 'telegram' => { test: 'test' } } } it 'enqueues the job' do expect { job }.to have_enqueued_job(described_class) diff --git a/spec/services/whatsapp/incoming_message_service_spec.rb b/spec/services/whatsapp/incoming_message_service_spec.rb index a6734f32dc282..c2f90dd36dd3d 100644 --- a/spec/services/whatsapp/incoming_message_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_service_spec.rb @@ -63,8 +63,8 @@ 'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }], 'messages' => [{ 'errors' => [{ 'code': 131_051, 'title': 'Message type is currently not supported.' }], - 'from': '2423423243', 'id': 'wamid.SDFADSf23sfasdafasdfa', - 'timestamp': '1667047370', 'type': 'unsupported' + :from => '2423423243', :id => 'wamid.SDFADSf23sfasdafasdfa', + :timestamp => '1667047370', :type => 'unsupported' }] }.with_indifferent_access @@ -131,7 +131,7 @@ params = { 'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }], 'messages' => [{ 'from' => '2423423243', 'id' => 'SDFADSf23sfasdafasdfa', - 'interactive': { + :interactive => { 'button_reply': { 'id': '1', 'title': 'First Button' @@ -195,11 +195,11 @@ 'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }], 'messages' => [{ 'from' => '2423423243', 'id' => 'SDFADSf23sfasdafasdfa', 'location' => { 'id' => 'b1c68f38-8734-4ad3-b4a1-ef0c10d683', - 'address': 'San Francisco, CA, USA', - 'latitude': 37.7893768, - 'longitude': -122.3895553, - 'name': 'Bay Bridge', - 'url': 'http://location_url.test' }, + :address => 'San Francisco, CA, USA', + :latitude => 37.7893768, + :longitude => -122.3895553, + :name => 'Bay Bridge', + :url => 'http://location_url.test' }, 'timestamp' => '1633034394', 'type' => 'location' }] }.with_indifferent_access described_class.new(inbox: whatsapp_channel.inbox, params: params).perform diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e375bb8eee4d8..3c275aeb46a8b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,7 @@ config.shared_context_metadata_behavior = :apply_to_host_groups - def with_modified_env(options, &block) - ClimateControl.modify(options, &block) + def with_modified_env(options, &) + ClimateControl.modify(options, &) end end