* Update /internal/badges route to be /internal/badges/award -Updates the route -Redirects the old route, /internal/badges, to the new route * Updates the redirect in #award_badges to correct route -Updates #award_badges in Internal::Badges::Controller to account for the new route, /internal/badges/award * Adjust route to be /internal/badges/award in admin_awards_badges_spec.rb * Adjust URL to be /internal/badges/award in badges_spec.rb * Replace /internal/badges/award with /internal/badge_achievements to follow convention -Updates the old route in routes.rb -Updates the old route in #award_badges in Internal::Badges::Controller -Updates the old route in admin_awards_badges_spec.rb -Updates the old route in badges_spec.rb
29 lines
864 B
Ruby
29 lines
864 B
Ruby
module Internal
|
|
class BadgesController < Internal::ApplicationController
|
|
layout "internal"
|
|
|
|
def index
|
|
@badges = Badge.all
|
|
end
|
|
|
|
def award_badges
|
|
raise ArgumentError, "Please choose a badge to award" if permitted_params[:badge].blank?
|
|
|
|
usernames = permitted_params[:usernames].split(/\s*,\s*/)
|
|
message = permitted_params[:message_markdown].presence || "Congrats!"
|
|
BadgeAchievements::BadgeAwardWorker.perform_async(usernames, permitted_params[:badge], message)
|
|
|
|
flash[:success] = "Badges are being rewarded. The task will finish shortly."
|
|
redirect_to internal_badges_url
|
|
rescue ArgumentError => e
|
|
flash[:danger] = e.message
|
|
redirect_to "/internal/badge_achievements"
|
|
end
|
|
|
|
private
|
|
|
|
def permitted_params
|
|
params.permit(:usernames, :badge, :message_markdown)
|
|
end
|
|
end
|
|
end
|