Skip to content

Commit

Permalink
AO3-6634 Add board_assistants_team admin role (#4749)
Browse files Browse the repository at this point in the history
* AO3-6634 Add board_assistants_team role

* AO3-6634 Rename SPAM_COMMENT_ROLES to SPAM_WORK_COMMENT_ROLES for clarity

* AO3-6634 Actually no I don't like that, put it back

* AO3-6634 Prefer .nil? to == nil and put in a context block I missed

* AO3-6634 Prefer update! for roles

* AO3-6634 More shared examples

* AO3-6634 Prefer update! for roles
  • Loading branch information
sarken authored Apr 4, 2024
1 parent 321fee4 commit dbcbef8
Show file tree
Hide file tree
Showing 8 changed files with 401 additions and 203 deletions.
2 changes: 1 addition & 1 deletion app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Admin < ApplicationRecord
VALID_ROLES = %w[superadmin board communications development_and_membership elections translation tag_wrangling docs support policy_and_abuse open_doors].freeze
VALID_ROLES = %w[superadmin board board_assistants_team communications development_and_membership docs elections translation tag_wrangling support policy_and_abuse open_doors].freeze

serialize :roles, Array

Expand Down
4 changes: 2 additions & 2 deletions app/policies/admin_banner_policy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AdminBannerPolicy < ApplicationPolicy
ACCESS_AND_EDIT_ROLES = %w[superadmin board communications development_and_membership support].freeze
CREATE_AND_DESTROY_ROLES = %w[superadmin board communications support].freeze
ACCESS_AND_EDIT_ROLES = %w[superadmin board board_assistants_team communications development_and_membership support].freeze
CREATE_AND_DESTROY_ROLES = %w[superadmin board board_assistants_team communications support].freeze

def index?
user_has_roles?(ACCESS_AND_EDIT_ROLES)
Expand Down
2 changes: 1 addition & 1 deletion app/policies/admin_post_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AdminPostPolicy < ApplicationPolicy
POSTING_ROLES = %w[superadmin board communications support translation].freeze
POSTING_ROLES = %w[superadmin board board_assistants_team communications support translation].freeze

def can_post?
user_has_roles?(POSTING_ROLES)
Expand Down
12 changes: 9 additions & 3 deletions app/policies/comment_policy.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class CommentPolicy < ApplicationPolicy
DESTROY_COMMENT_ROLES = %w[superadmin board policy_and_abuse support].freeze
DESTROY_ADMIN_POST_COMMENT_ROLES = %w[superadmin board communications elections policy_and_abuse support].freeze
DESTROY_ADMIN_POST_COMMENT_ROLES = %w[superadmin board board_assistants_team communications elections policy_and_abuse support].freeze
FREEZE_TAG_COMMENT_ROLES = %w[superadmin tag_wrangling].freeze
FREEZE_WORK_COMMENT_ROLES = %w[superadmin policy_and_abuse].freeze
HIDE_TAG_COMMENT_ROLES = %w[superadmin tag_wrangling].freeze
HIDE_WORK_COMMENT_ROLES = %w[superadmin policy_and_abuse].freeze
SPAM_ROLES = %w[superadmin board communications elections policy_and_abuse support].freeze
SPAM_ADMIN_POST_COMMENT_ROLES = %w[superadmin board board_assistants_team communications elections policy_and_abuse support].freeze
SPAM_COMMENT_ROLES = %w[superadmin board policy_and_abuse support].freeze

def can_destroy_comment?
case record.ultimate_parent
Expand Down Expand Up @@ -39,7 +40,12 @@ def can_hide_comment?
end

def can_mark_comment_spam?
user_has_roles?(SPAM_ROLES)
case record.ultimate_parent
when AdminPost
user_has_roles?(SPAM_ADMIN_POST_COMMENT_ROLES)
else
user_has_roles?(SPAM_COMMENT_ROLES)
end
end

alias destroy? can_destroy_comment?
Expand Down
1 change: 1 addition & 0 deletions config/locales/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ en:
attributes:
admin/role:
board: Board
board_assistants_team: Board Assistants Team
communications: Communications
development_and_membership: Development & Membership
docs: AO3 Docs
Expand Down
16 changes: 8 additions & 8 deletions spec/controllers/admin/banners_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications development_and_membership support]
authorized_roles: %w[superadmin board board_assistants_team communications development_and_membership support]
end

describe "GET #show" do
Expand All @@ -61,7 +61,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications development_and_membership support]
authorized_roles: %w[superadmin board board_assistants_team communications development_and_membership support]
end

describe "GET #new" do
Expand All @@ -72,7 +72,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications support]
authorized_roles: %w[superadmin board board_assistants_team communications support]
end

describe "POST #create" do
Expand All @@ -83,7 +83,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications support]
authorized_roles: %w[superadmin board board_assistants_team communications support]
end

describe "GET #edit" do
Expand All @@ -94,7 +94,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications development_and_membership support]
authorized_roles: %w[superadmin board board_assistants_team communications development_and_membership support]
end

describe "PUT #update" do
Expand All @@ -106,7 +106,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications development_and_membership support]
authorized_roles: %w[superadmin board board_assistants_team communications development_and_membership support]
end

describe "GET #confirm_delete" do
Expand All @@ -117,7 +117,7 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications support]
authorized_roles: %w[superadmin board board_assistants_team communications support]
end

describe "DELETE #destroy" do
Expand All @@ -129,6 +129,6 @@
end

it_behaves_like "only authorized admins are allowed",
authorized_roles: %w[superadmin board communications support]
authorized_roles: %w[superadmin board board_assistants_team communications support]
end
end
Loading

0 comments on commit dbcbef8

Please sign in to comment.