From c043d3b37636e1eb115230bfd60e50b133ff5a26 Mon Sep 17 00:00:00 2001 From: Jacob Herrington Date: Fri, 9 Apr 2021 10:59:56 -0500 Subject: [PATCH] Rename unidiomatic methods (#13328) --- .../notification_subscriptions_controller.rb | 6 +++--- app/policies/api_secret_policy.rb | 4 ++-- app/policies/application_policy.rb | 2 +- app/policies/article_policy.rb | 8 ++++---- app/policies/chat_channel_policy.rb | 12 ++++++------ app/policies/comment_policy.rb | 18 +++++++++--------- app/policies/follow_policy.rb | 4 ++-- app/policies/listing_policy.rb | 6 +++--- app/policies/message_policy.rb | 4 ++-- app/policies/response_template_policy.rb | 14 +++++++------- .../welcome_notification/generator.rb | 4 ++-- app/services/users/remove_role.rb | 4 ++-- 12 files changed, 43 insertions(+), 43 deletions(-) diff --git a/app/controllers/notification_subscriptions_controller.rb b/app/controllers/notification_subscriptions_controller.rb index 83582322e..1f1d5817a 100644 --- a/app/controllers/notification_subscriptions_controller.rb +++ b/app/controllers/notification_subscriptions_controller.rb @@ -21,10 +21,10 @@ class NotificationSubscriptionsController < ApplicationController if params[:config] == "not_subscribed" @notification_subscription.delete - @notification_subscription.notifiable.update(receive_notifications: false) if current_user_is_author? + @notification_subscription.notifiable.update(receive_notifications: false) if current_user_author? else @notification_subscription.config = params[:config] || "all_comments" - receive_notifications = (params[:config] == "all_comments" && current_user_is_author?) + receive_notifications = (params[:config] == "all_comments" && current_user_author?) @notification_subscription.notifiable.update(receive_notifications: true) if receive_notifications @notification_subscription.save end @@ -37,7 +37,7 @@ class NotificationSubscriptionsController < ApplicationController private - def current_user_is_author? + def current_user_author? # TODO: think of a better solution for handling mute notifications in dashboard / manage current_user.id == @notification_subscription.notifiable.user_id end diff --git a/app/policies/api_secret_policy.rb b/app/policies/api_secret_policy.rb index a916af811..7d9b6c68a 100644 --- a/app/policies/api_secret_policy.rb +++ b/app/policies/api_secret_policy.rb @@ -4,7 +4,7 @@ class ApiSecretPolicy < ApplicationPolicy end def destroy? - user_is_owner? + user_owner? end def permitted_attributes @@ -13,7 +13,7 @@ class ApiSecretPolicy < ApplicationPolicy private - def user_is_owner? + def user_owner? user.id == record.user_id end end diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 9881e44a5..f704132ef 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -73,7 +73,7 @@ class ApplicationPolicy delegate :suspended?, to: :user, prefix: true - def user_is_trusted? + def user_trusted? user.has_role?(:trusted) end end diff --git a/app/policies/article_policy.rb b/app/policies/article_policy.rb index cca5b1af2..cf1c9ced3 100644 --- a/app/policies/article_policy.rb +++ b/app/policies/article_policy.rb @@ -1,6 +1,6 @@ class ArticlePolicy < ApplicationPolicy def update? - user_is_author? || user_admin? || user_org_admin? || minimal_admin? + user_author? || user_admin? || user_org_admin? || minimal_admin? end def admin_unpublish? @@ -28,7 +28,7 @@ class ArticlePolicy < ApplicationPolicy end def stats? - user_is_author? || user_admin? + user_author? || user_admin? end def permitted_attributes @@ -39,12 +39,12 @@ class ArticlePolicy < ApplicationPolicy end def subscriptions? - user_is_author? || user_admin? + user_author? || user_admin? end private - def user_is_author? + def user_author? if record.instance_of?(Article) record.user_id == user.id else diff --git a/app/policies/chat_channel_policy.rb b/app/policies/chat_channel_policy.rb index ec114d77f..1cd1d9774 100644 --- a/app/policies/chat_channel_policy.rb +++ b/app/policies/chat_channel_policy.rb @@ -8,7 +8,7 @@ class ChatChannelPolicy < ApplicationPolicy end def update? - user_can_edit_channel + user_can_edit_channel? end def moderate? @@ -32,11 +32,11 @@ class ChatChannelPolicy < ApplicationPolicy end def block_chat? - user_part_of_channel && channel_is_direct + user_part_of_channel && channel_direct? end def update_channel? - user_can_edit_channel + user_can_edit_channel? end def join_channel_invitation? @@ -44,7 +44,7 @@ class ChatChannelPolicy < ApplicationPolicy end def set_channel? - user_can_edit_channel + user_can_edit_channel? end def joining_invitation_response? @@ -57,7 +57,7 @@ class ChatChannelPolicy < ApplicationPolicy private - def user_can_edit_channel + def user_can_edit_channel? record.present? && (user.has_role?(:super_admin) || record.channel_mod_ids.include?(user.id)) && !record.private_org_channel? @@ -71,7 +71,7 @@ class ChatChannelPolicy < ApplicationPolicy record.present? && record.has_member?(user) end - def channel_is_direct + def channel_direct? record.channel_type == "direct" end diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index a3d7936ea..c5dfaa8d1 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -1,10 +1,10 @@ class CommentPolicy < ApplicationPolicy def edit? - user_is_author? + user_author? end def create? - !user_suspended? && !user.comment_suspended? && !user_is_blocked? + !user_suspended? && !user.comment_suspended? && !user_blocked? end def update? @@ -28,15 +28,15 @@ class CommentPolicy < ApplicationPolicy end def moderator_create? - !user_is_blocked? && (user_is_moderator? || minimal_admin?) + !user_blocked? && (user_moderator? || minimal_admin?) end def hide? - user_is_commentable_author? + user_commentable_author? end def unhide? - user_is_commentable_author? + user_commentable_author? end def admin_delete? @@ -61,21 +61,21 @@ class CommentPolicy < ApplicationPolicy private - def user_is_moderator? + def user_moderator? user.moderator_for_tags.present? end - def user_is_author? + def user_author? record.user_id == user.id end - def user_is_blocked? + def user_blocked? return false if user.blocked_by_count.zero? UserBlock.blocking?(record.commentable.user_id, user.id) end - def user_is_commentable_author? + def user_commentable_author? record.commentable.present? && record.commentable.user_id == user.id end end diff --git a/app/policies/follow_policy.rb b/app/policies/follow_policy.rb index 7f78290b2..7ed2a87ea 100644 --- a/app/policies/follow_policy.rb +++ b/app/policies/follow_policy.rb @@ -7,7 +7,7 @@ class FollowPolicy < ApplicationPolicy # record is an object of ActiveRecord_Relation def bulk_update? - record.all? { |follow| user_is_follower?(follow) } + record.all? { |follow| user_follower?(follow) } end def permitted_attributes @@ -16,7 +16,7 @@ class FollowPolicy < ApplicationPolicy private - def user_is_follower?(follow) + def user_follower?(follow) follow.follower_id == user.id && follow.follower_type == "User" end end diff --git a/app/policies/listing_policy.rb b/app/policies/listing_policy.rb index b966db1f5..d94d0cd70 100644 --- a/app/policies/listing_policy.rb +++ b/app/policies/listing_policy.rb @@ -1,10 +1,10 @@ class ListingPolicy < ApplicationPolicy def edit? - user_is_author? || authorized_organization_admin_editor? + user_author? || authorized_organization_admin_editor? end def update? - user_is_author? || authorized_organization_admin_editor? + user_author? || authorized_organization_admin_editor? end def authorized_organization_poster? @@ -21,7 +21,7 @@ class ListingPolicy < ApplicationPolicy private - def user_is_author? + def user_author? record.user_id == user.id end diff --git a/app/policies/message_policy.rb b/app/policies/message_policy.rb index 042066ea5..a735c75e1 100644 --- a/app/policies/message_policy.rb +++ b/app/policies/message_policy.rb @@ -4,7 +4,7 @@ class MessagePolicy < ApplicationPolicy end def destroy? - user_is_sender? + user_sender? end def update? @@ -17,7 +17,7 @@ class MessagePolicy < ApplicationPolicy private - def user_is_sender? + def user_sender? record.user_id == user.id end end diff --git a/app/policies/response_template_policy.rb b/app/policies/response_template_policy.rb index c1f314b9f..ef88a297c 100644 --- a/app/policies/response_template_policy.rb +++ b/app/policies/response_template_policy.rb @@ -10,7 +10,7 @@ class ResponseTemplatePolicy < ApplicationPolicy end def moderator_index? - user_is_moderator? + user_moderator? end def create? @@ -19,15 +19,15 @@ class ResponseTemplatePolicy < ApplicationPolicy # comes from comments_controller def moderator_create? - user_is_moderator? && record_is_mod_comment? + user_moderator? && mod_comment? end def destroy? - user_is_owner? + user_owner? end def update? - user_is_owner? + user_owner? end def permitted_attributes_for_create @@ -40,15 +40,15 @@ class ResponseTemplatePolicy < ApplicationPolicy private - def user_is_owner? + def user_owner? user.id == record.user_id end - def user_is_moderator? + def user_moderator? minimal_admin? || user.moderator_for_tags&.present? end - def record_is_mod_comment? + def mod_comment? record.type_of == "mod_comment" end end diff --git a/app/services/broadcasts/welcome_notification/generator.rb b/app/services/broadcasts/welcome_notification/generator.rb index 8831f5031..e753ed278 100644 --- a/app/services/broadcasts/welcome_notification/generator.rb +++ b/app/services/broadcasts/welcome_notification/generator.rb @@ -51,7 +51,7 @@ module Broadcasts def send_feed_customization_notification return if user.created_at > 3.days.ago || - user_is_following_tags? || + user_following_tags? || received_notification?(customize_feed_broadcast) Notification.send_welcome_notification(user.id, customize_feed_broadcast.id) @@ -98,7 +98,7 @@ module Broadcasts (ga_providers - enabled_providers).empty? end - def user_is_following_tags? + def user_following_tags? user.cached_followed_tag_names.count > 1 end diff --git a/app/services/users/remove_role.rb b/app/services/users/remove_role.rb index b6a1e24ac..d7920e500 100644 --- a/app/services/users/remove_role.rb +++ b/app/services/users/remove_role.rb @@ -16,7 +16,7 @@ module Users def call return response if super_admin_role?(role) - return response if user_is_current_user?(user) + return response if user_current_user?(user) if resource_type && user.remove_role(role, resource_type) response.success = true @@ -40,7 +40,7 @@ module Users true end - def user_is_current_user?(user) + def user_current_user?(user) return false if user.id != admin.id response.error_message = "Admins cannot remove roles from themselves."