fixes #1383
This commit is contained in:
@@ -2,7 +2,7 @@ class ArtistsController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show, :banned]
|
||||
before_filter :builder_only, :only => [:destroy]
|
||||
before_filter :admin_only, :only => [:ban]
|
||||
before_filter :admin_only, :only => [:ban, :unban]
|
||||
|
||||
def new
|
||||
@artist = Artist.new_with_defaults(params)
|
||||
@@ -32,6 +32,12 @@ class ArtistsController < ApplicationController
|
||||
redirect_to(artist_path(@artist), :notice => "Artist was banned")
|
||||
end
|
||||
|
||||
def unban
|
||||
@artist = Artist.find(params[:id])
|
||||
@artist.unban!
|
||||
redirect_to(artist_path(@artist), :notice => "Artist was unbanned")
|
||||
end
|
||||
|
||||
def index
|
||||
search_params = params[:search].present? ? params[:search] : params
|
||||
@artists = Artist.search(search_params).order("id desc").paginate(params[:page], :limit => params[:limit])
|
||||
|
||||
@@ -202,6 +202,24 @@ class Artist < ActiveRecord::Base
|
||||
end
|
||||
|
||||
module BanMethods
|
||||
def unban!
|
||||
Post.transaction do
|
||||
CurrentUser.without_safe_mode do
|
||||
begin
|
||||
Post.tag_match(name).each do |post|
|
||||
post.unban!
|
||||
end
|
||||
rescue Post::SearchError
|
||||
# swallow
|
||||
end
|
||||
|
||||
ti = TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").first
|
||||
ti.destroy if ti
|
||||
update_column(:is_banned, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def ban!
|
||||
Post.transaction do
|
||||
CurrentUser.without_safe_mode do
|
||||
|
||||
@@ -21,7 +21,12 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<li><%= link_to "Ban", ban_artist_path(@artist), :method => :put, :confirm => "Are you sure you want to ban this artist?" %></li>
|
||||
<% if @artist.is_banned? %>
|
||||
<li><%= link_to "unban", unban_artist_path(@artist), :method => :put, :confirm => "Are you sure you want to unban this artist?" %></li>
|
||||
|
||||
<% else %>
|
||||
<li><%= link_to "Ban", ban_artist_path(@artist), :method => :put, :confirm => "Are you sure you want to ban this artist?" %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</menu>
|
||||
|
||||
@@ -63,6 +63,7 @@ Danbooru::Application.routes.draw do
|
||||
member do
|
||||
put :revert
|
||||
put :ban
|
||||
put :unban
|
||||
post :undelete
|
||||
end
|
||||
collection do
|
||||
|
||||
@@ -37,6 +37,16 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
@post.reload
|
||||
end
|
||||
|
||||
should "allow unbanning" do
|
||||
assert_difference("TagImplication.count", -1) do
|
||||
@artist.unban!
|
||||
end
|
||||
@post.reload
|
||||
@artist.reload
|
||||
assert(!@artist.is_banned?, "artist should not be banned")
|
||||
assert(!@post.is_banned?, "post should not be banned")
|
||||
end
|
||||
|
||||
should "ban the post" do
|
||||
assert(@post.is_banned?)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user