diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index c532c5fa0..74a50dd57 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -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]) diff --git a/app/models/artist.rb b/app/models/artist.rb index 722029311..1cb33042b 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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 diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index 06a70ad5c..85857241d 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -21,7 +21,12 @@ <% end %> <% end %> <% if CurrentUser.is_admin? %> -