Fixed issue #1253 - Duplicates in Caller Log (Sipgate).
This commit is contained in:
parent
16e79bbf88
commit
83d11b122e
3 changed files with 130 additions and 30 deletions
|
@ -54,8 +54,10 @@ returns
|
||||||
search_params[:level] = level
|
search_params[:level] = level
|
||||||
end
|
end
|
||||||
|
|
||||||
result = Cti::CallerId.where(search_params).group(:user_id, :id).order(id: 'DESC').limit(20)
|
caller_ids = Cti::CallerId.select('MAX(id) as caller_id').where(search_params).group(:user_id).order('caller_id DESC').limit(20).map(&:caller_id)
|
||||||
|
Cti::CallerId.where(id: caller_ids).order(id: :desc).each { |record|
|
||||||
|
result.push record
|
||||||
|
}
|
||||||
break if result.present?
|
break if result.present?
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|
|
@ -266,7 +266,22 @@ returns
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# processes a incoming event
|
=begin
|
||||||
|
|
||||||
|
processes a incoming event
|
||||||
|
|
||||||
|
Cti::Log.process(
|
||||||
|
'cause' => '',
|
||||||
|
'event' => 'newCall',
|
||||||
|
'user' => 'user 1',
|
||||||
|
'from' => '4912347114711',
|
||||||
|
'to' => '4930600000000',
|
||||||
|
'callId' => '4991155921769858278-1',
|
||||||
|
'direction' => 'in',
|
||||||
|
)
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
def self.process(params)
|
def self.process(params)
|
||||||
comment = params['cause']
|
comment = params['cause']
|
||||||
event = params['event']
|
event = params['event']
|
||||||
|
|
|
@ -3,12 +3,12 @@ require 'test_helper'
|
||||||
|
|
||||||
class CtiCallerIdTest < ActiveSupport::TestCase
|
class CtiCallerIdTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test '2 lookups' do
|
setup do
|
||||||
|
|
||||||
Ticket.destroy_all
|
Ticket.destroy_all
|
||||||
Cti::CallerId.destroy_all
|
Cti::CallerId.destroy_all
|
||||||
|
|
||||||
agent1 = User.create_or_update(
|
@agent1 = User.create_or_update(
|
||||||
login: 'ticket-caller_id-agent1@example.com',
|
login: 'ticket-caller_id-agent1@example.com',
|
||||||
firstname: 'CallerId',
|
firstname: 'CallerId',
|
||||||
lastname: 'Agent1',
|
lastname: 'Agent1',
|
||||||
|
@ -22,7 +22,7 @@ class CtiCallerIdTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
agent2 = User.create_or_update(
|
@agent2 = User.create_or_update(
|
||||||
login: 'ticket-caller_id-agent2@example.com',
|
login: 'ticket-caller_id-agent2@example.com',
|
||||||
firstname: 'CallerId',
|
firstname: 'CallerId',
|
||||||
lastname: 'Agent2',
|
lastname: 'Agent2',
|
||||||
|
@ -34,7 +34,7 @@ class CtiCallerIdTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
agent3 = User.create_or_update(
|
@agent3 = User.create_or_update(
|
||||||
login: 'ticket-caller_id-agent3@example.com',
|
login: 'ticket-caller_id-agent3@example.com',
|
||||||
firstname: 'CallerId',
|
firstname: 'CallerId',
|
||||||
lastname: 'Agent3',
|
lastname: 'Agent3',
|
||||||
|
@ -46,7 +46,7 @@ class CtiCallerIdTest < ActiveSupport::TestCase
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
customer1 = User.create_or_update(
|
@customer1 = User.create_or_update(
|
||||||
login: 'ticket-caller_id-customer1@example.com',
|
login: 'ticket-caller_id-customer1@example.com',
|
||||||
firstname: 'CallerId',
|
firstname: 'CallerId',
|
||||||
lastname: 'Customer1',
|
lastname: 'Customer1',
|
||||||
|
@ -57,6 +57,10 @@ class CtiCallerIdTest < ActiveSupport::TestCase
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
test '1 lookups' do
|
||||||
|
|
||||||
Cti::CallerId.rebuild
|
Cti::CallerId.rebuild
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('491111222277')
|
caller_ids = Cti::CallerId.lookup('491111222277')
|
||||||
|
@ -64,27 +68,27 @@ class CtiCallerIdTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('491111222223')
|
caller_ids = Cti::CallerId.lookup('491111222223')
|
||||||
assert_equal(1, caller_ids.length)
|
assert_equal(1, caller_ids.length)
|
||||||
assert_equal(agent1.id, caller_ids[0].user_id)
|
assert_equal(@agent1.id, caller_ids[0].user_id)
|
||||||
assert_equal('known', caller_ids[0].level)
|
assert_equal('known', caller_ids[0].level)
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('492222222222')
|
caller_ids = Cti::CallerId.lookup('492222222222')
|
||||||
assert_equal(2, caller_ids.length)
|
assert_equal(2, caller_ids.length)
|
||||||
assert_equal(agent3.id, caller_ids[0].user_id)
|
assert_equal(@agent3.id, caller_ids[0].user_id)
|
||||||
assert_equal('known', caller_ids[0].level)
|
assert_equal('known', caller_ids[0].level)
|
||||||
assert_equal(agent2.id, caller_ids[1].user_id)
|
assert_equal(@agent2.id, caller_ids[1].user_id)
|
||||||
assert_equal('known', caller_ids[1].level)
|
assert_equal('known', caller_ids[1].level)
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
ticket1 = Ticket.create(
|
ticket1 = Ticket.create!(
|
||||||
title: 'some caller id test 1',
|
title: 'some caller id test 1',
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
customer: customer1,
|
customer: @customer1,
|
||||||
state: Ticket::State.lookup(name: 'new'),
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
updated_by_id: agent1.id,
|
updated_by_id: @agent1.id,
|
||||||
created_by_id: agent1.id,
|
created_by_id: @agent1.id,
|
||||||
)
|
)
|
||||||
article1 = Ticket::Article.create(
|
article1 = Ticket::Article.create!(
|
||||||
ticket_id: ticket1.id,
|
ticket_id: ticket1.id,
|
||||||
from: 'some_sender@example.com',
|
from: 'some_sender@example.com',
|
||||||
to: 'some_recipient@example.com',
|
to: 'some_recipient@example.com',
|
||||||
|
@ -96,22 +100,22 @@ Mob: +49 333 8362222",
|
||||||
internal: false,
|
internal: false,
|
||||||
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
||||||
type: Ticket::Article::Type.where(name: 'email').first,
|
type: Ticket::Article::Type.where(name: 'email').first,
|
||||||
updated_by_id: customer1.id,
|
updated_by_id: @customer1.id,
|
||||||
created_by_id: customer1.id,
|
created_by_id: @customer1.id,
|
||||||
)
|
)
|
||||||
assert(ticket1)
|
assert(ticket1)
|
||||||
|
|
||||||
# create ticket in group
|
# create ticket in group
|
||||||
ticket2 = Ticket.create(
|
ticket2 = Ticket.create!(
|
||||||
title: 'some caller id test 2',
|
title: 'some caller id test 2',
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
customer: customer1,
|
customer: @customer1,
|
||||||
state: Ticket::State.lookup(name: 'new'),
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
priority: Ticket::Priority.lookup(name: '2 normal'),
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
updated_by_id: agent1.id,
|
updated_by_id: @agent1.id,
|
||||||
created_by_id: agent1.id,
|
created_by_id: @agent1.id,
|
||||||
)
|
)
|
||||||
article2 = Ticket::Article.create(
|
article2 = Ticket::Article.create!(
|
||||||
ticket_id: ticket2.id,
|
ticket_id: ticket2.id,
|
||||||
from: 'some_sender@example.com',
|
from: 'some_sender@example.com',
|
||||||
to: 'some_recipient@example.com',
|
to: 'some_recipient@example.com',
|
||||||
|
@ -123,8 +127,8 @@ Mob: +49 333 1112222",
|
||||||
internal: false,
|
internal: false,
|
||||||
sender: Ticket::Article::Sender.where(name: 'Agent').first,
|
sender: Ticket::Article::Sender.where(name: 'Agent').first,
|
||||||
type: Ticket::Article::Type.where(name: 'email').first,
|
type: Ticket::Article::Type.where(name: 'email').first,
|
||||||
updated_by_id: agent1.id,
|
updated_by_id: @agent1.id,
|
||||||
created_by_id: agent1.id,
|
created_by_id: @agent1.id,
|
||||||
)
|
)
|
||||||
assert(ticket2)
|
assert(ticket2)
|
||||||
|
|
||||||
|
@ -135,19 +139,19 @@ Mob: +49 333 1112222",
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('491111222223')
|
caller_ids = Cti::CallerId.lookup('491111222223')
|
||||||
assert_equal(1, caller_ids.length)
|
assert_equal(1, caller_ids.length)
|
||||||
assert_equal(agent1.id, caller_ids[0].user_id)
|
assert_equal(@agent1.id, caller_ids[0].user_id)
|
||||||
assert_equal('known', caller_ids[0].level)
|
assert_equal('known', caller_ids[0].level)
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('492222222222')
|
caller_ids = Cti::CallerId.lookup('492222222222')
|
||||||
assert_equal(2, caller_ids.length)
|
assert_equal(2, caller_ids.length)
|
||||||
assert_equal(agent3.id, caller_ids[0].user_id)
|
assert_equal(@agent3.id, caller_ids[0].user_id)
|
||||||
assert_equal('known', caller_ids[0].level)
|
assert_equal('known', caller_ids[0].level)
|
||||||
assert_equal(agent2.id, caller_ids[1].user_id)
|
assert_equal(@agent2.id, caller_ids[1].user_id)
|
||||||
assert_equal('known', caller_ids[1].level)
|
assert_equal('known', caller_ids[1].level)
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('492226112222')
|
caller_ids = Cti::CallerId.lookup('492226112222')
|
||||||
assert_equal(1, caller_ids.length)
|
assert_equal(1, caller_ids.length)
|
||||||
assert_equal(customer1.id, caller_ids[0].user_id)
|
assert_equal(@customer1.id, caller_ids[0].user_id)
|
||||||
assert_equal('maybe', caller_ids[0].level)
|
assert_equal('maybe', caller_ids[0].level)
|
||||||
|
|
||||||
caller_ids = Cti::CallerId.lookup('492221112222')
|
caller_ids = Cti::CallerId.lookup('492221112222')
|
||||||
|
@ -155,7 +159,7 @@ Mob: +49 333 1112222",
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test '3 lookups' do
|
test '2 lookups' do
|
||||||
|
|
||||||
Cti::CallerId.destroy_all
|
Cti::CallerId.destroy_all
|
||||||
|
|
||||||
|
@ -244,4 +248,83 @@ Mob: +49 333 1112222",
|
||||||
assert_nil(caller_ids[0].comment)
|
assert_nil(caller_ids[0].comment)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test '3 process - log' do
|
||||||
|
|
||||||
|
ticket1 = Ticket.create!(
|
||||||
|
title: 'some caller id test 1',
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer: @customer1,
|
||||||
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
|
updated_by_id: @agent1.id,
|
||||||
|
created_by_id: @agent1.id,
|
||||||
|
)
|
||||||
|
article1 = Ticket::Article.create!(
|
||||||
|
ticket_id: ticket1.id,
|
||||||
|
from: 'some_sender@example.com',
|
||||||
|
to: 'some_recipient@example.com',
|
||||||
|
subject: 'some subject',
|
||||||
|
message_id: 'some@id',
|
||||||
|
body: "some message\nFon (GEL): +49 111 366-1111 Mi-Fr
|
||||||
|
Fon (LIN): +49 222 6112222 Mo-Di
|
||||||
|
Mob: +49 333 8362222",
|
||||||
|
internal: false,
|
||||||
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
||||||
|
type: Ticket::Article::Type.where(name: 'email').first,
|
||||||
|
updated_by_id: @customer1.id,
|
||||||
|
created_by_id: @customer1.id,
|
||||||
|
)
|
||||||
|
assert(ticket1)
|
||||||
|
ticket2 = Ticket.create!(
|
||||||
|
title: 'some caller id test 2',
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer: @customer1,
|
||||||
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
|
updated_by_id: @agent1.id,
|
||||||
|
created_by_id: @agent1.id,
|
||||||
|
)
|
||||||
|
article2 = Ticket::Article.create!(
|
||||||
|
ticket_id: ticket2.id,
|
||||||
|
from: 'some_sender@example.com',
|
||||||
|
to: 'some_recipient@example.com',
|
||||||
|
subject: 'some subject',
|
||||||
|
message_id: 'some@id',
|
||||||
|
body: "some message\nFon (GEL): +49 111 366-1111 Mi-Fr
|
||||||
|
Fon (LIN): +49 222 6112222 Mo-Di
|
||||||
|
Mob: +49 333 8362222",
|
||||||
|
internal: false,
|
||||||
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
||||||
|
type: Ticket::Article::Type.where(name: 'email').first,
|
||||||
|
updated_by_id: @customer1.id,
|
||||||
|
created_by_id: @customer1.id,
|
||||||
|
)
|
||||||
|
assert(ticket2)
|
||||||
|
|
||||||
|
Cti::CallerId.rebuild
|
||||||
|
|
||||||
|
Cti::Log.process(
|
||||||
|
'cause' => '',
|
||||||
|
'event' => 'newCall',
|
||||||
|
'user' => 'user 1',
|
||||||
|
'from' => '491113661111',
|
||||||
|
'to' => '4930600000000',
|
||||||
|
'callId' => '4991155921769858278-1',
|
||||||
|
'direction' => 'in',
|
||||||
|
)
|
||||||
|
|
||||||
|
log = Cti::Log.log
|
||||||
|
assert(log[:list])
|
||||||
|
assert(log[:assets])
|
||||||
|
assert(log[:list][0])
|
||||||
|
assert_not(log[:list][1])
|
||||||
|
assert(log[:list][0].preferences)
|
||||||
|
assert(log[:list][0].preferences[:from])
|
||||||
|
assert_equal(1, log[:list][0].preferences[:from].count)
|
||||||
|
assert_equal(@customer1.id, log[:list][0].preferences[:from][0][:user_id])
|
||||||
|
assert_equal('maybe', log[:list][0].preferences[:from][0][:level])
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue