diff --git a/app/models/user.rb b/app/models/user.rb index 5073d41e1dd..366518ccb75 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -119,7 +119,7 @@ def suspend! analytics.user_suspended(success: false, error_message: :user_already_suspended) raise 'user_already_suspended' end - OutOfBandSessionAccessor.new(unique_session_id).destroy + OutOfBandSessionAccessor.new(unique_session_id).destroy if unique_session_id update!(suspended_at: Time.zone.now, unique_session_id: nil) analytics.user_suspended(success: true) end diff --git a/spec/lib/action_account_spec.rb b/spec/lib/action_account_spec.rb index 6d1c2975e22..82cd01864ee 100644 --- a/spec/lib/action_account_spec.rb +++ b/spec/lib/action_account_spec.rb @@ -196,7 +196,7 @@ let(:config) { ScriptBase::Config.new(include_missing:) } subject(:result) { subtask.run(args:, config:) } - it 'Suspend a user that is not suspended already', aggregate_failures: true do + it 'suspend a user that is not suspended already', aggregate_failures: true do expect(result.table).to match_array( [ ['uuid', 'status'], diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 545de436f61..aa6de66bba3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -810,6 +810,14 @@ expect(OutOfBandSessionAccessor.new(mock_session_id).exists?).to eq false end + + context 'user has a nil current session id' do + let(:mock_session_id) { nil } + + it 'does not error' do + expect { user.suspend! }.to_not raise_error + end + end end it 'raises an error if the user is already suspended' do