From a8642d3ed0f6603155180bb5a99fa116b5c9b22d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 17 Aug 2018 16:12:28 +0200 Subject: [PATCH] Follow up for issue #2193 - re-enabled shown anonymous if no caller is exists. Fixed triggering event of new/changed caller log items. --- .../app/views/cti/caller_log.jst.eco | 24 ++++++--- app/models/cti/log.rb | 27 ++++------ .../integration_cti_controller_test.rb | 51 ++++++++++++++----- test/unit/cti_caller_id_test.rb | 42 ++++++++++++++- 4 files changed, 104 insertions(+), 40 deletions(-) diff --git a/app/assets/javascripts/app/views/cti/caller_log.jst.eco b/app/assets/javascripts/app/views/cti/caller_log.jst.eco index 6265567d9..ddd2d8128 100644 --- a/app/assets/javascripts/app/views/cti/caller_log.jst.eco +++ b/app/assets/javascripts/app/views/cti/caller_log.jst.eco @@ -30,21 +30,25 @@ <% classes.push('is-inactive') if !user.active %> <% if caller_id.level isnt 'known': %><%- @T('maybe') %> <% end %> <%= user.displayNameLong() %>
- <% else if caller_id.comment: %> + <% else if !_.isEmpty(caller_id.comment): %> <% shown = true %> <%- @T('maybe') %> <%= caller_id.comment %>
<% end %> <% end %> <% end %> - <% if !shown && item.from_comment: %> + <% if !shown && !_.isEmpty(item.from_comment): %> <% shown = true %> - <% if item.from_comment: %><%= item.from_comment %><% end %> + <%= item.from_comment %>
<% end %> <% if shown: %> <%= item.from_pretty %> <% else: %> - <%= item.from_pretty %> + <% if !_.isEmpty(item.from_pretty): %> + <%= item.from_pretty %> + <% else: %> + <%= item.from %> + <% end %> <% end %> @@ -58,21 +62,25 @@ <% classes.push('is-inactive') if !user.active %> <% if caller_id.level isnt 'known': %><%- @T('maybe') %> <% end %> <%= user.displayNameLong() %>
- <% else if caller_id.comment: %> + <% else if !_.isEmpty(caller_id.comment): %> <% shown = true %> <%- @T('maybe') %> <%= caller_id.comment %>
<% end %> <% end %> <% end %> - <% if !shown && item.to_comment: %> + <% if !shown && !_.isEmpty(item.to_comment): %> <% shown = true %> - <% if item.to_comment: %><%= item.to_comment %><% end %> + <%= item.to_comment %>
<% end %> <% if shown: %> <%= item.to_pretty %> <% else: %> - <%= item.to_pretty %> + <% if !_.isEmpty(item.to_pretty): %> + <%= item.to_pretty %> + <% else: %> + <%= item.to %> + <% end %> <% end %> diff --git a/app/models/cti/log.rb b/app/models/cti/log.rb index aaeb5013e..9c553dda4 100644 --- a/app/models/cti/log.rb +++ b/app/models/cti/log.rb @@ -4,9 +4,7 @@ module Cti store :preferences - after_create :push_incoming_call, :push_caller_list_update - after_update :push_incoming_call, :push_caller_list_update - after_destroy :push_caller_list_update + after_commit :push_incoming_call, :push_caller_list_update =begin @@ -366,12 +364,13 @@ Cti::Log.process( end def push_incoming_call - return if state != 'newCall' - return if direction != 'in' + return true if destroyed? + return true if state != 'newCall' + return true if direction != 'in' + + # send notify about event users = User.with_permissions('cti.agent') users.each do |user| - - # send notify about event Sessions.send_to( user.id, { @@ -380,24 +379,21 @@ Cti::Log.process( }, ) end + true end def self.push_caller_list_update?(record) list_ids = Cti::Log.log_records.pluck(:id) - if list_ids.present? - last_caller_log = Cti::Log.find_by(id: list_ids.last) - return false if last_caller_log && last_caller_log.created_at > record.created_at - 1.day - end - true + return true if list_ids.include?(record.id) + false end def push_caller_list_update - return false if Cti::Log.push_caller_list_update?(self) + return false if !Cti::Log.push_caller_list_update?(self) + # send notify on create/update/delete users = User.with_permissions('cti.agent') users.each do |user| - - # send notify on create/update/delete Sessions.send_to( user.id, { @@ -405,7 +401,6 @@ Cti::Log.process( }, ) end - true end diff --git a/test/controllers/integration_cti_controller_test.rb b/test/controllers/integration_cti_controller_test.rb index 1305a35fe..8e92f911c 100644 --- a/test/controllers/integration_cti_controller_test.rb +++ b/test/controllers/integration_cti_controller_test.rb @@ -448,6 +448,28 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest assert_nil(log.duration_waiting_time) assert_nil(log.duration_talking_time) + # inbound - IV - new call + params = 'event=newCall&direction=in&to=4930600000000&from=anonymous&call_id=1234567890-7&user%5B%5D=user+1,user+2' + post "/api/v1/cti/#{token}", params: params + assert_response(200) + log = Cti::Log.find_by(call_id: '1234567890-7') + assert(log) + assert_equal('4930600000000', log.to) + assert_equal('anonymous', log.from) + assert_equal('in', log.direction) + assert_equal('user 1,user 2', log.to_comment) + assert_nil(log.from_comment) + assert_not(log.preferences['to']) + assert_not(log.preferences['from']) + assert_nil(log.comment) + assert_equal('newCall', log.state) + assert_equal(false, log.done) + assert(log.initialized_at) + assert_nil(log.start_at) + assert_nil(log.end_at) + assert_nil(log.duration_waiting_time) + assert_nil(log.duration_talking_time) + # get caller list get '/api/v1/cti/log' assert_response(401) @@ -461,24 +483,25 @@ class IntegrationCtiControllerTest < ActionDispatch::IntegrationTest assert_response(200) result = JSON.parse(@response.body) assert_equal(result['list'].class, Array) - assert_equal(6, result['list'].count) + assert_equal(7, result['list'].count) assert(result['assets']) assert(result['assets']['User']) assert(result['assets']['User'][customer2.id.to_s]) assert(result['assets']['User'][customer3.id.to_s]) - assert_equal('1234567890-6', result['list'][0]['call_id']) - assert_equal('1234567890-5', result['list'][1]['call_id']) - assert_equal('1234567890-4', result['list'][2]['call_id']) - assert_equal('1234567890-3', result['list'][3]['call_id']) - assert_equal('1234567890-2', result['list'][4]['call_id']) - assert_equal('hangup', result['list'][4]['state']) - assert_equal('4930777000000', result['list'][4]['from']) - assert_equal('user 1', result['list'][4]['from_comment']) - assert_equal('4912347114711', result['list'][4]['to']) - assert_equal('CallerId Customer1', result['list'][4]['to_comment']) - assert_equal('normalClearing', result['list'][4]['comment']) - assert_equal('hangup', result['list'][4]['state']) - assert_equal('1234567890-1', result['list'][5]['call_id']) + assert_equal('1234567890-7', result['list'][0]['call_id']) + assert_equal('1234567890-6', result['list'][1]['call_id']) + assert_equal('1234567890-5', result['list'][2]['call_id']) + assert_equal('1234567890-4', result['list'][3]['call_id']) + assert_equal('1234567890-3', result['list'][4]['call_id']) + assert_equal('1234567890-2', result['list'][5]['call_id']) + assert_equal('hangup', result['list'][5]['state']) + assert_equal('4930777000000', result['list'][5]['from']) + assert_equal('user 1', result['list'][5]['from_comment']) + assert_equal('4912347114711', result['list'][5]['to']) + assert_equal('CallerId Customer1', result['list'][5]['to_comment']) + assert_equal('normalClearing', result['list'][5]['comment']) + assert_equal('hangup', result['list'][5]['state']) + assert_equal('1234567890-1', result['list'][6]['call_id']) end diff --git a/test/unit/cti_caller_id_test.rb b/test/unit/cti_caller_id_test.rb index 6eebb590a..164b53516 100644 --- a/test/unit/cti_caller_id_test.rb +++ b/test/unit/cti_caller_id_test.rb @@ -479,7 +479,18 @@ Mob: +49 333 8362222", test '5 probe if caller log need to be pushed' do - 60.times do |count| + Cti::Log.process( + 'cause' => '', + 'event' => 'newCall', + 'user' => 'user 1', + 'from' => '491111222222', + 'to' => '4930600000000', + 'callId' => 'touch-loop-0', + 'direction' => 'in', + ) + assert(Cti::Log.push_caller_list_update?(Cti::Log.last)) + + 65.times do |count| travel 1.hour Cti::Log.process( 'cause' => '', @@ -487,13 +498,40 @@ Mob: +49 333 8362222", 'user' => 'user 1', 'from' => '491111222222', 'to' => '4930600000000', - 'callId' => "touch-loop-#{count}", + 'callId' => "touch-loop-1-#{count}", 'direction' => 'in', ) end assert(Cti::Log.push_caller_list_update?(Cti::Log.last)) assert_not(Cti::Log.push_caller_list_update?(Cti::Log.first)) + 65.times do |count| + travel 1.minute + Cti::Log.process( + 'cause' => '', + 'event' => 'newCall', + 'user' => 'user 1', + 'from' => '491111222222', + 'to' => '4930600000000', + 'callId' => "touch-loop-2-#{count}", + 'direction' => 'in', + ) + end + assert(Cti::Log.push_caller_list_update?(Cti::Log.last)) + assert_not(Cti::Log.push_caller_list_update?(Cti::Log.first)) + + travel 2.seconds + Cti::Log.process( + 'cause' => '', + 'event' => 'newCall', + 'user' => 'user 1', + 'from' => '491111222222', + 'to' => '4930600000000', + 'callId' => 'touch-loop-3-1', + 'direction' => 'in', + ) + assert(Cti::Log.push_caller_list_update?(Cti::Log.last)) + end end