From bf2973bdc421f4e98a9fa06882ec5560a7413168 Mon Sep 17 00:00:00 2001 From: Julianna Tetreault <32834804+juliannatetreault@users.noreply.github.com> Date: Thu, 17 Mar 2022 10:36:10 -0600 Subject: [PATCH] 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 --- app/controllers/admin/users_controller.rb | 6 ++++++ .../admin/users/show/profile/actions/_banish.html.erb | 9 +-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index bc7ff0c08..fb26e71e7 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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 diff --git a/app/views/admin/users/show/profile/actions/_banish.html.erb b/app/views/admin/users/show/profile/actions/_banish.html.erb index 0ca9dc6ac..a5bb7f587 100644 --- a/app/views/admin/users/show/profile/actions/_banish.html.erb +++ b/app/views/admin/users/show/profile/actions/_banish.html.erb @@ -1,13 +1,6 @@
This action is irreversible.
-Once banished, we will delete all content created by <%= @user.name %> and change their username to @spam_###.
-Be careful with this action.
- <%= 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 %> - - <% end %> - <% elsif current_user.super_admin? || current_user.support_admin? %> + <% if @banishable_user %>This action is irreversible.
Once banished, we will delete all content created by <%= @user.name %> and change their username to @spam_###.
Be careful with this action.