diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index d7a32348f8c..589f4c2f681 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -12,8 +12,8 @@ class AdminDashboardData @json ||= { reports: REPORTS.map { |type| Report.find(type) }, problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check, ram_check].compact, - admins: User.where(admin: true).count, - moderators: User.where(moderator: true).count + admins: User.admins.count, + moderators: User.moderators.count }.merge( SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {} ) @@ -43,4 +43,4 @@ class AdminDashboardData def ram_check I18n.t('dashboard.memory_warning') if MemInfo.new.mem_total and MemInfo.new.mem_total < 1_000_000 end -end \ No newline at end of file +end diff --git a/app/models/post_action.rb b/app/models/post_action.rb index dd51a390b6b..1e9e66f7620 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -25,7 +25,7 @@ class PostAction < ActiveRecord::Base 'topics.deleted_at' => nil).count('DISTINCT posts.id') $redis.set('posts_flagged_count', posts_flagged_count) - admins = User.where(admin: true).select(:id).map {|u| u.id} + admins = User.admins.select(:id).map {|u| u.id} MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: admins }) end diff --git a/app/models/user.rb b/app/models/user.rb index ed0e0cda810..83f6b528b45 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,6 +47,9 @@ class User < ActiveRecord::Base # This is just used to pass some information into the serializer attr_accessor :notification_channel_position + scope :admins, ->{ where(admin: true) } + scope :moderators, ->{ where(moderator: true) } + module NewTopicDuration ALWAYS = -1 LAST_VISIT = -2 diff --git a/lib/admin_constraint.rb b/lib/admin_constraint.rb index 125d1d6787a..7ee35dd5943 100644 --- a/lib/admin_constraint.rb +++ b/lib/admin_constraint.rb @@ -4,7 +4,7 @@ class AdminConstraint def matches?(request) return false unless request.session[:current_user_id].present? - User.where(id: request.session[:current_user_id].to_i).where(admin: true).exists? + User.admins.where(id: request.session[:current_user_id].to_i).exists? end -end \ No newline at end of file +end diff --git a/lib/system_message.rb b/lib/system_message.rb index 4829f96afe1..883cd72c09e 100644 --- a/lib/system_message.rb +++ b/lib/system_message.rb @@ -41,7 +41,7 @@ class SystemMessage # Either returns the system_username user or the first admin. def self.system_user user = User.where(username_lower: SiteSetting.system_username).first if SiteSetting.system_username.present? - user = User.where(admin: true).order(:id).first if user.blank? + user = User.admins.order(:id).first if user.blank? user end