[EOY 2020] Replace "ban" with "suspend" in Admin (#11581)
* Implement changes * display "Suspended" if user role.name is banned * Correct equality symbol Co-authored-by: Michael Kohl <me@citizen428.net> Co-authored-by: Michael Kohl <me@citizen428.net>
This commit is contained in:
parent
de3d62bc40
commit
845e00797b
12 changed files with 36 additions and 32 deletions
|
|
@ -103,7 +103,7 @@ class ChatChannelsController < ApplicationController
|
|||
else
|
||||
render json: {
|
||||
status: "error",
|
||||
message: "Ban failed. user with username '#{username}' not found in this channel."
|
||||
message: "Suspend failed. user with username '#{username}' not found in this channel."
|
||||
}, status: :bad_request
|
||||
end
|
||||
when "/unban"
|
||||
|
|
@ -114,7 +114,7 @@ class ChatChannelsController < ApplicationController
|
|||
else
|
||||
render json: {
|
||||
status: "error",
|
||||
message: "Unban failed. User with username '#{username}' not found in this channel."
|
||||
message: "Unsuspend failed. User with username '#{username}' not found in this channel."
|
||||
}, status: :bad_request
|
||||
end
|
||||
when "/clearchannel"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
module Constants
|
||||
module Role
|
||||
BASE_ROLES = ["Warn",
|
||||
"Comment Ban",
|
||||
"Ban",
|
||||
"Comment Suspend",
|
||||
"Suspend",
|
||||
"Regular Member",
|
||||
"Trusted",
|
||||
"Pro"].freeze
|
||||
|
|
|
|||
|
|
@ -699,8 +699,8 @@ class Article < ApplicationRecord
|
|||
author_id: SiteConfig.mascot_user_id,
|
||||
noteable_id: user_id,
|
||||
noteable_type: "User",
|
||||
reason: "automatic_ban",
|
||||
content: "User banned for too many spammy articles, triggered by autovomit.",
|
||||
reason: "automatic_suspend",
|
||||
content: "User suspended for too many spammy articles, triggered by autovomit.",
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -272,8 +272,8 @@ class Comment < ApplicationRecord
|
|||
author_id: SiteConfig.mascot_user_id,
|
||||
noteable_id: user_id,
|
||||
noteable_type: "User",
|
||||
reason: "automatic_ban",
|
||||
content: "User banned for too many spammy articles, triggered by autovomit.",
|
||||
reason: "automatic_suspend",
|
||||
content: "User suspended for too many spammy articles, triggered by autovomit.",
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ module Moderator
|
|||
BanishedUser.create(username: user.username, banished_by: admin)
|
||||
user.unsubscribe_from_newsletters if user.email?
|
||||
remove_profile_info
|
||||
handle_user_status("Ban", "spam account")
|
||||
handle_user_status("Suspend", "spam account")
|
||||
delete_user_activity
|
||||
delete_comments
|
||||
delete_articles
|
||||
|
|
|
|||
|
|
@ -57,12 +57,12 @@ module Moderator
|
|||
|
||||
def handle_user_status(role, note)
|
||||
case role
|
||||
when "Ban" || "Spammer"
|
||||
when "Suspend" || "Spammer"
|
||||
user.add_role :banned
|
||||
remove_privileges
|
||||
when "Warn"
|
||||
warned
|
||||
when "Comment Ban"
|
||||
when "Comment Suspend"
|
||||
comment_banned
|
||||
when "Regular Member"
|
||||
regular_member
|
||||
|
|
|
|||
|
|
@ -15,7 +15,11 @@
|
|||
<p>(view full history in notes below)</p>
|
||||
<ul>
|
||||
<% @user.roles.each do |role| %>
|
||||
<li><%= role.name %> <em><%= role.resource_name.to_s %></em></li>
|
||||
<% if role.name == "banned" %>
|
||||
<li>suspended</li>
|
||||
<% else %>
|
||||
<li><%= role.name %> <em><%= role.resource_name.to_s %></em></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<% elsif @user.warned %>
|
||||
<span class="badge badge-warning">Member is Warned</span>
|
||||
<% elsif @user.comment_banned %>
|
||||
<span class="badge badge-warning">Member is Comment Banned</span>
|
||||
<span class="badge badge-warning">Member is Comment Suspended</span>
|
||||
<% elsif @user.trusted %>
|
||||
<span class="badge badge-success">Member is Trusted</span>
|
||||
<% else %>
|
||||
|
|
|
|||
|
|
@ -798,13 +798,13 @@ RSpec.describe Article, type: :model do
|
|||
expect(Reaction.last.user_id).to eq(user.id)
|
||||
end
|
||||
|
||||
it "does not ban user if only single vomit" do
|
||||
it "does not suspend user if only single vomit" do
|
||||
article.body_markdown = article.body_markdown.gsub(article.title, "This post is about Yahoomagoo gogo")
|
||||
article.save
|
||||
expect(article.user.banned).to be false
|
||||
end
|
||||
|
||||
it "bans user with 3 comment vomits" do
|
||||
it "suspends user with 3 comment vomits" do
|
||||
second_article = create(:article, user: article.user)
|
||||
third_article = create(:article, user: article.user)
|
||||
article.body_markdown = article.body_markdown.gsub(article.title, "This post is about Yahoomagoo gogo")
|
||||
|
|
@ -815,7 +815,7 @@ RSpec.describe Article, type: :model do
|
|||
second_article.save
|
||||
third_article.save
|
||||
expect(article.user.banned).to be true
|
||||
expect(Note.last.reason).to eq "automatic_ban"
|
||||
expect(Note.last.reason).to eq "automatic_suspend"
|
||||
end
|
||||
|
||||
it "does not create vomit reaction if does not have matching title" do
|
||||
|
|
|
|||
|
|
@ -410,13 +410,13 @@ RSpec.describe Comment, type: :model do
|
|||
expect(Reaction.last.user_id).to eq(user.id)
|
||||
end
|
||||
|
||||
it "does not ban user if only single vomit" do
|
||||
it "does no suspend user if only single vomit" do
|
||||
comment.body_markdown = "This post is about Yahoomagoo gogo"
|
||||
comment.save
|
||||
expect(comment.user.banned).to be false
|
||||
end
|
||||
|
||||
it "bans user with 3 comment vomits" do
|
||||
it "suspends user with 3 comment vomits" do
|
||||
comment.body_markdown = "This post is about Yahoomagoo gogo"
|
||||
second_comment = create(:comment, user: comment.user, body_markdown: "This post is about Yahoomagoo gogo")
|
||||
third_comment = create(:comment, user: comment.user, body_markdown: "This post is about Yahoomagoo gogo")
|
||||
|
|
@ -425,7 +425,7 @@ RSpec.describe Comment, type: :model do
|
|||
second_comment.save
|
||||
third_comment.save
|
||||
expect(comment.user.banned).to be true
|
||||
expect(Note.last.reason).to eq "automatic_ban"
|
||||
expect(Note.last.reason).to eq "automatic_suspend"
|
||||
end
|
||||
|
||||
it "does not create vomit reaction if user is established in this context" do
|
||||
|
|
|
|||
|
|
@ -113,19 +113,19 @@ RSpec.describe "Admin::Users", type: :request do
|
|||
end
|
||||
|
||||
context "when managing activity and roles" do
|
||||
it "adds comment ban role" do
|
||||
params = { user: { user_status: "Comment Ban", note_for_current_role: "comment ban this user" } }
|
||||
it "adds comment suspend role" do
|
||||
params = { user: { user_status: "Comment Suspend", note_for_current_role: "comment suspend this user" } }
|
||||
patch "/admin/users/#{user.id}/user_status", params: params
|
||||
|
||||
expect(user.roles.first.name).to eq("comment_banned")
|
||||
expect(Note.first.content).to eq("comment ban this user")
|
||||
expect(Note.first.content).to eq("comment suspend this user")
|
||||
end
|
||||
|
||||
it "selects new role for user" do
|
||||
user.add_role :trusted
|
||||
user.reload
|
||||
|
||||
params = { user: { user_status: "Comment Ban", note_for_current_role: "comment ban this user" } }
|
||||
params = { user: { user_status: "Comment Suspend", note_for_current_role: "comment suspend this user" } }
|
||||
patch "/admin/users/#{user.id}/user_status", params: params
|
||||
|
||||
expect(user.roles.count).to eq(1)
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ RSpec.describe "Admin bans user", type: :system do
|
|||
visit edit_admin_user_path(user.id)
|
||||
end
|
||||
|
||||
def ban_user
|
||||
def suspend_user
|
||||
visit "/admin/users/#{user.id}/edit"
|
||||
select("Ban", from: "user_user_status")
|
||||
select("Suspend", from: "user_user_status")
|
||||
fill_in("user_note_for_current_role", with: "something")
|
||||
click_button("Update User Status")
|
||||
expect(page).to have_content("User has been updated")
|
||||
|
|
@ -30,7 +30,7 @@ RSpec.describe "Admin bans user", type: :system do
|
|||
user.add_role :tag_moderator, tag
|
||||
end
|
||||
|
||||
def unban_user
|
||||
def unsuspend_user
|
||||
visit "/admin/users/#{user.id}/edit"
|
||||
select("Regular Member", from: "user_user_status")
|
||||
fill_in("user_note_for_current_role", with: "good user")
|
||||
|
|
@ -49,16 +49,16 @@ RSpec.describe "Admin bans user", type: :system do
|
|||
end
|
||||
|
||||
# to-do: add spec for invalid bans
|
||||
it "checks that the user is banned and has note" do
|
||||
ban_user
|
||||
it "checks that the user is suspended and has note" do
|
||||
suspend_user
|
||||
expect(user.banned).to eq(true)
|
||||
expect(Note.last.reason).to eq "Ban"
|
||||
expect(Note.last.reason).to eq "Suspend"
|
||||
end
|
||||
|
||||
it "removes other roles if user is banned" do
|
||||
it "removes other roles if user is suspended" do
|
||||
user.add_role :trusted
|
||||
add_tag_moderator_role
|
||||
ban_user
|
||||
suspend_user
|
||||
|
||||
expect(user.banned).to eq(true)
|
||||
expect(user.trusted).to eq(false)
|
||||
|
|
@ -68,7 +68,7 @@ RSpec.describe "Admin bans user", type: :system do
|
|||
|
||||
it "unbans user" do
|
||||
user.add_role :banned
|
||||
unban_user
|
||||
unsuspend_user
|
||||
|
||||
expect(user.has_role?(:banned)).to eq(false)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue