From af2915b0863dbdca9b033ece1269de83652192a5 Mon Sep 17 00:00:00 2001 From: Jess Lee Date: Fri, 1 Feb 2019 16:10:17 -0500 Subject: [PATCH] Fix Banisher Updates (#1704) * delete activity before updating username * fix linting * remove unnecssary return --- app/models/user.rb | 4 ++++ app/services/moderator/banisher.rb | 5 ++--- app/views/internal/users/edit.html.erb | 14 +++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 590deb004..420d4b2d3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -286,6 +286,10 @@ class User < ApplicationRecord has_role? :warned end + def banished? + user.notes.where(reason: "banned", content: "spam account").any? && user.banned + end + def banned_from_mentorship has_role? :banned_from_mentorship end diff --git a/app/services/moderator/banisher.rb b/app/services/moderator/banisher.rb index ce8b5108a..478107148 100644 --- a/app/services/moderator/banisher.rb +++ b/app/services/moderator/banisher.rb @@ -22,7 +22,7 @@ module Moderator new_name = "spam_#{rand(10000)}" new_username = "spam_#{rand(10000)}" end - user.update_columns(name: new_name, username: new_username, old_username: user.name) + user.update_columns(name: new_name, username: new_username, old_username: user.username) CacheBuster.new.bust("/#{user.old_username}") end @@ -90,12 +90,11 @@ module Moderator def banish user.unsubscribe_from_newsletters - reassign_and_bust_username remove_profile_info add_banned_role delete_user_activity user.remove_from_algolia_index - user.save! + reassign_and_bust_username end end end diff --git a/app/views/internal/users/edit.html.erb b/app/views/internal/users/edit.html.erb index 373ed0a4d..b50d5d259 100644 --- a/app/views/internal/users/edit.html.erb +++ b/app/views/internal/users/edit.html.erb @@ -1,5 +1,5 @@

- <%= @user.name%> (@<%= @user.username %>) + <%= @user.name %> (@<%= @user.username %>)

click here view user details & take other actions

Member since <%= @user.created_at.strftime("%b %e '%y") %>

@@ -11,17 +11,19 @@

Banish User

- <% if @user.comments.where("created_at < ?", 100.days.ago).empty? && @user.created_at < 100.days.ago %> + <% if @user.banished? %> +

User has been banished.

+ <% elsif @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 %> + <%= form_for(@user, url: banish_internal_user_path(@user), html: { method: :post, onsumbit: "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 => "return confirm('Are you sure? This is extremely destructive and irreversible.Banishing will delete all articles and turn their username into @spam_###')"}) do %> + <%= form_for(@user, url: banish_internal_user_path(@user), html: { method: :post, onsumbit: "return confirm('Are you sure? This is extremely destructive and irreversible.Banishing will delete all articles and turn their username into @spam_###')" }) do %> <% end %> <% else %> @@ -34,12 +36,10 @@ <% 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 => "return 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 %>

Only super admins can fully delete users.

<% end %>
- -