From f4d44187c8baaaf4ca7d303b4e425bd52c966ded Mon Sep 17 00:00:00 2001
From: Neil Lalonde <neillalonde@gmail.com>
Date: Tue, 24 Nov 2015 14:37:33 -0500
Subject: [PATCH] FIX: site_contact_user should default to system user, not
 first admin user

---
 lib/discourse.rb                  | 2 +-
 spec/components/discourse_spec.rb | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/discourse.rb b/lib/discourse.rb
index 890aa9aa932..3e6f4a57a31 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -272,7 +272,7 @@ module Discourse
   # Either returns the site_contact_username user or the first admin.
   def self.site_contact_user
     user = User.find_by(username_lower: SiteSetting.site_contact_username.downcase) if SiteSetting.site_contact_username.present?
-    user ||= User.admins.real.order(:id).first
+    user ||= (system_user || User.admins.real.order(:id).first)
   end
 
   SYSTEM_USER_ID ||= -1
diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb
index 5765a6d425f..deee763a98d 100644
--- a/spec/components/discourse_spec.rb
+++ b/spec/components/discourse_spec.rb
@@ -62,9 +62,9 @@ describe Discourse do
       expect(Discourse.site_contact_user).to eq(another_admin)
     end
 
-    it 'returns the first admin user otherwise' do
+    it 'returns the system user otherwise' do
       SiteSetting.stubs(:site_contact_username).returns(nil)
-      expect(Discourse.site_contact_user).to eq(admin)
+      expect(Discourse.site_contact_user.username).to eq("system")
     end
 
   end