Skip to content

Commit

Permalink
chore: Add assigned option to conversation finder API (#2630)
Browse files Browse the repository at this point in the history
- Adds the ability to filter all the conversations which are assigned
- Add rack timeout gem
- Remove size attribute from Sidekiq config
  • Loading branch information
sojan-official committed Jul 14, 2021
1 parent 3d18ec9 commit d7982a6
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 70 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -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)
Expand Down Expand Up @@ -666,6 +667,7 @@ DEPENDENCIES
puma
pundit
rack-cors
rack-timeout
rails
redis
redis-namespace
Expand Down
2 changes: 2 additions & 0 deletions app/finders/conversation_finder.rb
Expand Up @@ -73,6 +73,8 @@ def filter_by_assignee_type
@conversations = @conversations.assigned_to(current_user)
when 'unassigned'
@conversations = @conversations.unassigned
when 'assigned'
@conversations = @conversations.where.not(assignee_id: nil)
end
@conversations
end
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/sidekiq.rb
Expand Up @@ -3,11 +3,11 @@
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
Expand Down
3 changes: 2 additions & 1 deletion config/schedule.yml
Expand Up @@ -11,4 +11,5 @@ internal_check_new_versions_job:
internal_check_new_versions_job:
cron: "*/5 * * * *"
class: "TriggerScheduledItemsJob"
queue: scheduled_jobs
queue: scheduled_jobs

6 changes: 0 additions & 6 deletions 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
Expand Down
26 changes: 23 additions & 3 deletions spec/finders/conversation_finder_spec.rb
Expand Up @@ -6,7 +6,7 @@
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)
Expand All @@ -15,6 +15,8 @@
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

Expand All @@ -28,10 +30,28 @@
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
Expand Down
13 changes: 0 additions & 13 deletions spec/lib/redis/config_spec.rb
Expand Up @@ -20,14 +20,6 @@
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
Expand Down Expand Up @@ -58,10 +50,5 @@
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
41 changes: 41 additions & 0 deletions 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
@@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion swagger/paths/index.yml
Expand Up @@ -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'
Expand Down
75 changes: 74 additions & 1 deletion swagger/swagger.json
Expand Up @@ -1406,7 +1406,8 @@
"enum": [
"me",
"unassigned",
"all"
"all",
"assigned"
]
},
{
Expand Down Expand Up @@ -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": [
{
Expand Down

0 comments on commit d7982a6

Please sign in to comment.