parent
8c9560e33f
commit
1eeaa34e98
10 changed files with 64 additions and 4 deletions
|
|
@ -5,6 +5,7 @@ module Constants
|
|||
"Comment Suspended" => { name: "comment_suspended", resource_type: nil },
|
||||
"Limited" => { name: "limited", resource_type: nil },
|
||||
"Suspended" => { name: "suspended", resource_type: nil },
|
||||
"Spam" => { name: "spam", resource_type: nil },
|
||||
# This "role" is a weird amalgamation of multiple roles.
|
||||
"Good standing" => :good_standing,
|
||||
"Trusted" => { name: "trusted", resource_type: nil }
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class Role < ApplicationRecord
|
|||
super_admin
|
||||
support_admin
|
||||
suspended
|
||||
spam
|
||||
tag_moderator
|
||||
tech_admin
|
||||
trusted
|
||||
|
|
|
|||
|
|
@ -447,6 +447,7 @@ class User < ApplicationRecord
|
|||
:super_admin?,
|
||||
:support_admin?,
|
||||
:suspended?,
|
||||
:spam?,
|
||||
:tag_moderator?,
|
||||
:tech_admin?,
|
||||
:trusted?,
|
||||
|
|
|
|||
|
|
@ -133,6 +133,10 @@ module Authorizer
|
|||
has_role?(:suspended)
|
||||
end
|
||||
|
||||
def spam?
|
||||
has_role?(:spam)
|
||||
end
|
||||
|
||||
def tag_moderator?(tag: nil)
|
||||
# Note a fan of "peeking" into the roles table, which in a way
|
||||
# circumvents the rolify gem. But this was the past implementation.
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ module Moderator
|
|||
)
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def handle_user_status(role, note)
|
||||
case role
|
||||
when "Admin"
|
||||
|
|
@ -69,6 +70,9 @@ module Moderator
|
|||
when "Suspended" || "Spammer"
|
||||
user.add_role(:suspended)
|
||||
remove_privileges
|
||||
when "Spam"
|
||||
user.add_role(:spam)
|
||||
remove_privileges
|
||||
when "Super Moderator"
|
||||
assign_elevated_role_to_user(user, :super_moderator)
|
||||
TagModerators::AddTrustedRole.call(user)
|
||||
|
|
@ -95,6 +99,7 @@ module Moderator
|
|||
end
|
||||
create_note(role, note)
|
||||
end
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
def assign_elevated_role_to_user(user, role)
|
||||
check_super_admin
|
||||
|
|
@ -129,13 +134,15 @@ module Moderator
|
|||
|
||||
def warned
|
||||
user.add_role(:warned)
|
||||
user.remove_role(:suspended)
|
||||
user.remove_role(:suspended) if user.suspended?
|
||||
user.remove_role(:spam) if user.spam?
|
||||
remove_privileges
|
||||
end
|
||||
|
||||
def remove_negative_roles
|
||||
user.remove_role(:limited) if user.limited?
|
||||
user.remove_role(:suspended) if user.suspended?
|
||||
user.remove_role(:spam) if user.spam?
|
||||
user.remove_role(:warned) if user.warned?
|
||||
user.remove_role(:comment_suspended) if user.comment_suspended?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -401,6 +401,7 @@ en:
|
|||
Comment Suspended: Comment Suspended
|
||||
Limited: Limited
|
||||
Suspended: Suspended
|
||||
Spam: Spam
|
||||
Good Standing: Good Standing
|
||||
Good standing: Good standing
|
||||
Trusted: Trusted
|
||||
|
|
|
|||
|
|
@ -399,6 +399,7 @@ fr:
|
|||
Comment Suspended: Comment Suspended
|
||||
Limited: Limited
|
||||
Suspended: Suspended
|
||||
Spam: Spam
|
||||
Good Standing: Good Standing
|
||||
Good standing: Good standing
|
||||
Trusted: Trusted
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ RSpec.describe Role do
|
|||
it "contains the correct values" do
|
||||
expected_roles = %w[
|
||||
admin codeland_admin comment_suspended limited podcast_admin
|
||||
restricted_liquid_tag single_resource_admin super_admin support_admin suspended tag_moderator tech_admin
|
||||
restricted_liquid_tag single_resource_admin super_admin support_admin suspended spam tag_moderator tech_admin
|
||||
trusted warned creator super_moderator
|
||||
]
|
||||
expect(described_class::ROLES).to match_array(expected_roles)
|
||||
|
|
|
|||
|
|
@ -278,5 +278,32 @@ RSpec.describe "Moderations" do
|
|||
end.to change(AuditLog, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "when adding the spam role to the user" do
|
||||
it "creates a note on a user when note content is provided" do
|
||||
note_content = "Spam acount"
|
||||
expect do
|
||||
patch "/admin/member_manager/users/#{article.user_id}/user_status",
|
||||
params: { user: { user_status: "Spam", note_for_current_role: note_content } }
|
||||
end.to change(Note, :count).by(1)
|
||||
expect(Note.last.content).to eq(note_content)
|
||||
end
|
||||
|
||||
it "creates a default note on a user when note content isn't provided" do
|
||||
expected_note = "#{super_mod.username} updated #{article.user.username}"
|
||||
expect do
|
||||
patch "/admin/member_manager/users/#{article.user_id}/user_status",
|
||||
params: { user: { user_status: "Spam" } }
|
||||
end.to change(Note, :count).by(1)
|
||||
expect(Note.last.content).to eq(expected_note)
|
||||
end
|
||||
|
||||
it "creates an AuditLog for the action taken" do
|
||||
expect do
|
||||
patch "/admin/member_manager/users/#{article.user_id}/user_status",
|
||||
params: { user: { user_status: "Spam", new_note: "Test note" } }
|
||||
end.to change(AuditLog, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,6 +46,16 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
|
|||
end
|
||||
end
|
||||
|
||||
context "when user is in spam role" do
|
||||
before { user.add_role(:spam) }
|
||||
|
||||
it "adding #{status} also removes the spam role" do
|
||||
expect(user.roles.pluck(:name)).to include("spam") # confirm assumptions
|
||||
manage_roles_for user, user_status: status
|
||||
expect(user.roles.pluck(:name)).not_to include("spam") # confirm assumptions
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is in comment_suspended role" do
|
||||
before { user.add_role(:comment_suspended) }
|
||||
|
||||
|
|
@ -138,17 +148,24 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
|
|||
it_behaves_like "elevated role", "Tech Admin"
|
||||
|
||||
it_behaves_like "negative role", "Suspended"
|
||||
it_behaves_like "negative role", "Spam"
|
||||
it_behaves_like "negative role", "Limited"
|
||||
it_behaves_like "negative role", "Warned"
|
||||
|
||||
context "when user is in suspended role" do
|
||||
before { user.add_role(:suspended) }
|
||||
|
||||
it "adding warned removes the suspended role" do
|
||||
user.add_role(:suspended)
|
||||
expect(user.roles.pluck(:name)).to include("suspended") # confirm assumptions
|
||||
manage_roles_for user, user_status: "Warned"
|
||||
expect(user.roles.pluck(:name)).not_to include("suspended") # confirm assumptions
|
||||
end
|
||||
|
||||
it "adding warned removes the spam role" do
|
||||
user.add_role(:spam)
|
||||
expect(user.roles.pluck(:name)).to include("spam")
|
||||
manage_roles_for user, user_status: "Warned"
|
||||
expect(user.roles.pluck(:name)).not_to include("spam")
|
||||
end
|
||||
end
|
||||
|
||||
it "updates user status to limited" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue