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:
Julianna Tetreault 2022-03-17 10:36:10 -06:00 committed by GitHub
parent c06be3f447
commit bf2973bdc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View file

@ -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

View file

@ -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>