Merge pull request #589 from goshakkk/user-admin-scope

Create the User.admins and User.moderators scopes
This commit is contained in:
Robin Ward 2013-03-29 10:06:28 -07:00
commit 92eaa69df9
5 changed files with 10 additions and 7 deletions

View file

@ -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} : {}
)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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