forked from e621ng/e621ng
[Admin] Add a page to remove dnp tags from artists
This commit is contained in:
parent
162ed5c13a
commit
83692fc595
51
app/controllers/admin/stuck_dnp_controller.rb
Normal file
51
app/controllers/admin/stuck_dnp_controller.rb
Normal file
@ -0,0 +1,51 @@
|
||||
module Admin
|
||||
class StuckDnpController < ApplicationController
|
||||
before_action :admin_only
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
query = create_params[:query]
|
||||
|
||||
if query.blank?
|
||||
flash[:notice] = "No query specified"
|
||||
redirect_to new_admin_stuck_dnp_path
|
||||
return
|
||||
end
|
||||
|
||||
dnp_tags = %w[avoid_posting conditional_dnp]
|
||||
post_ids = []
|
||||
Post.tag_match(query).limit(1000).records.each do |p|
|
||||
contains_avoid_posting = p.has_tag?("avoid_posting")
|
||||
contains_conditional_dnp = p.has_tag?("conditional_dnp")
|
||||
if !contains_avoid_posting && !contains_conditional_dnp
|
||||
next
|
||||
end
|
||||
|
||||
p.do_not_version_changes = true
|
||||
|
||||
locked_tags = Tag.scan_tags((p.locked_tags || "").downcase)
|
||||
locked_tags -= dnp_tags
|
||||
p.locked_tags = locked_tags.join(" ")
|
||||
p.remove_tag(dnp_tags)
|
||||
|
||||
p.save
|
||||
|
||||
if contains_avoid_posting != p.has_tag?("avoid_posting") || contains_conditional_dnp != p.has_tag?("conditional_dnp")
|
||||
post_ids << p.id
|
||||
end
|
||||
end
|
||||
|
||||
StaffAuditLog.log(:stuck_dnp, CurrentUser.user, { query: query, post_ids: post_ids })
|
||||
flash[:notice] = "DNP tags removed from #{post_ids.count} posts"
|
||||
redirect_to new_admin_stuck_dnp_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_params
|
||||
params.require(:stuck_dnp).permit(%i[query])
|
||||
end
|
||||
end
|
||||
end
|
12
app/views/admin/stuck_dnp/new.html.erb
Normal file
12
app/views/admin/stuck_dnp/new.html.erb
Normal file
@ -0,0 +1,12 @@
|
||||
<div id="c-admin-stuck-dnp">
|
||||
<div id="a-new">
|
||||
<h1>Remove stuck DNP tags</h1>
|
||||
<p>
|
||||
Use this to remove <%= link_to "avoid_posting", wiki_path(id: "avoid_posting") %> and <%= link_to "conditional_dnp", wiki_path(id: "conditional_dnp") %> from artists who got removed from the DNP list.
|
||||
</p>
|
||||
<%= custom_form_for(:stuck_dnp, url: admin_stuck_dnp_path, method: :post) do |f| %>
|
||||
<%= f.input :query %>
|
||||
<%= f.submit "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
@ -115,6 +115,7 @@
|
||||
<li><%= link_to("Danger Zone", admin_danger_zone_index_path) %></li>
|
||||
<li><%= link_to("IP Bans", ip_bans_path) %></li>
|
||||
<li><%= link_to("Alt list", alt_list_admin_users_path) %></li>
|
||||
<li><%= link_to("Stuck DNP tags", new_admin_stuck_dnp_path) %></li>
|
||||
<% end %>
|
||||
<li><%= link_to("Upload Whitelist", upload_whitelists_path) %></li>
|
||||
<li><%= link_to("Mod Actions", mod_actions_path) %></li>
|
||||
|
@ -20,6 +20,7 @@ Rails.application.routes.draw do
|
||||
resource :dashboard, :only => [:show]
|
||||
resources :exceptions, only: [:index, :show]
|
||||
resource :reowner, controller: 'reowner', only: [:new, :create]
|
||||
resource :stuck_dnp, controller: "stuck_dnp", only: %i[new create]
|
||||
resources :staff_notes, only: [:index]
|
||||
resources :danger_zone, only: [:index] do
|
||||
collection do
|
||||
|
Loading…
Reference in New Issue
Block a user