From 942e090b3a8d5c117f7b3d84385794c7ffc39556 Mon Sep 17 00:00:00 2001 From: Mahonri Gibson <mahonrig@gmail.com> Date: Thu, 11 May 2017 19:38:46 +0000 Subject: [PATCH] Fix welcome message crashing server if podmin is set to invalid user. Fixes #7363 closes #7452 --- Changelog.md | 1 + app/models/user.rb | 1 + spec/models/user_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/Changelog.md b/Changelog.md index b4ee909435..c9b28d8f59 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ * Fix first comment in mobile view with french locale [#7441](https://github.com/diaspora/diaspora/pull/7441) * Use post page title and post author in atom feed [#7420](https://github.com/diaspora/diaspora/pull/7420) * Handle broken public keys when receiving posts [#7448](https://github.com/diaspora/diaspora/pull/7448) +* Fix welcome message when podmin is set to an invalid username [#7452](https://github.com/diaspora/diaspora/pull/7452) ## Features diff --git a/app/models/user.rb b/app/models/user.rb index e8a09a322d..55fd554c53 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -431,6 +431,7 @@ class User < ActiveRecord::Base return unless AppConfig.settings.welcome_message.enabled? && AppConfig.admins.account? sender_username = AppConfig.admins.account.get sender = User.find_by(username: sender_username) + return if sender.nil? conversation = sender.build_conversation( participant_ids: [sender.person.id, person.id], subject: AppConfig.settings.welcome_message.subject.get, diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index da59913cef..f12f0390cf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -875,6 +875,12 @@ describe User, :type => :model do user.send_welcome_message expect(user.conversations.count).to eq 0 end + + it "should send no welcome message if podmin is invalid" do + AppConfig.admins.account = "invalid" + user.send_welcome_message + expect(user.conversations.count).to eq 0 + end end context "with welcome message disabled" do -- GitLab