Merge pull request #589 from goshakkk/user-admin-scope
Create the User.admins and User.moderators scopes
This commit is contained in:
commit
92eaa69df9
|
@ -12,8 +12,8 @@ class AdminDashboardData
|
||||||
@json ||= {
|
@json ||= {
|
||||||
reports: REPORTS.map { |type| Report.find(type) },
|
reports: REPORTS.map { |type| Report.find(type) },
|
||||||
problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check, ram_check].compact,
|
problems: [rails_env_check, host_names_check, gc_checks, sidekiq_check || clockwork_check, ram_check].compact,
|
||||||
admins: User.where(admin: true).count,
|
admins: User.admins.count,
|
||||||
moderators: User.where(moderator: true).count
|
moderators: User.moderators.count
|
||||||
}.merge(
|
}.merge(
|
||||||
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
|
SiteSetting.version_checks? ? {version_check: DiscourseUpdates.check_version} : {}
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,7 +25,7 @@ class PostAction < ActiveRecord::Base
|
||||||
'topics.deleted_at' => nil).count('DISTINCT posts.id')
|
'topics.deleted_at' => nil).count('DISTINCT posts.id')
|
||||||
|
|
||||||
$redis.set('posts_flagged_count', posts_flagged_count)
|
$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 })
|
MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: admins })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,9 @@ class User < ActiveRecord::Base
|
||||||
# This is just used to pass some information into the serializer
|
# This is just used to pass some information into the serializer
|
||||||
attr_accessor :notification_channel_position
|
attr_accessor :notification_channel_position
|
||||||
|
|
||||||
|
scope :admins, ->{ where(admin: true) }
|
||||||
|
scope :moderators, ->{ where(moderator: true) }
|
||||||
|
|
||||||
module NewTopicDuration
|
module NewTopicDuration
|
||||||
ALWAYS = -1
|
ALWAYS = -1
|
||||||
LAST_VISIT = -2
|
LAST_VISIT = -2
|
||||||
|
|
|
@ -4,7 +4,7 @@ class AdminConstraint
|
||||||
|
|
||||||
def matches?(request)
|
def matches?(request)
|
||||||
return false unless request.session[:current_user_id].present?
|
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
|
||||||
|
|
||||||
end
|
end
|
|
@ -41,7 +41,7 @@ class SystemMessage
|
||||||
# Either returns the system_username user or the first admin.
|
# Either returns the system_username user or the first admin.
|
||||||
def self.system_user
|
def self.system_user
|
||||||
user = User.where(username_lower: SiteSetting.system_username).first if SiteSetting.system_username.present?
|
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
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue