From 1e21815ce73428f33235effba7d91458b764117b Mon Sep 17 00:00:00 2001 From: Andy Zhao <17884966+Zhao-Andy@users.noreply.github.com> Date: Fri, 7 Aug 2020 22:52:13 -0400 Subject: [PATCH] [deploy] Add new support admin role (#9681) * Add new support admin role * Allow support admins to banish users * Fix spec order for new support admin role --- app/models/role.rb | 1 + app/policies/application_policy.rb | 4 ++++ app/views/admin/users/edit.html.erb | 6 +++--- spec/models/role_spec.rb | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/role.rb b/app/models/role.rb index bc7a5d975..c86a0c5bd 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -12,6 +12,7 @@ class Role < ApplicationRecord super_admin tag_moderator mod_relations_admin + support_admin tech_admin trusted warned diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 275705c5a..c0e856f3e 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -67,6 +67,10 @@ class ApplicationPolicy user.has_role?(:super_admin) end + def support_admin? + user.has_role?(:support_admin) + end + def user_is_banned? user.banned end diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index 20e8ef59a..c52ec5a59 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -129,9 +129,9 @@ <%= form_for(@user, url: banish_admin_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 %> <% end %> - <% elsif current_user.has_role?(:super_admin) %> + <% elsif current_user.has_role?(:super_admin) || current_user.has_role?(:support_admin) %>

This is not a new user. You are only allowed to take this action because you are a - super admin.

+ super admin or a support admin.

This is extremely destructive. Banishing will delete all the user's existing content and change their username to @spam_###.

@@ -140,7 +140,7 @@ <% end %> <% else %> -

This is not a new user so you'll need to contact a super admin to banish this user.

+

This is not a new user. Only super admins or support admins are allowed to banish this user.

<% end %> diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 444d4802d..eba0db7d2 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Role, type: :model do it "contains the correct values" do expected_roles = %w[ admin banned chatroom_beta_tester codeland_admin comment_banned podcast_admin pro restricted_liquid_tag - single_resource_admin super_admin tag_moderator mod_relations_admin tech_admin trusted + single_resource_admin super_admin tag_moderator mod_relations_admin support_admin tech_admin trusted warned workshop_pass ] expect(described_class::ROLES).to eq(expected_roles)