From ccbf10cb7af882cd0609e87a2df76e270c1d6632 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 10 Sep 2018 14:35:12 +0200 Subject: [PATCH] Fixed Rails namespace lookup issue and removed remaining foreign key records in Token table when deleting a user. --- app/models/user.rb | 1 + test/unit/user_test.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 281bd8d25..515243d77 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1166,6 +1166,7 @@ raise 'Minimum one user need to have admin permissions' ::OnlineNotification.where(user_id: id).destroy_all ::RecentView.where(created_by_id: id).destroy_all ::UserDevice.remove(id) + ::Token.where(user_id: id).destroy_all true end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 7c0fbfcdf..194284dd2 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1258,6 +1258,8 @@ class UserTest < ActiveSupport::TestCase RecentView.log(ticket1.class.to_s, ticket1.id, agent1) assert_equal(1, RecentView.where(created_by_id: agent1_id).count) + Token.create!(action: 'api', user_id: agent1_id) + agent1.destroy! assert_equal(0, UserDevice.where(user_id: agent1_id).count) @@ -1268,6 +1270,7 @@ class UserTest < ActiveSupport::TestCase assert_equal(0, Cti::CallerId.where(user_id: agent1_id).count) assert_equal(0, Taskbar.where(user_id: agent1_id).count) assert_equal(0, RecentView.where(created_by_id: agent1_id).count) + assert_equal(0, Token.where(user_id: agent1_id).count) end test 'adding group drops cache' do