Parenthesis consistency for add_role and remove_role (#12661)

* chore: use consistent code styles for the parenthesis around arguments

* Revert "chore: use consistent code styles for the parenthesis around arguments"

This reverts commit 281c899a5cff0480b182fef45b10ef69979166cb.

* chore: add consistent parenthesis
This commit is contained in:
Ridhwana 2021-02-15 20:35:25 +02:00 committed by GitHub
parent 4ffd9ca7a5
commit 07fcbb6f0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 42 additions and 42 deletions

View file

@ -101,7 +101,7 @@ class ChatChannelsController < ApplicationController
user = User.find_by(username: username)
membership = user&.chat_channel_memberships&.find_by(chat_channel: chat_channel)
if user && membership
user.add_role :banned
user.add_role(:banned)
user.messages.where(chat_channel: chat_channel).delete_all
membership.update(status: "removed_from_channel")
Pusher.trigger(chat_channel.pusher_channels, "user-banned", { userId: user.id }.to_json)
@ -116,7 +116,7 @@ class ChatChannelsController < ApplicationController
when "/unban"
user = User.find_by(username: username)
if user
user.remove_role :banned
user.remove_role(:banned)
render json: { status: "moderation-success", message: "#{username} was unsuspended." }, status: :ok
else
render json: {

View file

@ -25,15 +25,15 @@ module Moderator
end
def remove_privileges
@user.remove_role :workshop_pass
@user.remove_role :pro
@user.remove_role(:workshop_pass)
@user.remove_role(:pro)
remove_mod_roles
remove_tag_moderator_role
end
def remove_mod_roles
@user.remove_role :trusted
@user.remove_role :tag_moderator
@user.remove_role(:trusted)
@user.remove_role(:tag_moderator)
@user.update(email_tag_mod_newsletter: false)
Mailchimp::Bot.new(user).manage_tag_moderator_list
@user.update(email_community_mod_newsletter: false)
@ -41,7 +41,7 @@ module Moderator
end
def remove_tag_moderator_role
@user.remove_role :tag_moderator
@user.remove_role(:tag_moderator)
Mailchimp::Bot.new(user).manage_tag_moderator_list
end
@ -58,7 +58,7 @@ module Moderator
def handle_user_status(role, note)
case role
when "Suspend" || "Spammer"
user.add_role :banned
user.add_role(:banned)
remove_privileges
when "Warn"
warned
@ -68,20 +68,20 @@ module Moderator
regular_member
when "Trusted"
remove_negative_roles
user.remove_role :pro
user.remove_role(:pro)
TagModerators::AddTrustedRole.call(user)
when "Admin"
check_super_admin
remove_negative_roles
user.add_role :admin
user.add_role(:admin)
when "Super Admin"
check_super_admin
remove_negative_roles
user.add_role :super_admin
user.add_role(:super_admin)
when "Tech Admin"
check_super_admin
remove_negative_roles
user.add_role :tech_admin
user.add_role(:tech_admin)
# DataUpdateScripts falls under the admin namespace
# and hence requires a single_resource_admin role to view
# this technical admin resource
@ -93,7 +93,7 @@ module Moderator
when "Pro"
remove_negative_roles
TagModerators::AddTrustedRole.call(user)
user.add_role :pro
user.add_role(:pro)
end
create_note(role, note)
end
@ -103,27 +103,27 @@ module Moderator
end
def comment_banned
user.add_role :comment_banned
user.remove_role :banned
user.add_role(:comment_banned)
user.remove_role(:banned)
remove_privileges
end
def regular_member
remove_negative_roles
user.remove_role :pro
user.remove_role(:pro)
remove_mod_roles
end
def warned
user.add_role :warned
user.remove_role :banned
user.add_role(:warned)
user.remove_role(:banned)
remove_privileges
end
def remove_negative_roles
user.remove_role :banned if user.banned
user.remove_role :warned if user.warned
user.remove_role :comment_banned if user.comment_banned
user.remove_role(:banned) if user.banned
user.remove_role(:warned) if user.warned
user.remove_role(:comment_banned) if user.comment_banned
end
def update_trusted_cache

View file

@ -26,7 +26,7 @@ purpose. For example, if you needed to give a user access to only
```ruby
user = User.find(some_user_id)
user.add_role :single_resource_admin, Welcome
user.add_role(:single_resource_admin, Welcome)
```
This gives the user administration privileges on the controller associated with

View file

@ -41,7 +41,7 @@ rails console
> user.has_role? :pro
=> false
> user.add_role :pro
> user.add_role(:pro)
=> #<Role:
...
name: "pro"

View file

@ -100,7 +100,7 @@ FactoryBot.define do
end
trait :pro do
after(:build) { |user| user.add_role :pro }
after(:build) { |user| user.add_role(:pro) }
end
trait :org_member do
@ -144,7 +144,7 @@ FactoryBot.define do
trait :tag_moderator do
after(:create) do |user|
tag = create(:tag)
user.add_role :tag_moderator, tag
user.add_role(:tag_moderator, tag)
end
end

View file

@ -60,7 +60,7 @@ RSpec.describe CommentPolicy, type: :policy do
end
context "when user is an admin or super_admin" do
before { user.add_role :admin }
before { user.add_role(:admin) }
it { is_expected.to permit_actions(%i[create moderator_create admin_delete]) }

View file

@ -18,8 +18,8 @@ RSpec.describe "/admin/tags/:id/moderator", type: :request do
describe "DELETE /admin/tags/:id/moderator" do
before do
sign_in super_admin
user.add_role :trusted
user.add_role :tag_moderator, tag
user.add_role(:trusted)
user.add_role(:tag_moderator, tag)
end
it "removes the tag moderator role from the user" do

View file

@ -122,7 +122,7 @@ RSpec.describe "Admin::Users", type: :request do
end
it "selects new role for user" do
user.add_role :trusted
user.add_role(:trusted)
user.reload
params = { user: { user_status: "Comment Suspend", note_for_current_role: "comment suspend this user" } }
@ -133,7 +133,7 @@ RSpec.describe "Admin::Users", type: :request do
end
it "selects super admin role when user was banned" do
user.add_role :banned
user.add_role(:banned)
user.reload
params = { user: { user_status: "Super Admin", note_for_current_role: "they deserve it for some reason" } }

View file

@ -260,7 +260,7 @@ RSpec.describe "ChatChannels", type: :request do
context "when user is logged-in and authorized" do
before do
user.add_role :codeland_admin
user.add_role(:codeland_admin)
chat_channel.add_users([user, test_subject])
sign_in user
allow(Pusher).to receive(:trigger).and_return(true)

View file

@ -90,7 +90,7 @@ RSpec.describe "Moderations", type: :request do
let(:article2) { create(:article, tags: "javascript, cool, beans") }
it "shows the option to remove the tag when the article has the tag" do
tag_mod.add_role :trusted
tag_mod.add_role(:trusted)
sign_in tag_mod
get "#{article1.path}/actions_panel"
@ -98,7 +98,7 @@ RSpec.describe "Moderations", type: :request do
end
it "shows the option to add the tag when the article has the tag" do
tag_mod.add_role :trusted
tag_mod.add_role(:trusted)
sign_in tag_mod
get "#{article2.path}/actions_panel"

View file

@ -487,7 +487,7 @@ RSpec.describe "NotificationsIndex", type: :request do
let(:comment) { create(:comment, user_id: user2.id, commentable_id: article.id, commentable_type: "Article") }
before do
user.add_role :trusted
user.add_role(:trusted)
sign_in user
sidekiq_perform_enqueued_jobs do
Notification.send_moderation_notification(comment)
@ -528,7 +528,7 @@ RSpec.describe "NotificationsIndex", type: :request do
let(:comment) { create(:comment, user_id: user2.id, commentable_id: article.id, commentable_type: "Article") }
before do
user.add_role :trusted
user.add_role(:trusted)
user.update(mod_roundrobin_notifications: false)
sign_in user
sidekiq_perform_enqueued_jobs do

View file

@ -102,7 +102,7 @@ RSpec.describe Mailchimp::Bot, type: :service do
it "sends proper information" do
user.update(email_community_mod_newsletter: true)
user.add_role :trusted
user.add_role(:trusted)
SiteConfig.mailchimp_community_moderators_id = "something"
described_class.new(user).manage_community_moderator_list
expect(my_gibbon_client).to have_received(:upsert)

View file

@ -5,7 +5,7 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
let(:admin) { create(:user, :super_admin) }
it "updates user status" do
user.add_role :banned
user.add_role(:banned)
user.reload
described_class.handle_user_roles(
admin: admin,
@ -54,7 +54,7 @@ RSpec.describe Moderator::ManageActivityAndRoles, type: :service do
end
it "updates negative role to positive role" do
user.add_role :comment_banned
user.add_role(:comment_banned)
described_class.handle_user_roles(
admin: admin,
user: user,

View file

@ -27,7 +27,7 @@ RSpec.describe "Admin bans user", type: :system do
def add_tag_moderator_role
tag = FactoryBot.create(:tag)
user.add_role :tag_moderator, tag
user.add_role(:tag_moderator, tag)
end
def unsuspend_user
@ -39,7 +39,7 @@ RSpec.describe "Admin bans user", type: :system do
end
it "checks that the user is warned, has a note, and privileges are removed" do
user.add_role :trusted
user.add_role(:trusted)
add_tag_moderator_role
warn_user
@ -56,7 +56,7 @@ RSpec.describe "Admin bans user", type: :system do
end
it "removes other roles if user is suspended" do
user.add_role :trusted
user.add_role(:trusted)
add_tag_moderator_role
suspend_user
@ -67,7 +67,7 @@ RSpec.describe "Admin bans user", type: :system do
end
it "unbans user" do
user.add_role :banned
user.add_role(:banned)
unsuspend_user
expect(user.has_role?(:banned)).to eq(false)