diff --git a/app/jobs/onceoff/migrate_from_slack_official.rb b/app/jobs/onceoff/migrate_from_slack_official.rb index 69de9ef..19c9b4c 100644 --- a/app/jobs/onceoff/migrate_from_slack_official.rb +++ b/app/jobs/onceoff/migrate_from_slack_official.rb @@ -105,7 +105,8 @@ module Jobs end if !(slack_discourse_username = site_settings_value('slack_discourse_username')).nil? - SiteSetting.chat_integration_discourse_username = slack_discourse_username + username = User.find_by(username: slack_discourse_username.downcase)&.username + SiteSetting.chat_integration_discourse_username = (username || Discourse.system_user.username) end end diff --git a/spec/jobs/onceoff/migrate_from_slack_official_spec.rb b/spec/jobs/onceoff/migrate_from_slack_official_spec.rb index b8f6f44..715e455 100644 --- a/spec/jobs/onceoff/migrate_from_slack_official_spec.rb +++ b/spec/jobs/onceoff/migrate_from_slack_official_spec.rb @@ -41,6 +41,19 @@ RSpec.describe Jobs::DiscourseChatMigrateFromSlackOfficial do expect(SiteSetting.chat_integration_slack_enabled).to eq(true) expect(SiteSetting.chat_integration_enabled).to eq(true) end + + describe 'when slack_discourse_username is not valid' do + before do + SiteSetting.find_by(name: 'slack_discourse_username').update!(value: 'someguy') + end + + it 'should default to the system user' do + described_class.new.execute_onceoff({}) + + expect(SiteSetting.chat_integration_discourse_username) + .to eq(Discourse.system_user.username) + end + end end describe 'when a uncategorized filter is present' do