forked from e621ng/e621ng
[WikiPages] Redirect back to wiki when editing/fixing tag (#705)
This commit is contained in:
parent
f716bd8793
commit
ab0453120a
@ -5,6 +5,7 @@ class TagCorrectionsController < ApplicationController
|
||||
before_action :janitor_only, only: [:new, :create]
|
||||
|
||||
def new
|
||||
@from_wiki = request.referer.try(:include?, "wiki_pages") || false
|
||||
@correction = TagCorrection.new(params[:tag_id])
|
||||
respond_with(@correction)
|
||||
end
|
||||
@ -19,9 +20,12 @@ class TagCorrectionsController < ApplicationController
|
||||
|
||||
if params[:commit] == "Fix"
|
||||
@correction.fix!
|
||||
redirect_to tags_path(:search => {:name_matches => @correction.tag.name, :hide_empty => "no"}), :notice => "Tag will be fixed in a few seconds"
|
||||
if params[:from_wiki].to_s.truthy?
|
||||
return redirect_to(show_or_new_wiki_pages_path(title: WikiPage.normalize_name(@correction.tag.name)), notice: "Tag will be fixed in a few seconds")
|
||||
end
|
||||
redirect_to(tags_path(search: { name_matches: @correction.tag.name, hide_empty: "no"}), notice: "Tag will be fixed in a few seconds")
|
||||
else
|
||||
redirect_to tags_path(:search => {:name_matches => @correction.tag.name})
|
||||
redirect_to(tags_path(search: { name_matches: @correction.tag.name }))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,10 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagsController < ApplicationController
|
||||
before_action :member_only, :only => [:edit, :update, :preview]
|
||||
before_action :member_only, only: %i[edit update preview]
|
||||
respond_to :html, :json
|
||||
|
||||
def edit
|
||||
@from_wiki = request.referer.try(:include?, "wiki_pages") || false
|
||||
@tag = Tag.find(params[:id])
|
||||
check_privilege(@tag)
|
||||
respond_with(@tag)
|
||||
@ -38,7 +39,15 @@ class TagsController < ApplicationController
|
||||
@tag = Tag.find(params[:id])
|
||||
check_privilege(@tag)
|
||||
@tag.update(tag_params)
|
||||
respond_with(@tag)
|
||||
respond_with(@tag) do |format|
|
||||
format.html do
|
||||
if @tag.from_wiki.to_s.truthy?
|
||||
return redirect_to(show_or_new_wiki_pages_path(title: WikiPage.normalize_name(@tag.name)), notice: "Tag updated")
|
||||
else
|
||||
redirect_to(tags_path(search: { name_matches: @tag.name, hide_empty: "no" }))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
@ -48,7 +57,7 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
def tag_params
|
||||
permitted_params = [:category]
|
||||
permitted_params = %i[category from_wiki]
|
||||
permitted_params << :is_locked if CurrentUser.is_admin?
|
||||
|
||||
params.require(:tag).permit(permitted_params)
|
||||
|
@ -16,6 +16,8 @@ class Tag < ApplicationRecord
|
||||
|
||||
before_save :update_category, if: :category_changed?
|
||||
|
||||
attr_accessor :from_wiki
|
||||
|
||||
class CategoryMapping
|
||||
TagCategory::REVERSE_MAPPING.each do |value, category|
|
||||
define_method(category) do
|
||||
|
@ -47,7 +47,7 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
module SearchMethods
|
||||
def titled(title)
|
||||
find_by(title: title&.downcase&.tr(" ", "_"))
|
||||
find_by(title: WikiPage.normalize_name(title))
|
||||
end
|
||||
|
||||
def active
|
||||
@ -217,6 +217,10 @@ class WikiPage < ApplicationRecord
|
||||
name.unicode_normalize(:nfkc).gsub(/[[:space:]]+/, " ").strip.tr(" ", "_")
|
||||
end
|
||||
|
||||
def self.normalize_name(name)
|
||||
name&.downcase&.tr(" ", "_")
|
||||
end
|
||||
|
||||
def skip_secondary_validations=(value)
|
||||
@skip_secondary_validations = value.to_s.truthy?
|
||||
end
|
||||
|
@ -11,7 +11,8 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<%= form_tag(tag_correction_path(:tag_id => @correction.tag.id)) do %>
|
||||
<%= form_tag(tag_correction_path(tag_id: @correction.tag.id)) do %>
|
||||
<%= hidden_field_tag "from_wiki", @from_wiki %>
|
||||
<%= submit_tag "Fix" %>
|
||||
<%= submit_tag "Cancel" %>
|
||||
<% end %>
|
||||
|
@ -3,6 +3,7 @@
|
||||
<h1>Tag: <%= link_to @tag.name, posts_path(:tags => @tag.name), :class => "tag-type-#{@tag.category}" %></h1>
|
||||
|
||||
<%= custom_form_for(@tag) do |f| %>
|
||||
<%= f.hidden_field(:from_wiki, value: @from_wiki) %>
|
||||
<% if @tag.is_locked? %>
|
||||
<p>This tag is category locked</p>
|
||||
<% else %>
|
||||
|
@ -53,14 +53,14 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "update the tag" do
|
||||
put_auth tag_path(@tag), @user, params: { tag: { category: Tag.categories.general } }
|
||||
assert_redirected_to tag_path(@tag)
|
||||
assert_redirected_to(tags_path(search: { name_matches: @tag.name, hide_empty: "no" }))
|
||||
assert_equal(Tag.categories.general, @tag.reload.category)
|
||||
end
|
||||
|
||||
should "lock the tag for an admin" do
|
||||
put_auth tag_path(@tag), create(:admin_user), params: { tag: { is_locked: true } }
|
||||
|
||||
assert_redirected_to @tag
|
||||
assert_redirected_to(tags_path(search: { name_matches: @tag.name, hide_empty: "no" }))
|
||||
assert_equal(true, @tag.reload.is_locked)
|
||||
end
|
||||
|
||||
@ -87,7 +87,7 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
@admin = create(:admin_user)
|
||||
put_auth tag_path(@tag), @admin, params: { tag: { category: Tag.categories.general } }
|
||||
|
||||
assert_redirected_to @tag
|
||||
assert_redirected_to(tags_path(search: { name_matches: @tag.name, hide_empty: "no" }))
|
||||
assert_equal(Tag.categories.general, @tag.reload.category)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user