Refactor the "Banish" Modal in the Member Detail View (#16757)
* Refactors _banish.html.erb by removing duplicate code * Refactors _banish.html.erb to account for new and old users * Moves conditional into Admin::UsersController#set_user_to_be_banished * Reverts last commit, as it didnt work as expected * Fixes last commit, which reverted to the incorrect code * Pulls banishable user into instance var and fixes button txt
This commit is contained in:
parent
c06be3f447
commit
bf2973bdc4
2 changed files with 7 additions and 8 deletions
|
|
@ -36,6 +36,7 @@ module Admin
|
|||
def show
|
||||
@user = User.find(params[:id])
|
||||
set_current_tab(params[:tab])
|
||||
set_banishable_user
|
||||
set_feedback_messages
|
||||
set_related_reactions
|
||||
set_user_details
|
||||
|
|
@ -305,5 +306,10 @@ module Admin
|
|||
"overview"
|
||||
end
|
||||
end
|
||||
|
||||
def set_banishable_user
|
||||
@banishable_user = (@user.comments.where("created_at < ?", 100.days.ago).empty? &&
|
||||
@user.created_at < 100.days.ago) || current_user.super_admin? || current_user.support_admin?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,6 @@
|
|||
<div id="banish-for-spam">
|
||||
<div class="flex flex-col gap-4">
|
||||
<% if @user.comments.where("created_at < ?", 100.days.ago).empty? && @user.created_at < 100.days.ago %>
|
||||
<p>This action is irreversible.</p>
|
||||
<p>Once banished, we will delete all content created by <%= @user.name %> and change their username to @spam_###.</p>
|
||||
<p>Be careful with this action.</p>
|
||||
<%= form_for(@user, url: banish_admin_user_path(@user), html: { method: :post, onsubmit: "return confirm('Are you sure? This action is irreversible. Banishing will delete all content by #{@user.name} and change their username to @spam_###.')", id: nil }) do %>
|
||||
<button class="c-btn c-btn--primary c-btn--destructive">Banish User for spam</button>
|
||||
<% end %>
|
||||
<% elsif current_user.super_admin? || current_user.support_admin? %>
|
||||
<% if @banishable_user %>
|
||||
<p>This action is irreversible.</p>
|
||||
<p>Once banished, we will delete all content created by <%= @user.name %> and change their username to @spam_###.</p>
|
||||
<p>Be careful with this action.</p>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue