artists: allow members to rename, delete, and undelete artists.
Also allow Members to edit deleted or banned artists. Previously this was limited in the html, but not in the backend.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
class ArtistsController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
before_action :member_only, :except => [:index, :show, :show_or_new, :banned]
|
||||
before_action :builder_only, :only => [:destroy]
|
||||
before_action :admin_only, :only => [:ban, :unban]
|
||||
before_action :load_artist, :only => [:ban, :unban, :show, :edit, :update, :destroy, :undelete]
|
||||
|
||||
@@ -61,9 +60,6 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
if !@artist.deletable_by?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
@artist.update_attribute(:is_active, false)
|
||||
redirect_to(artist_path(@artist), :notice => "Artist deleted")
|
||||
end
|
||||
@@ -96,8 +92,7 @@ private
|
||||
end
|
||||
|
||||
def artist_params(context = nil)
|
||||
permitted_params = %i[name other_names other_names_string group_name url_string notes]
|
||||
permitted_params << :is_active if CurrentUser.is_builder?
|
||||
permitted_params = %i[name other_names other_names_string group_name url_string notes is_active]
|
||||
permitted_params << :source if context == :new
|
||||
|
||||
params.fetch(:artist, {}).permit(permitted_params)
|
||||
|
||||
@@ -538,14 +538,6 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def deletable_by?(user)
|
||||
user.is_builder?
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
user.is_builder? || (!is_banned? && is_active?)
|
||||
end
|
||||
|
||||
def visible?
|
||||
!is_banned? || CurrentUser.is_gold?
|
||||
end
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<%= simple_form_for(@artist) do |f| %>
|
||||
<% if @artist.new_record? %>
|
||||
<%= f.input :name, as: :string, input_html: { data: { autocomplete: "tag" } } %>
|
||||
<% elsif CurrentUser.user.is_builder? %>
|
||||
<%= f.input :name, as: :string, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this artist entry and its wiki page" %>
|
||||
<% else %>
|
||||
<p><%= @artist.name %></p>
|
||||
<%= f.input :name, as: :string, input_html: { data: { autocomplete: "tag" } }, hint: "Change to rename this artist entry and its wiki page" %>
|
||||
<% end %>
|
||||
|
||||
<%= f.input :other_names_string, label: "Other names", as: :text, input_html: { size: "50x1" }, hint: '<b style="color: red;">NEW</b> Separate names with spaces, not commas. Use underscores for spaces inside names.'.html_safe %>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<%= subnav_link_to "Edit", edit_artist_path(@artist), :"data-shortcut" => "e" %>
|
||||
<% end %>
|
||||
<%= subnav_link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %>
|
||||
<% if @artist.deletable_by?(CurrentUser.user) %>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<% if @artist.is_active? %>
|
||||
<%= subnav_link_to "Delete", artist_path(@artist), method: :delete, "data-shortcut": "shift+d", "data-confirm": "Are you sure you want to delete this artist?" %>
|
||||
<% else %>
|
||||
@@ -25,7 +25,6 @@
|
||||
<% if CurrentUser.is_admin? %>
|
||||
<% if @artist.is_banned? %>
|
||||
<%= subnav_link_to "Unban", unban_artist_path(@artist), :method => :put, :data => {:confirm => "Are you sure you want to unban this artist?"} %>
|
||||
|
||||
<% else %>
|
||||
<%= subnav_link_to "Ban", ban_artist_path(@artist), :method => :put, :data => {:confirm => "Are you sure you want to ban this artist?"} %>
|
||||
<% end %>
|
||||
|
||||
@@ -2,15 +2,10 @@
|
||||
<div id="a-edit">
|
||||
<h1>Edit Artist</h1>
|
||||
|
||||
<% if @artist.editable_by?(CurrentUser.user) %>
|
||||
<%= render "form" %>
|
||||
|
||||
<% elsif !@artist.is_active? %>
|
||||
<p>This artist entry is inactive and cannot be edited.</p>
|
||||
|
||||
<% elsif @artist.is_banned? %>
|
||||
<% if @artist.is_banned? %>
|
||||
<p>The artist requested removal of this page.</p>
|
||||
|
||||
<% else %>
|
||||
<%= render "form" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
<%= time_ago_in_words_tagged(artist.updated_at) %>
|
||||
</td>
|
||||
<td>
|
||||
<% if artist.editable_by?(CurrentUser.user) %>
|
||||
<% if CurrentUser.is_member? %>
|
||||
<%= link_to "Edit", edit_artist_path(artist) %>
|
||||
<% end %>
|
||||
|
||||
<% if artist.is_active? && artist.deletable_by?(CurrentUser.user) %>
|
||||
| <%= link_to "Delete", artist_path(artist, artist: { is_active: false }), method: :put, remote: true %>
|
||||
<% elsif !artist.is_active? && artist.deletable_by?(CurrentUser.user) %>
|
||||
| <%= link_to "Undelete", artist_path(artist, artist: { is_active: true }), method: :put, remote: true %>
|
||||
<% if artist.is_active? %>
|
||||
| <%= link_to "Delete", artist_path(artist, artist: { is_active: false }), method: :put, remote: true %>
|
||||
<% else %>
|
||||
| <%= link_to "Undelete", artist_path(artist, artist: { is_active: true }), method: :put, remote: true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user