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
|
class ArtistsController < ApplicationController
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
before_action :member_only, :except => [:index, :show, :show_or_new, :banned]
|
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 :admin_only, :only => [:ban, :unban]
|
||||||
before_action :load_artist, :only => [:ban, :unban, :show, :edit, :update, :destroy, :undelete]
|
before_action :load_artist, :only => [:ban, :unban, :show, :edit, :update, :destroy, :undelete]
|
||||||
|
|
||||||
@@ -61,9 +60,6 @@ class ArtistsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if !@artist.deletable_by?(CurrentUser.user)
|
|
||||||
raise User::PrivilegeError
|
|
||||||
end
|
|
||||||
@artist.update_attribute(:is_active, false)
|
@artist.update_attribute(:is_active, false)
|
||||||
redirect_to(artist_path(@artist), :notice => "Artist deleted")
|
redirect_to(artist_path(@artist), :notice => "Artist deleted")
|
||||||
end
|
end
|
||||||
@@ -96,8 +92,7 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def artist_params(context = nil)
|
def artist_params(context = nil)
|
||||||
permitted_params = %i[name other_names other_names_string group_name url_string notes]
|
permitted_params = %i[name other_names other_names_string group_name url_string notes is_active]
|
||||||
permitted_params << :is_active if CurrentUser.is_builder?
|
|
||||||
permitted_params << :source if context == :new
|
permitted_params << :source if context == :new
|
||||||
|
|
||||||
params.fetch(:artist, {}).permit(permitted_params)
|
params.fetch(:artist, {}).permit(permitted_params)
|
||||||
|
|||||||
@@ -538,14 +538,6 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def deletable_by?(user)
|
|
||||||
user.is_builder?
|
|
||||||
end
|
|
||||||
|
|
||||||
def editable_by?(user)
|
|
||||||
user.is_builder? || (!is_banned? && is_active?)
|
|
||||||
end
|
|
||||||
|
|
||||||
def visible?
|
def visible?
|
||||||
!is_banned? || CurrentUser.is_gold?
|
!is_banned? || CurrentUser.is_gold?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
<%= simple_form_for(@artist) do |f| %>
|
<%= simple_form_for(@artist) do |f| %>
|
||||||
<% if @artist.new_record? %>
|
<% if @artist.new_record? %>
|
||||||
<%= f.input :name, as: :string, input_html: { data: { autocomplete: "tag" } } %>
|
<%= 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 %>
|
<% 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 %>
|
<% 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 %>
|
<%= 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" %>
|
<%= subnav_link_to "Edit", edit_artist_path(@artist), :"data-shortcut" => "e" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= subnav_link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %>
|
<%= 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? %>
|
<% 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?" %>
|
<%= 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 %>
|
<% else %>
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
<% if @artist.is_banned? %>
|
<% 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?"} %>
|
<%= subnav_link_to "Unban", unban_artist_path(@artist), :method => :put, :data => {:confirm => "Are you sure you want to unban this artist?"} %>
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= subnav_link_to "Ban", ban_artist_path(@artist), :method => :put, :data => {:confirm => "Are you sure you want to ban this artist?"} %>
|
<%= subnav_link_to "Ban", ban_artist_path(@artist), :method => :put, :data => {:confirm => "Are you sure you want to ban this artist?"} %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -2,15 +2,10 @@
|
|||||||
<div id="a-edit">
|
<div id="a-edit">
|
||||||
<h1>Edit Artist</h1>
|
<h1>Edit Artist</h1>
|
||||||
|
|
||||||
<% if @artist.editable_by?(CurrentUser.user) %>
|
<% if @artist.is_banned? %>
|
||||||
<%= render "form" %>
|
|
||||||
|
|
||||||
<% elsif !@artist.is_active? %>
|
|
||||||
<p>This artist entry is inactive and cannot be edited.</p>
|
|
||||||
|
|
||||||
<% elsif @artist.is_banned? %>
|
|
||||||
<p>The artist requested removal of this page.</p>
|
<p>The artist requested removal of this page.</p>
|
||||||
|
<% else %>
|
||||||
|
<%= render "form" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -40,14 +40,14 @@
|
|||||||
<%= time_ago_in_words_tagged(artist.updated_at) %>
|
<%= time_ago_in_words_tagged(artist.updated_at) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if artist.editable_by?(CurrentUser.user) %>
|
<% if CurrentUser.is_member? %>
|
||||||
<%= link_to "Edit", edit_artist_path(artist) %>
|
<%= link_to "Edit", edit_artist_path(artist) %>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if artist.is_active? && artist.deletable_by?(CurrentUser.user) %>
|
<% if artist.is_active? %>
|
||||||
| <%= link_to "Delete", artist_path(artist, artist: { is_active: false }), method: :put, remote: true %>
|
| <%= link_to "Delete", artist_path(artist, artist: { is_active: false }), method: :put, remote: true %>
|
||||||
<% elsif !artist.is_active? && artist.deletable_by?(CurrentUser.user) %>
|
<% else %>
|
||||||
| <%= link_to "Undelete", artist_path(artist, artist: { is_active: true }), method: :put, remote: true %>
|
| <%= link_to "Undelete", artist_path(artist, artist: { is_active: true }), method: :put, remote: true %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user