Fixed issue #2218 - CTI Caller Log blocks user deletion/destroy and fails

This commit is contained in:
Martin Edenhofer 2018-08-31 12:25:06 +02:00
parent ec74d56b77
commit 2774bc207d
3 changed files with 28 additions and 11 deletions

View file

@ -98,6 +98,10 @@ returns
# set user id # set user id
user_id = record[:created_by_id] user_id = record[:created_by_id]
if model == User if model == User
if record.destroyed?
Cti::CallerId.where(user_id: user_id).destroy_all
return
end
user_id = record.id user_id = record.id
end end
return if !user_id return if !user_id

View file

@ -1157,15 +1157,15 @@ raise 'Minimum one user need to have admin permissions'
end end
def destroy_longer_required_objects def destroy_longer_required_objects
Authorization.where(user_id: id).destroy_all ::Authorization.where(user_id: id).destroy_all
Avatar.remove('User', id) ::Avatar.remove('User', id)
Cti::CallerId.where(user_id: id).destroy_all ::Cti::CallerId.where(user_id: id).destroy_all
Taskbar.where(user_id: id).destroy_all ::Taskbar.where(user_id: id).destroy_all
Karma::ActivityLog.where(user_id: id).destroy_all ::Karma::ActivityLog.where(user_id: id).destroy_all
Karma::User.where(user_id: id).destroy_all ::Karma::User.where(user_id: id).destroy_all
OnlineNotification.where(user_id: id).destroy_all ::OnlineNotification.where(user_id: id).destroy_all
RecentView.where(created_by_id: id).destroy_all ::RecentView.where(created_by_id: id).destroy_all
UserDevice.remove(id) ::UserDevice.remove(id)
true true
end end

View file

@ -325,7 +325,7 @@ Mob: +49 333 8362222",
end 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| 5.times do |count|
travel 2.seconds travel 2.seconds
Cti::Log.process( Cti::Log.process(
@ -477,7 +477,7 @@ Mob: +49 333 8362222",
end 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( Cti::Log.process(
'cause' => '', 'cause' => '',
@ -534,4 +534,17 @@ Mob: +49 333 8362222",
end 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 end