Rename unidiomatic methods (#13328)
This commit is contained in:
parent
8659703305
commit
c043d3b376
12 changed files with 43 additions and 43 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue