diff --git a/Gemfile b/Gemfile index 6a35ddb47..0f285c6fd 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,7 @@ gem 'activerecord-import' gem 'dotenv-rails' gem 'foreman' gem 'puma' +gem 'rack-timeout' gem 'webpacker', '~> 5.x' # metrics on heroku gem 'barnes' diff --git a/Gemfile.lock b/Gemfile.lock index 6b9508907..86d421fa7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -384,6 +384,7 @@ GEM rack rack-test (1.1.0) rack (>= 1.0, < 3) + rack-timeout (0.6.0) rails (6.0.3.7) actioncable (= 6.0.3.7) actionmailbox (= 6.0.3.7) @@ -666,6 +667,7 @@ DEPENDENCIES puma pundit rack-cors + rack-timeout rails redis redis-namespace diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index 8791da5b9..06f219e27 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -73,6 +73,8 @@ class ConversationFinder @conversations = @conversations.assigned_to(current_user) when 'unassigned' @conversations = @conversations.unassigned + when 'assigned' + @conversations = @conversations.where.not(assignee_id: nil) end @conversations end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index f76e4a409..3a183f0a9 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -3,11 +3,11 @@ require Rails.root.join('lib/redis/config') schedule_file = 'config/schedule.yml' Sidekiq.configure_client do |config| - config.redis = Redis::Config.sidekiq + config.redis = Redis::Config.app end Sidekiq.configure_server do |config| - config.redis = Redis::Config.sidekiq + config.redis = Redis::Config.app end # https://github.com/ondrejbartas/sidekiq-cron diff --git a/config/schedule.yml b/config/schedule.yml index 6859713fa..5dd27afc3 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -11,4 +11,5 @@ internal_check_new_versions_job: internal_check_new_versions_job: cron: "*/5 * * * *" class: "TriggerScheduledItemsJob" - queue: scheduled_jobs \ No newline at end of file + queue: scheduled_jobs + \ No newline at end of file diff --git a/lib/redis/config.rb b/lib/redis/config.rb index f6027d1f6..6e286f142 100644 --- a/lib/redis/config.rb +++ b/lib/redis/config.rb @@ -1,16 +1,10 @@ module Redis::Config DEFAULT_SENTINEL_PORT ||= '26379'.freeze - SIDEKIQ_SIZE ||= 25 - class << self def app config end - def sidekiq - app.merge(size: SIDEKIQ_SIZE) - end - def config @config ||= sentinel? ? sentinel_config : base_config end diff --git a/spec/finders/conversation_finder_spec.rb b/spec/finders/conversation_finder_spec.rb index d10aa1e1d..d92b3b0a9 100644 --- a/spec/finders/conversation_finder_spec.rb +++ b/spec/finders/conversation_finder_spec.rb @@ -6,7 +6,7 @@ describe ::ConversationFinder do let!(:account) { create(:account) } let!(:user_1) { create(:user, account: account) } let!(:user_2) { create(:user, account: account) } - let!(:inbox) { create(:inbox, account: account) } + let!(:inbox) { create(:inbox, account: account, enable_auto_assignment: false) } before do create(:inbox_member, user: user_1, inbox: inbox) @@ -15,6 +15,8 @@ describe ::ConversationFinder do create(:conversation, account: account, inbox: inbox, assignee: user_1) create(:conversation, account: account, inbox: inbox, assignee: user_1, status: 'resolved') create(:conversation, account: account, inbox: inbox, assignee: user_2) + # unassigned conversation + create(:conversation, account: account, inbox: inbox) Current.account = account end @@ -28,10 +30,28 @@ describe ::ConversationFinder do end end - context 'with assignee' do + context 'with assignee_type all' do let(:params) { { assignee_type: 'all' } } - it 'filter conversations by assignee' do + it 'filter conversations by assignee type all' do + result = conversation_finder.perform + expect(result[:conversations].count).to be 4 + end + end + + context 'with assignee_type unassigned' do + let(:params) { { assignee_type: 'unassigned' } } + + it 'filter conversations by assignee type unassigned' do + result = conversation_finder.perform + expect(result[:conversations].count).to be 1 + end + end + + context 'with assignee_type assigned' do + let(:params) { { assignee_type: 'assigned' } } + + it 'filter conversations by assignee type assigned' do result = conversation_finder.perform expect(result[:conversations].count).to be 3 end diff --git a/spec/lib/redis/config_spec.rb b/spec/lib/redis/config_spec.rb index 2b919696f..a82065328 100644 --- a/spec/lib/redis/config_spec.rb +++ b/spec/lib/redis/config_spec.rb @@ -20,14 +20,6 @@ describe ::Redis::Config do expect(app_config[:url]).to eq(redis_url) expect(app_config[:password]).to eq(redis_pasword) end - - it 'checks for sidekiq redis config' do - sidekiq_config = described_class.sidekiq - expect(sidekiq_config.keys).to match_array([:url, :password, :size, :network_timeout, :reconnect_attempts]) - expect(sidekiq_config[:url]).to eq redis_url - expect(sidekiq_config[:password]).to eq redis_pasword - expect(sidekiq_config[:size]).to eq described_class::SIDEKIQ_SIZE - end end context 'when redis sentinel is used' do @@ -58,10 +50,5 @@ describe ::Redis::Config do expect(described_class.app[:url]).to eq("redis://#{redis_master_name}") expect(described_class.app[:sentinels]).to match_array(expected_sentinels) end - - it 'checks for sidekiq redis config' do - expect(described_class.sidekiq.keys).to match_array([:url, :password, :sentinels, :size, :network_timeout, :reconnect_attempts]) - expect(described_class.sidekiq[:size]).to eq described_class::SIDEKIQ_SIZE - end end end diff --git a/swagger/paths/conversation/create.yml b/swagger/paths/conversation/create.yml new file mode 100644 index 000000000..e13d17cfb --- /dev/null +++ b/swagger/paths/conversation/create.yml @@ -0,0 +1,41 @@ +get: + tags: + - Conversation + operationId: conversationList + description: List all the conversations with pagination + summary: Conversations List + parameters: + - $ref: '#/parameters/account_id' + - name: assignee_type + in: query + type: string + enum: ['me', 'unassigned', 'all', 'assigned'] + required: true + - name: status + in: query + type: string + enum: ['open', 'resolved', 'bot'] + required: true + - name: page + in: query + type: integer + required: true + - name: inbox_id + in: query + type: integer + - name: labels + in: query + type: array + items: + type: string + + responses: + 200: + description: Success + schema: + $ref: '#/definitions/conversation_list' + 400: + description: Bad Request Error + schema: + $ref: '#/definitions/bad_request_error' + description: Access denied \ No newline at end of file diff --git a/swagger/paths/conversation/index_or_create.yml b/swagger/paths/conversation/index.yml similarity index 72% rename from swagger/paths/conversation/index_or_create.yml rename to swagger/paths/conversation/index.yml index b553b02f5..35707b65a 100644 --- a/swagger/paths/conversation/index_or_create.yml +++ b/swagger/paths/conversation/index.yml @@ -1,45 +1,3 @@ -get: - tags: - - Conversation - operationId: conversationList - description: List all the conversations with pagination - summary: Conversations List - parameters: - - $ref: '#/parameters/account_id' - - name: assignee_type - in: query - type: string - enum: ['me', 'unassigned', 'all'] - required: true - - name: status - in: query - type: string - enum: ['open', 'resolved', 'bot'] - required: true - - name: page - in: query - type: integer - required: true - - name: inbox_id - in: query - type: integer - - name: labels - in: query - type: array - items: - type: string - - responses: - 200: - description: Success - schema: - $ref: '#/definitions/conversation_list' - 400: - description: Bad Request Error - schema: - $ref: '#/definitions/bad_request_error' - description: Access denied - get: tags: - Conversation @@ -53,7 +11,7 @@ get: - name: assignee_type in: query type: string - enum: ['me', 'unassigned', 'all'] + enum: ['me', 'unassigned', 'all', 'assigned'] - name: status in: query type: string diff --git a/swagger/paths/index.yml b/swagger/paths/index.yml index 0d3791fa9..b0b27f27f 100644 --- a/swagger/paths/index.yml +++ b/swagger/paths/index.yml @@ -156,7 +156,11 @@ public/api/v1/inboxes/{inbox_identifier}/contacts/{contact_identifier}/conversat /api/v1/accounts/{account_id}/conversations: parameters: - $ref: '#/parameters/account_id' - $ref: ./conversation/index_or_create.yml + $ref: ./conversation/index.yml +/api/v1/accounts/{account_id}/conversations/: + parameters: + - $ref: '#/parameters/account_id' + $ref: ./conversation/create.yml /api/v1/accounts/{account_id}/conversations/{converstion_id}: parameters: - $ref: '#/parameters/account_id' diff --git a/swagger/swagger.json b/swagger/swagger.json index 8ad079bd0..561a1bd66 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -1406,7 +1406,8 @@ "enum": [ "me", "unassigned", - "all" + "all", + "assigned" ] }, { @@ -1542,6 +1543,78 @@ } } }, + "/api/v1/accounts/{account_id}/conversations/": { + "get": { + "tags": [ + "Conversation" + ], + "operationId": "conversationList", + "description": "List all the conversations with pagination", + "summary": "Conversations List", + "parameters": [ + { + "$ref": "#/parameters/account_id" + }, + { + "name": "assignee_type", + "in": "query", + "type": "string", + "enum": [ + "me", + "unassigned", + "all", + "assigned" + ], + "required": true + }, + { + "name": "status", + "in": "query", + "type": "string", + "enum": [ + "open", + "resolved", + "bot" + ], + "required": true + }, + { + "name": "page", + "in": "query", + "type": "integer", + "required": true + }, + { + "name": "inbox_id", + "in": "query", + "type": "integer" + }, + { + "name": "labels", + "in": "query", + "type": "array", + "items": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/conversation_list" + } + }, + "400": { + "description": "Bad Request Error", + "schema": { + "$ref": "#/definitions/bad_request_error" + } + }, + "description": "Access denied" + } + } + }, "/api/v1/accounts/{account_id}/conversations/{converstion_id}": { "parameters": [ {