From 2774bc207de095b5548bc07c82cea432f5cd7bd5 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 31 Aug 2018 12:25:06 +0200 Subject: [PATCH] Fixed issue #2218 - CTI Caller Log blocks user deletion/destroy and fails --- app/models/cti/caller_id.rb | 4 ++++ app/models/user.rb | 18 +++++++++--------- test/unit/cti_caller_id_test.rb | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/models/cti/caller_id.rb b/app/models/cti/caller_id.rb index 42cdf5522..f531f83af 100644 --- a/app/models/cti/caller_id.rb +++ b/app/models/cti/caller_id.rb @@ -98,6 +98,10 @@ returns # set user id user_id = record[:created_by_id] if model == User + if record.destroyed? + Cti::CallerId.where(user_id: user_id).destroy_all + return + end user_id = record.id end return if !user_id diff --git a/app/models/user.rb b/app/models/user.rb index f1fd4d44c..281bd8d25 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1157,15 +1157,15 @@ raise 'Minimum one user need to have admin permissions' end def destroy_longer_required_objects - Authorization.where(user_id: id).destroy_all - Avatar.remove('User', id) - Cti::CallerId.where(user_id: id).destroy_all - Taskbar.where(user_id: id).destroy_all - Karma::ActivityLog.where(user_id: id).destroy_all - Karma::User.where(user_id: id).destroy_all - OnlineNotification.where(user_id: id).destroy_all - RecentView.where(created_by_id: id).destroy_all - UserDevice.remove(id) + ::Authorization.where(user_id: id).destroy_all + ::Avatar.remove('User', id) + ::Cti::CallerId.where(user_id: id).destroy_all + ::Taskbar.where(user_id: id).destroy_all + ::Karma::ActivityLog.where(user_id: id).destroy_all + ::Karma::User.where(user_id: id).destroy_all + ::OnlineNotification.where(user_id: id).destroy_all + ::RecentView.where(created_by_id: id).destroy_all + ::UserDevice.remove(id) true end diff --git a/test/unit/cti_caller_id_test.rb b/test/unit/cti_caller_id_test.rb index 164b53516..09ceb718d 100644 --- a/test/unit/cti_caller_id_test.rb +++ b/test/unit/cti_caller_id_test.rb @@ -325,7 +325,7 @@ Mob: +49 333 8362222", end - test '4 touch caller log / don\'t touch caller log' do + test '4 touch caller log / don\'t touch caller log' do 5.times do |count| travel 2.seconds Cti::Log.process( @@ -477,7 +477,7 @@ Mob: +49 333 8362222", end - test '5 probe if caller log need to be pushed' do + test '5 probe if caller log need to be pushed' do Cti::Log.process( 'cause' => '', @@ -534,4 +534,17 @@ Mob: +49 333 8362222", end + test 'user delete with caller log rebuild' do + assert_equal(2, Cti::CallerId.where(user_id: @agent2.id).count) + + @agent2.destroy! + + assert_equal(0, Cti::CallerId.where(user_id: @agent2.id).count) + + Observer::Transaction.commit + Scheduler.worker(true) + + assert_equal(0, Cti::CallerId.where(user_id: @agent2.id).count) + end + end