diff --git a/app/controllers/admin/tags/moderators_controller.rb b/app/controllers/admin/tags/moderators_controller.rb index f114405c9..41e0b8153 100644 --- a/app/controllers/admin/tags/moderators_controller.rb +++ b/app/controllers/admin/tags/moderators_controller.rb @@ -18,7 +18,7 @@ module Admin flash[:error] = "Error: User ID ##{tag_params[:user_id]} was not found, or their account has errors: #{user&.errors_as_sentence}" end - redirect_to admin_tag_path(params[:tag_id]) + redirect_to edit_admin_tag_path(params[:tag_id]) end def destroy @@ -31,7 +31,7 @@ module Admin flash[:error] = "Error: User ID ##{tag_params[:user_id]} was not found, or their account has errors: #{user&.errors_as_sentence}" end - redirect_to admin_tag_path(tag.id) + redirect_to edit_admin_tag_path(tag.id) end private diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 9745b50a1..82f6b65f6 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -2,6 +2,7 @@ module Admin class TagsController < Admin::ApplicationController layout "admin" + before_action :badges_for_options, only: %i[new create edit update] after_action only: [:update] do Audit::Logger.log(:moderator, current_user, params.dup) end @@ -18,10 +19,26 @@ module Admin @tags = @tags.where("tags.name ILIKE :search", search: "%#{params[:search]}%") if params[:search].present? end - def show + def new + @tag = Tag.new + end + + def create + @tag = Tag.new(tag_params) + @tag.name = params[:tag][:name].downcase + + if @tag.save + flash[:success] = "Tag has been created!" + redirect_to edit_admin_tag_path(@tag) + else + flash[:danger] = @tag.errors_as_sentence + render :new + end + end + + def edit @tag = Tag.find(params[:id]) @tag_moderators = User.with_role(:tag_moderator, @tag).select(:id, :username) - @badges_for_options = Badge.pluck(:title, :id) end def update @@ -31,16 +48,20 @@ module Admin else flash[:error] = "The tag update failed: #{@tag.errors_as_sentence}" end - redirect_to admin_tag_path(@tag.id) + redirect_to edit_admin_tag_path(@tag.id) end private + def badges_for_options + @badges_for_options = Badge.pluck(:title, :id) + end + def tag_params allowed_params = %i[ id supported rules_markdown short_summary pretty_name bg_color_hex - text_color_hex user_id alias_for badge_id - category social_preview_template wiki_body_markdown + text_color_hex user_id alias_for badge_id requires_approval + category social_preview_template wiki_body_markdown submission_template ] params.require(:tag).permit(allowed_params) end diff --git a/app/views/admin/tags/_form.html.erb b/app/views/admin/tags/_form.html.erb index 6061fc1b1..01930d37d 100644 --- a/app/views/admin/tags/_form.html.erb +++ b/app/views/admin/tags/_form.html.erb @@ -1,57 +1,70 @@ -