Added limited role (#19969)
* Added limited role * Nit fix * Updated tetss * Added spec tests * Attempt at 100% code coverage * Rollback DB migration * Revert timestamp
This commit is contained in:
parent
98c92bcde2
commit
5ef0f43636
17 changed files with 77 additions and 3 deletions
|
|
@ -52,6 +52,8 @@ module Admin
|
|||
I18n.t("views.admin.users.statuses.Warned")
|
||||
elsif user.comment_suspended?
|
||||
I18n.t("views.admin.users.statuses.Comment Suspended")
|
||||
elsif user.limited?
|
||||
I18n.t("views.admin.users.statuses.Limited")
|
||||
elsif user.trusted?
|
||||
I18n.t("views.admin.users.statuses.Trusted")
|
||||
else
|
||||
|
|
@ -101,6 +103,8 @@ module Admin
|
|||
"#F59E0B"
|
||||
when "Comment Suspended"
|
||||
"#DC2626"
|
||||
when "Limited"
|
||||
"#DC2626"
|
||||
when "Trusted"
|
||||
"#059669"
|
||||
else
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ module Constants
|
|||
BASE_ROLES_LABELS_TO_WHERE_CLAUSE = {
|
||||
"Warned" => { name: "warned", resource_type: nil },
|
||||
"Comment Suspended" => { name: "comment_suspended", resource_type: nil },
|
||||
"Limited" => { name: "limited", resource_type: nil },
|
||||
"Suspended" => { name: "suspended", resource_type: nil },
|
||||
# This "role" is a weird amalgamation of multiple roles.
|
||||
"Good standing" => :good_standing,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class Role < ApplicationRecord
|
|||
trusted
|
||||
warned
|
||||
workshop_pass
|
||||
limited
|
||||
].freeze
|
||||
|
||||
ROLES.each do |role|
|
||||
|
|
|
|||
|
|
@ -417,6 +417,7 @@ class User < ApplicationRecord
|
|||
:auditable?,
|
||||
:banished?,
|
||||
:comment_suspended?,
|
||||
:limited?,
|
||||
:creator?,
|
||||
:has_trusted_role?,
|
||||
:super_moderator?,
|
||||
|
|
@ -602,7 +603,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def set_username
|
||||
self.username = username&.downcase&.presence || generate_username
|
||||
self.username = username&.downcase.presence || generate_username
|
||||
end
|
||||
|
||||
def auth_provider_usernames
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ module Authorizer
|
|||
has_role?(:comment_suspended)
|
||||
end
|
||||
|
||||
def limited?
|
||||
has_role?(:limited)
|
||||
end
|
||||
|
||||
def creator?
|
||||
has_role?(:creator)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ module Admin
|
|||
state: :trusted
|
||||
}.with_indifferent_access.freeze
|
||||
|
||||
POTENTIAL_ROLE_NAMES = %i[comment_suspended suspended trusted warned].freeze
|
||||
POTENTIAL_ROLE_NAMES = %i[comment_suspended limited suspended trusted warned].freeze
|
||||
|
||||
def self.call(relation: User.all, options: {})
|
||||
options = DEFAULT_OPTIONS.merge(options)
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ module Moderator
|
|||
TagModerators::AddTrustedRole.call(user)
|
||||
when "Comment Suspended"
|
||||
comment_suspended
|
||||
when "Limited"
|
||||
limited
|
||||
when "Suspended" || "Spammer"
|
||||
user.add_role(:suspended)
|
||||
remove_privileges
|
||||
|
|
@ -116,6 +118,11 @@ module Moderator
|
|||
remove_privileges
|
||||
end
|
||||
|
||||
def limited
|
||||
user.add_role(:limited)
|
||||
remove_privileges
|
||||
end
|
||||
|
||||
def regular_member
|
||||
remove_negative_roles
|
||||
remove_mod_roles
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
<%= render "admin/users/index/status_indicator", status: "Warned" %>
|
||||
<% elsif user.comment_suspended? %>
|
||||
<%= render "admin/users/index/status_indicator", status: "Comment Suspended" %>
|
||||
<% elsif user.limited? %>
|
||||
<%= render "admin/users/index/status_indicator", status: "Limited" %>
|
||||
<% elsif user.trusted? %>
|
||||
<%= render "admin/users/index/status_indicator", status: "Trusted" %>
|
||||
<% else %>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
<span data-testid="user-status" class="c-indicator c-indicator--warning c-indicator--relaxed"><%= t("views.admin.users.statuses.Warned") %></span>
|
||||
<% elsif user.comment_suspended? %>
|
||||
<span data-testid="user-status" class="c-indicator c-indicator--warning c-indicator--relaxed"><%= t("views.admin.users.statuses.Comment Suspended") %></span>
|
||||
<% elsif user.limited? %>
|
||||
<span data-testid="user-status" class="c-indicator c-indicator--warning c-indicator--relaxed"><%= t("views.admin.users.statuses.Limited") %></span>
|
||||
<% elsif user.trusted? %>
|
||||
<span data-testid="user-status" class="c-indicator c-indicator--success c-indicator--relaxed"><%= t("views.admin.users.statuses.Trusted") %></span>
|
||||
<% else %>
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ en:
|
|||
admin: Admin
|
||||
codeland_admin: Codeland Admin
|
||||
comment_suspended: Comment Suspended
|
||||
limited: Limited
|
||||
creator: Creator
|
||||
mod_relations_admin: Mod Relations Admin
|
||||
super_moderator: Super Moderator
|
||||
|
|
@ -400,6 +401,7 @@ en:
|
|||
statuses:
|
||||
Warned: Warned
|
||||
Comment Suspended: Comment Suspended
|
||||
Limited: Limited
|
||||
Suspended: Suspended
|
||||
Good Standing: Good Standing
|
||||
Good standing: Good standing
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ fr:
|
|||
admin: Admin
|
||||
codeland_admin: Codeland Admin
|
||||
comment_suspended: Comment Suspended
|
||||
limited: Limited
|
||||
creator: Creator
|
||||
mod_relations_admin: Mod Relations Admin
|
||||
super_moderator: Super Moderator
|
||||
|
|
@ -398,6 +399,7 @@ fr:
|
|||
statuses:
|
||||
Warned: Warned
|
||||
Comment Suspended: Comment Suspended
|
||||
Limited: Limited
|
||||
Suspended: Suspended
|
||||
Good Standing: Good Standing
|
||||
Good standing: Good standing
|
||||
|
|
|
|||
|
|
@ -159,6 +159,25 @@ describe('Manage User Roles', () => {
|
|||
cy.findByRole('button', {
|
||||
name: 'Remove role: Comment Suspended',
|
||||
}).should('exist');
|
||||
|
||||
openRolesModal().within(() => {
|
||||
cy.findByRole('combobox', { name: 'Role' }).select('Limited');
|
||||
cy.findByRole('textbox', { name: 'Add a note to this action:' }).type(
|
||||
'some reason',
|
||||
);
|
||||
cy.findByRole('button', { name: 'Add' }).click();
|
||||
});
|
||||
|
||||
cy.getModal().should('not.exist');
|
||||
verifyAndDismissFlashMessage('User has been updated', 'flash-success');
|
||||
checkUserStatus('Warned');
|
||||
|
||||
cy.findByRole('button', { name: 'Remove role: Warned' }).should(
|
||||
'exist',
|
||||
);
|
||||
cy.findByRole('button', {
|
||||
name: 'Remove role: Limited',
|
||||
}).should('exist');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -122,6 +122,10 @@ FactoryBot.define do
|
|||
after(:build) { |user| user.add_role(:comment_suspended) }
|
||||
end
|
||||
|
||||
trait :limited do
|
||||
after(:build) { |user| user.add_role(:limited) }
|
||||
end
|
||||
|
||||
trait :invited do
|
||||
after(:build) do |user|
|
||||
user.registered = false
|
||||
|
|
|
|||
|
|
@ -133,6 +133,12 @@ describe Admin::UsersHelper do
|
|||
expect(status).to eq "Comment Suspended"
|
||||
end
|
||||
|
||||
it "renders the proper status for a user that is limited" do
|
||||
limited_user = create(:user, :limited)
|
||||
status = helper.user_status(limited_user)
|
||||
expect(status).to eq "Limited"
|
||||
end
|
||||
|
||||
it "renders the proper status for a user that is trusted" do
|
||||
trusted_user = create(:user, :trusted)
|
||||
status = helper.user_status(trusted_user)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ RSpec.describe Role do
|
|||
describe "::ROLES" do
|
||||
it "contains the correct values" do
|
||||
expected_roles = %w[
|
||||
admin codeland_admin comment_suspended mod_relations_admin podcast_admin
|
||||
admin codeland_admin comment_suspended limited mod_relations_admin podcast_admin
|
||||
restricted_liquid_tag single_resource_admin super_admin support_admin suspended tag_moderator tech_admin
|
||||
trusted warned workshop_pass creator super_moderator
|
||||
]
|
||||
|
|
|
|||
|
|
@ -130,6 +130,14 @@ RSpec.describe "Admin::Users" do
|
|||
expect(Note.first.content).to eq("comment suspend this user")
|
||||
end
|
||||
|
||||
it "adds limited role" do
|
||||
params = { user: { user_status: "Limited", note_for_current_role: "limited role added" } }
|
||||
patch user_status_admin_user_path(user.id), params: params
|
||||
|
||||
expect(user.roles.first.name).to eq("limited")
|
||||
expect(Note.first.content).to eq("limited role added")
|
||||
end
|
||||
|
||||
it "selects new role for user" do
|
||||
user.add_role(:trusted)
|
||||
user.reload
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
|
|||
expect(user.suspended?).to be false
|
||||
end
|
||||
|
||||
it "updates user status to limited" do
|
||||
user.add_role(:limited)
|
||||
user.reload
|
||||
described_class.handle_user_roles(
|
||||
admin: admin,
|
||||
user: user,
|
||||
user_params: { note_for_current_role: "limited user", user_status: "Limited" },
|
||||
)
|
||||
expect(user.limited?).to be true
|
||||
end
|
||||
|
||||
it "updates user to super admin" do
|
||||
described_class.handle_user_roles(
|
||||
admin: admin,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue