Merge pull request #1810 from basecamp/flavorjones/disconnect-cable-on-deactivation
Disconnect action cable when user is deactivated
This commit is contained in:
@@ -24,10 +24,16 @@ class User < ApplicationRecord
|
|||||||
transaction do
|
transaction do
|
||||||
accesses.destroy_all
|
accesses.destroy_all
|
||||||
update! active: false, identity: nil
|
update! active: false, identity: nil
|
||||||
|
close_remote_connections
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup?
|
def setup?
|
||||||
name != identity.email_address
|
name != identity.email_address
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def close_remote_connections
|
||||||
|
ActionCable.server.remote_connections.where(current_user: self).disconnect(reconnect: false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ class UserTest < ActiveSupport::TestCase
|
|||||||
test "deactivate" do
|
test "deactivate" do
|
||||||
assert_changes -> { users(:jz).active? }, from: true, to: false do
|
assert_changes -> { users(:jz).active? }, from: true, to: false do
|
||||||
assert_changes -> { users(:jz).accesses.count }, from: 1, to: 0 do
|
assert_changes -> { users(:jz).accesses.count }, from: 1, to: 0 do
|
||||||
users(:jz).deactivate
|
users(:jz).tap do |user|
|
||||||
|
user.stubs(:close_remote_connections).once
|
||||||
|
user.deactivate
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user