From f50247f0891fc101dbad4d8c4efe34914a83f088 Mon Sep 17 00:00:00 2001 From: Jess Lee Date: Tue, 29 Jan 2019 15:01:04 -0500 Subject: [PATCH] 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 --- app/controllers/internal/users_controller.rb | 3 +-- app/views/internal/users/edit.html.erb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index d3d99602a..605cde6c9 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -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 diff --git a/app/views/internal/users/edit.html.erb b/app/views/internal/users/edit.html.erb index ace377e6e..373ed0a4d 100644 --- a/app/views/internal/users/edit.html.erb +++ b/app/views/internal/users/edit.html.erb @@ -11,19 +11,19 @@

Banish User

- <% 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 %> +

This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.

+

Do not do this lightly.

+ <%= 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 %> + + <% end %> + <% elsif current_user.has_role?(:super_admin) %>

This is not a new user. You are only allowed to take this action because you are a super admin.

This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.

Do not do this lightly.

- <%= 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 %> <% end %> - <% elsif @user.comments.where("created_at < ?", 100.days.ago).empty? %> -

This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.

-

Do not do this lightly.

- <%= 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 %> - - <% end %> <% else %>

This is not a new user so you'll need to contact a super admin to banish this user.

<% end %> @@ -34,7 +34,7 @@ <% if current_user.has_role?(:super_admin) %>

This will completely destroy the user and all of their activity from our database. This action is irreversible.

Do not do this lightly.

- <%= 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 %> <% end %> <% else %>