mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
FEATURE: Allow admins to disable specific badges
This commit is contained in:
@ -30,7 +30,7 @@ class Admin::BadgesController < Admin::AdminController
|
||||
end
|
||||
|
||||
def update_badge_from_params(badge)
|
||||
params.permit(:name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable)
|
||||
params.permit(:name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable, :enabled)
|
||||
badge.name = params[:name]
|
||||
badge.description = params[:description]
|
||||
badge.badge_type = BadgeType.find(params[:badge_type_id])
|
||||
@ -38,6 +38,7 @@ class Admin::BadgesController < Admin::AdminController
|
||||
badge.multiple_grant = params[:multiple_grant]
|
||||
badge.icon = params[:icon]
|
||||
badge.listable = params[:listable]
|
||||
badge.enabled = params[:enabled]
|
||||
badge
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ class BadgesController < ApplicationController
|
||||
|
||||
def index
|
||||
badges = Badge.all
|
||||
badges = badges.where(listable: true) if(params[:only_listable] == "true") || !request.xhr?
|
||||
badges = badges.where(enabled: true, listable: true) if(params[:only_listable] == "true") || !request.xhr?
|
||||
badges = badges.to_a
|
||||
serialized = MultiJson.dump(serialize_data(badges, BadgeSerializer, root: "badges"))
|
||||
respond_to do |format|
|
||||
@ -17,7 +17,7 @@ class BadgesController < ApplicationController
|
||||
|
||||
def show
|
||||
params.require(:id)
|
||||
badge = Badge.find(params[:id])
|
||||
badge = Badge.enabled.find(params[:id])
|
||||
|
||||
if current_user
|
||||
user_badge = UserBadge.find_by(user_id: current_user.id, badge_id: badge.id)
|
||||
|
@ -17,7 +17,8 @@ class UserBadgesController < ApplicationController
|
||||
user_badges = user_badges.includes(:user, :granted_by, badge: :badge_type, post: :topic)
|
||||
|
||||
if params[:grouped]
|
||||
user_badges = user_badges.group(:badge_id).select(UserBadge.attribute_names.map {|x| "MAX(#{x}) as #{x}" }, 'COUNT(*) as count')
|
||||
user_badges = user_badges.group(:badge_id)
|
||||
.select(UserBadge.attribute_names.map {|x| "MAX(#{x}) as #{x}" }, 'COUNT(*) as count')
|
||||
end
|
||||
|
||||
render_serialized(user_badges, UserBadgeSerializer, root: "user_badges")
|
||||
@ -60,9 +61,9 @@ class UserBadgesController < ApplicationController
|
||||
params.permit(:badge_name)
|
||||
if params[:badge_name].nil?
|
||||
params.require(:badge_id)
|
||||
badge = Badge.find_by(id: params[:badge_id])
|
||||
badge = Badge.find_by(id: params[:badge_id], enabled: true)
|
||||
else
|
||||
badge = Badge.find_by(name: params[:badge_name])
|
||||
badge = Badge.find_by(name: params[:badge_name], enabled: true)
|
||||
end
|
||||
raise Discourse::NotFound.new if badge.blank?
|
||||
|
||||
|
Reference in New Issue
Block a user