Rename base_roles ui labels (#17938)

* rename base_roles ui labels

* update some specs

* fix missed strings in cypress spec
This commit is contained in:
Suzanne Aitchison 2022-06-21 16:17:35 +01:00 committed by GitHub
parent bb4f8fa2b5
commit 26077f3e1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 31 deletions

View file

@ -1,13 +1,13 @@
module Admin
module UsersHelper
def role_options(logged_in_user)
options = { "Base Roles" => Constants::Role::BASE_ROLES }
options = { "Statuses" => Constants::Role::BASE_ROLES }
if logged_in_user.super_admin?
special_roles = Constants::Role::SPECIAL_ROLES
if FeatureFlag.enabled?(:moderator_role)
special_roles = special_roles.dup << "Moderator"
end
options["Special Roles"] = special_roles
options["Roles"] = special_roles
end
options
end

View file

@ -1,10 +1,10 @@
module Constants
module Role
BASE_ROLES = [
"Warn",
"Comment Suspend",
"Suspend",
"Regular Member",
"Warned",
"Comment Suspended",
"Suspended",
"Good standing",
"Trusted",
].freeze

View file

@ -17,7 +17,7 @@ module Moderator
BanishedUser.create(username: user.username, banished_by: admin)
user.remove_from_mailchimp_newsletters if user.email?
remove_profile_info
handle_user_status("Suspend", I18n.t("services.moderator.banish_user.spam_account"))
handle_user_status("Suspended", I18n.t("services.moderator.banish_user.spam_account"))
delete_user_activity
delete_comments
delete_articles

View file

@ -59,15 +59,15 @@ module Moderator
when "Admin"
assign_elevated_role_to_user(user, :admin)
TagModerators::AddTrustedRole.call(user)
when "Comment Suspend"
when "Comment Suspended"
comment_suspended
when "Suspend" || "Spammer"
when "Suspended" || "Spammer"
user.add_role(:suspended)
remove_privileges
when "Moderator"
assign_elevated_role_to_user(user, :moderator)
TagModerators::AddTrustedRole.call(user)
when "Regular Member"
when "Good standing"
regular_member
when /^(Resource Admin: )/
check_super_admin
@ -85,7 +85,7 @@ module Moderator
when "Trusted"
remove_negative_roles
TagModerators::AddTrustedRole.call(user)
when "Warn"
when "Warned"
warned
end
create_note(role, note)

View file

@ -27,14 +27,14 @@ describe('Manage User Roles', () => {
cy.visit('/admin/member_manager/users/2');
});
it('Remove other roles and add a note when Warn role added', () => {
it('Remove other roles and add a note when Warned role added', () => {
checkUserStatus('Trusted');
cy.findByRole('button', { name: 'Remove role: Trusted' }).should(
'exist',
);
openRolesModal().within(() => {
cy.findByRole('combobox', { name: 'Role' }).select('Warn');
cy.findByRole('combobox', { name: 'Role' }).select('Warned');
cy.findByRole('textbox', { name: 'Add a note to this action:' }).type(
'some reason',
);
@ -57,13 +57,13 @@ describe('Manage User Roles', () => {
.click();
cy.findByText('some reason').should('exist');
cy.findByText(/Warn by/).should('exist');
cy.findByText(/Warned by/).should('exist');
});
it('should remove other roles & add a note when Suspend role added', () => {
cy.findByRole('button', { name: 'Remove role: Trusted' });
openRolesModal().within(() => {
cy.findByRole('combobox', { name: 'Role' }).select('Suspend');
cy.findByRole('combobox', { name: 'Role' }).select('Suspended');
cy.findByRole('textbox', { name: 'Add a note to this action:' }).type(
'some reason',
);
@ -86,7 +86,7 @@ describe('Manage User Roles', () => {
.findByRole('link', { name: 'Notes' })
.click();
cy.findByText('some reason').should('exist');
cy.findByText(/Suspend by/).should('exist');
cy.findByText(/Suspended by/).should('exist');
});
it('should remove a role', () => {
@ -132,7 +132,7 @@ describe('Manage User Roles', () => {
cy.findByText('No roles assigned yet.').should('be.visible');
openRolesModal().within(() => {
cy.findByRole('combobox', { name: 'Role' }).select('Warn');
cy.findByRole('combobox', { name: 'Role' }).select('Warned');
cy.findByRole('button', { name: 'Add' }).click();
cy.findByRole('button', { name: 'Close' }).click();
});
@ -147,7 +147,7 @@ describe('Manage User Roles', () => {
cy.findByText('No roles assigned yet.').should('be.visible');
openRolesModal().within(() => {
cy.findByRole('combobox', { name: 'Role' }).select('Warn');
cy.findByRole('combobox', { name: 'Role' }).select('Warned');
cy.findByRole('textbox', { name: 'Add a note to this action:' }).type(
'some reason',
);
@ -163,7 +163,9 @@ describe('Manage User Roles', () => {
);
openRolesModal().within(() => {
cy.findByRole('combobox', { name: 'Role' }).select('Comment Suspend');
cy.findByRole('combobox', { name: 'Role' }).select(
'Comment Suspended',
);
cy.findByRole('textbox', { name: 'Add a note to this action:' }).type(
'some reason',
);

View file

@ -4,18 +4,18 @@ describe Admin::UsersHelper do
describe "#role_options" do
let(:user) { create(:user) }
it "returns base roles", :aggregate_failures do
it "returns base roles as statuses", :aggregate_failures do
user.add_role(:admin)
roles = helper.role_options(user)
expect(roles).to have_key("Base Roles")
expect(roles["Base Roles"]).to eq Constants::Role::BASE_ROLES
expect(roles).to have_key("Statuses")
expect(roles["Statuses"]).to eq Constants::Role::BASE_ROLES
end
it "returns special roles", :aggregate_failures do
it "returns special roles as roles", :aggregate_failures do
user.add_role(:super_admin)
roles = helper.role_options(user)
expect(roles).to have_key("Special Roles")
expect(roles["Special Roles"]).to eq Constants::Role::SPECIAL_ROLES
expect(roles).to have_key("Roles")
expect(roles["Roles"]).to eq Constants::Role::SPECIAL_ROLES
end
it "adds moderator role when feature flag enabled", :aggregate_failures do
@ -23,8 +23,8 @@ describe Admin::UsersHelper do
allow(FeatureFlag).to receive(:enabled?).with(:moderator_role).and_return(true)
roles = helper.role_options(user)
expect(roles).to have_key("Special Roles")
expect(roles["Special Roles"]).to include "Moderator"
expect(roles).to have_key("Roles")
expect(roles["Roles"]).to include "Moderator"
end
end

View file

@ -123,7 +123,7 @@ RSpec.describe "Admin::Users", type: :request do
context "when managing activity and roles" do
it "adds comment suspend role" do
params = { user: { user_status: "Comment Suspend", note_for_current_role: "comment suspend this user" } }
params = { user: { user_status: "Comment Suspended", note_for_current_role: "comment suspend this user" } }
patch user_status_admin_user_path(user.id), params: params
expect(user.roles.first.name).to eq("comment_suspended")
@ -134,7 +134,7 @@ RSpec.describe "Admin::Users", type: :request do
user.add_role(:trusted)
user.reload
params = { user: { user_status: "Comment Suspend", note_for_current_role: "comment suspend this user" } }
params = { user: { user_status: "Comment Suspended", note_for_current_role: "comment suspend this user" } }
patch user_status_admin_user_path(user.id), params: params
expect(user.roles.count).to eq(1)

View file

@ -10,7 +10,7 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
described_class.handle_user_roles(
admin: admin,
user: user,
user_params: { note_for_current_role: "warning user", user_status: "Warn" },
user_params: { note_for_current_role: "warning user", user_status: "Warned" },
)
expect(user.warned?).to be true
expect(user.suspended?).to be false
@ -78,7 +78,7 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
described_class.handle_user_roles(
admin: admin,
user: user,
user_params: { note_for_current_role: "user in good standing", user_status: "Regular Member" },
user_params: { note_for_current_role: "user in good standing", user_status: "Good standing" },
)
expect(user.suspended?).to be false
expect(user.roles.count).to eq(0)