Fix conditional so super admins can ban older spammers (#1651)

* allow superadmins to band old spammers

* enhance flash notification and show all new users

* fix confirm dialog
This commit is contained in:
Jess Lee 2019-01-29 15:01:04 -05:00 committed by Ben Halpern
parent 7c7c39149c
commit f50247f089
2 changed files with 10 additions and 11 deletions

View file

@ -128,10 +128,9 @@ class Internal::UsersController < Internal::ApplicationController
def full_delete
@user = User.find(params[:id])
username = @user.username
begin
Moderator::Banisher.call_delete_activity(admin: current_user, offender: @user)
flash[:notice] = "@" + username + " has been fully deleted. If this is a GDPR delete, remember to delete them from Mailchimp and Google Analytics."
flash[:notice] = "@" + @user.username + " (email: " + @user.email + ", user_id: " + @user.id.to_s + ") has been fully deleted. If this is a GDPR delete, remember to delete them from Mailchimp and Google Analytics."
rescue StandardError => e
flash[:error] = e.message
end

View file

@ -11,19 +11,19 @@
</ul>
<div class="row">
<h2>Banish User</h2>
<% if @user.comments.where("created_at < ?", 100.days.ago).empty? && current_user.has_role?(:super_admin) %>
<% if @user.comments.where("created_at < ?", 100.days.ago).empty? && @user.created_at < 100.days.ago %>
<p><em>This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.</em></p>
<p><strong>Do not do this lightly.</strong></p>
<%= form_for(@user, :url => banish_internal_user_path(@user), :html => {:method => :post, :onsubmit => "return confirm('Are you sure? This is extremely destructive and irreversible. Banishing will delete all articles and turn their username into @spam_###')"}) do %>
<button class="btn btn-danger" style="font-size:2em;">Banish User for Spam</button>
<% end %>
<% elsif current_user.has_role?(:super_admin) %>
<p><strong>This is not a new user.</strong> You are only allowed to take this action because you are a <strong>super admin.</strong></p>
<p><em>This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.</em></p>
<p><strong>Do not do this lightly.</strong></p>
<%= form_for(@user, :url => banish_internal_user_path(@user), :html => {:method => :post, :onsubmit => "confirm('Are you sure? This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###. Do not do it lightly.')"}) do %>
<%= form_for(@user, :url => banish_internal_user_path(@user), :html => {:method => :post, :onsubmit => "return confirm('Are you sure? This is extremely destructive and irreversible.Banishing will delete all articles and turn their username into @spam_###')"}) do %>
<button class="btn btn-danger" style="font-size:2em;">Banish User for Spam!</button>
<% end %>
<% elsif @user.comments.where("created_at < ?", 100.days.ago).empty? %>
<p><em>This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.</em></p>
<p><strong>Do not do this lightly.</strong></p>
<%= form_for(@user, :url => banish_internal_user_path(@user), :html => {:method => :post, :onsubmit => "confirm('Are you sure? This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###. Do not do it lightly.')"}) do %>
<button class="btn btn-danger" style="font-size:2em;">Banish User for Spam</button>
<% end %>
<% else %>
<p><em>This is not a new user so you'll need to contact a super admin to banish this user.</em></p>
<% end %>
@ -34,7 +34,7 @@
<% if current_user.has_role?(:super_admin) %>
<p>This will <strong>completely destroy the user</strong> and all of their activity from our database. This action is irreversible.</p>
<p><strong>Do not do this lightly.</strong></p>
<%= form_for(@user, :url => full_delete_internal_user_path(@user), :html => {:method => :post, :onsubmit => "confirm('Are you sure? This is extremely destructive and irreversible.')"}) do %>
<%= form_for(@user, :url => full_delete_internal_user_path(@user), :html => {:method => :post, :onsubmit => "return confirm('Are you sure? This is extremely destructive and irreversible.')"}) do %>
<button class="btn btn-danger" style="font-size:2em;">Fully Delete User & All Activity</button>
<% end %>
<% else %>