From 743bddc0657c800ca5b932ba405fa70e3291cb46 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Thu, 16 Apr 2020 15:05:01 +0530 Subject: [PATCH] Chore: Housekeeping tasks (#721) - End point to return api version - Move agent bot listener to sync dispatcher - gem update --- Gemfile.lock | 32 ++++++++++++------------- app/controllers/api_controller.rb | 8 +++++++ app/dispatchers/async_dispatcher.rb | 2 +- app/dispatchers/sync_dispatcher.rb | 2 +- config/app.yml | 14 +++++++++++ config/application.rb | 7 ++++++ config/routes.rb | 1 + spec/controllers/api_controller_spec.rb | 11 +++++++++ 8 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 app/controllers/api_controller.rb create mode 100644 config/app.yml create mode 100644 spec/controllers/api_controller_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 0ad798ef4..6c9edc7ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,10 +82,10 @@ GEM rake (>= 10.4, < 14.0) ast (2.4.0) attr_extras (6.2.3) - aws-eventstream (1.0.3) - aws-partitions (1.294.0) - aws-sdk-core (3.92.0) - aws-eventstream (~> 1.0, >= 1.0.2) + aws-eventstream (1.1.0) + aws-partitions (1.296.0) + aws-sdk-core (3.94.0) + aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) @@ -113,7 +113,7 @@ GEM bindex (0.8.1) bootsnap (1.4.6) msgpack (~> 1.0) - brakeman (4.8.0) + brakeman (4.8.1) browser (4.0.0) builder (3.2.4) bullet (6.1.0) @@ -179,7 +179,7 @@ GEM foreman (0.87.1) globalid (0.4.2) activesupport (>= 4.2.0) - google-api-client (0.37.2) + google-api-client (0.38.0) addressable (~> 2.5, >= 2.5.1) googleauth (~> 0.9) httpclient (>= 2.8.1, < 3.0) @@ -193,20 +193,20 @@ GEM google-cloud-env (1.3.1) faraday (>= 0.17.3, < 2.0) google-cloud-errors (1.0.0) - google-cloud-storage (1.25.1) + google-cloud-storage (1.26.0) addressable (~> 2.5) digest-crc (~> 0.4) google-api-client (~> 0.33) google-cloud-core (~> 1.2) googleauth (~> 0.9) mini_mime (~> 1.0) - googleauth (0.11.0) + googleauth (0.12.0) faraday (>= 0.17.3, < 2.0) jwt (>= 1.4, < 3.0) memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) - signet (~> 0.12) + signet (~> 0.14) groupdate (5.0.0) activesupport (>= 5) haikunator (1.1.0) @@ -253,7 +253,7 @@ GEM listen (3.2.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.4.0) + loofah (2.5.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -284,21 +284,21 @@ GEM orm_adapter (0.5.0) os (1.1.0) parallel (1.19.1) - parser (2.7.1.0) + parser (2.7.1.1) ast (~> 2.4.0) pg (1.2.3) - pry (0.13.0) + pry (0.13.1) coderay (~> 1.1) method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.3) + public_suffix (4.0.4) puma (4.3.3) nio4r (~> 2.0) pundit (2.1.0) activesupport (>= 3.0.0) rack (2.2.2) - rack-cache (1.11.0) + rack-cache (1.11.1) rack (>= 0.4) rack-cors (1.1.1) rack (>= 2.0.0) @@ -388,7 +388,7 @@ GEM unicode-display_width (>= 1.4.0, < 2.0) rubocop-performance (1.5.2) rubocop (>= 0.71.0) - rubocop-rails (2.5.1) + rubocop-rails (2.5.2) activesupport rack (>= 1.1) rubocop (>= 0.72.0) @@ -463,7 +463,7 @@ GEM unf_ext (0.0.7.7) unicode-display_width (1.7.0) uniform_notifier (1.13.0) - valid_email2 (3.2.1) + valid_email2 (3.2.2) activemodel (>= 3.2) mail (~> 2.5) virtus (1.0.5) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb new file mode 100644 index 000000000..3d7f59f0c --- /dev/null +++ b/app/controllers/api_controller.rb @@ -0,0 +1,8 @@ +class ApiController < ApplicationController + skip_before_action :set_current_user, only: [:index] + skip_before_action :check_subscription, only: [:index] + + def index + render json: { version: Chatwoot.config[:version], timestamp: Time.now.utc.to_formatted_s(:db) } + end +end diff --git a/app/dispatchers/async_dispatcher.rb b/app/dispatchers/async_dispatcher.rb index 65569c1b0..72e44a1c2 100644 --- a/app/dispatchers/async_dispatcher.rb +++ b/app/dispatchers/async_dispatcher.rb @@ -9,7 +9,7 @@ class AsyncDispatcher < BaseDispatcher end def listeners - listeners = [AgentBotListener.instance, EmailNotificationListener.instance, ReportingListener.instance, WebhookListener.instance] + listeners = [EmailNotificationListener.instance, ReportingListener.instance, WebhookListener.instance] listeners << EventListener.instance listeners << SubscriptionListener.instance if ENV['BILLING_ENABLED'] listeners diff --git a/app/dispatchers/sync_dispatcher.rb b/app/dispatchers/sync_dispatcher.rb index e3bad28a1..509a42727 100644 --- a/app/dispatchers/sync_dispatcher.rb +++ b/app/dispatchers/sync_dispatcher.rb @@ -5,6 +5,6 @@ class SyncDispatcher < BaseDispatcher end def listeners - [ActionCableListener.instance] + [ActionCableListener.instance, AgentBotListener.instance] end end diff --git a/config/app.yml b/config/app.yml new file mode 100644 index 000000000..2fb8246aa --- /dev/null +++ b/config/app.yml @@ -0,0 +1,14 @@ +shared: &shared + version: '1.4.0' + +development: + <<: *shared + +production: + <<: *shared + +staging: + <<: *shared + +test: + <<: *shared \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index e336393d7..c7421cb4b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -30,5 +30,12 @@ module Chatwoot config.action_dispatch.default_headers = { 'X-Frame-Options' => 'ALLOWALL' } + + # Custom chatwoot configurations + config.x = config_for(:app).with_indifferent_access + end + + def self.config + @config ||= Rails.configuration.x end end diff --git a/config/routes.rb b/config/routes.rb index 8a9f0e568..a86f8b83a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ Rails.application.routes.draw do resource :widget, only: [:show] + get '/api', to: 'api#index' namespace :api, defaults: { format: 'json' } do namespace :v1 do # ---------------------------------- diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb new file mode 100644 index 000000000..b2948e28a --- /dev/null +++ b/spec/controllers/api_controller_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe 'API Base', type: :request do + describe 'request to api base url' do + it 'returns api version' do + get '/api/' + expect(response).to have_http_status(:success) + expect(response.body).to include(Chatwoot.config[:version]) + end + end +end