DEV: Apply new Rubocop linting on services
This commit is contained in:
parent
a52b83333e
commit
cf2b4d9934
|
@ -465,7 +465,7 @@ GEM
|
|||
parser (>= 3.3.1.0)
|
||||
rubocop-capybara (2.21.0)
|
||||
rubocop (~> 1.41)
|
||||
rubocop-discourse (3.8.6)
|
||||
rubocop-discourse (3.9.0)
|
||||
activesupport (>= 6.1)
|
||||
rubocop (>= 1.59.0)
|
||||
rubocop-capybara (>= 2.0.0)
|
||||
|
|
|
@ -4,12 +4,15 @@ class AdminNotices::Dismiss
|
|||
include Service::Base
|
||||
|
||||
policy :invalid_access
|
||||
|
||||
params do
|
||||
attribute :id, :integer
|
||||
|
||||
validates :id, presence: true
|
||||
end
|
||||
|
||||
model :admin_notice, optional: true
|
||||
|
||||
transaction do
|
||||
step :destroy
|
||||
step :reset_problem_check
|
||||
|
|
|
@ -4,10 +4,12 @@ class Experiments::Toggle
|
|||
include Service::Base
|
||||
|
||||
policy :current_user_is_admin
|
||||
|
||||
params do
|
||||
attribute :setting_name, :string
|
||||
validates :setting_name, presence: true
|
||||
end
|
||||
|
||||
policy :setting_is_available
|
||||
transaction { step :toggle }
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ class Flags::CreateFlag
|
|||
include Service::Base
|
||||
|
||||
policy :invalid_access
|
||||
|
||||
params do
|
||||
attribute :name, :string
|
||||
attribute :description, :string
|
||||
|
@ -18,8 +19,10 @@ class Flags::CreateFlag
|
|||
validates :description, length: { maximum: Flag::MAX_DESCRIPTION_LENGTH }
|
||||
validates :applies_to, inclusion: { in: -> { Flag.valid_applies_to_types } }, allow_nil: false
|
||||
end
|
||||
|
||||
policy :unique_name
|
||||
model :flag, :instantiate_flag
|
||||
|
||||
transaction do
|
||||
step :create
|
||||
step :log
|
||||
|
|
|
@ -8,10 +8,12 @@ class Flags::DestroyFlag
|
|||
|
||||
validates :id, presence: true
|
||||
end
|
||||
|
||||
model :flag
|
||||
policy :not_system
|
||||
policy :not_used
|
||||
policy :invalid_access
|
||||
|
||||
transaction do
|
||||
step :destroy
|
||||
step :log
|
||||
|
|
|
@ -10,10 +10,12 @@ class Flags::ReorderFlag
|
|||
validates :flag_id, presence: true
|
||||
validates :direction, inclusion: { in: %w[up down] }
|
||||
end
|
||||
|
||||
model :flag
|
||||
policy :invalid_access
|
||||
model :all_flags
|
||||
policy :invalid_move
|
||||
|
||||
transaction do
|
||||
step :move
|
||||
step :log
|
||||
|
|
|
@ -4,12 +4,15 @@ class Flags::ToggleFlag
|
|||
include Service::Base
|
||||
|
||||
policy :invalid_access
|
||||
|
||||
params do
|
||||
attribute :flag_id, :integer
|
||||
|
||||
validates :flag_id, presence: true
|
||||
end
|
||||
|
||||
model :flag
|
||||
|
||||
transaction do
|
||||
step :toggle
|
||||
step :log
|
||||
|
|
|
@ -19,11 +19,13 @@ class Flags::UpdateFlag
|
|||
validates :description, length: { maximum: Flag::MAX_DESCRIPTION_LENGTH }
|
||||
validates :applies_to, inclusion: { in: -> { Flag.valid_applies_to_types } }, allow_nil: false
|
||||
end
|
||||
|
||||
model :flag
|
||||
policy :not_system
|
||||
policy :not_used
|
||||
policy :invalid_access
|
||||
policy :unique_name
|
||||
|
||||
transaction do
|
||||
step :update
|
||||
step :log
|
||||
|
|
|
@ -6,6 +6,7 @@ class SiteSetting::Update
|
|||
options { attribute :allow_changing_hidden, :boolean, default: false }
|
||||
|
||||
policy :current_user_is_admin
|
||||
|
||||
params do
|
||||
attribute :setting_name
|
||||
attribute :new_value
|
||||
|
@ -34,6 +35,7 @@ class SiteSetting::Update
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
policy :setting_is_visible
|
||||
policy :setting_is_configurable
|
||||
step :save
|
||||
|
|
|
@ -19,6 +19,7 @@ class User::Silence
|
|||
validates :other_user_ids, length: { maximum: User::MAX_SIMILAR_USERS }
|
||||
validates :post_action, inclusion: { in: %w[delete delete_replies edit] }, allow_blank: true
|
||||
end
|
||||
|
||||
model :user
|
||||
policy :not_silenced_already, class_name: User::Policy::NotAlreadySilenced
|
||||
model :users
|
||||
|
|
|
@ -19,6 +19,7 @@ class User::Suspend
|
|||
validates :other_user_ids, length: { maximum: User::MAX_SIMILAR_USERS }
|
||||
validates :post_action, inclusion: { in: %w[delete delete_replies edit] }, allow_blank: true
|
||||
end
|
||||
|
||||
model :user
|
||||
policy :not_suspended_already, class_name: User::Policy::NotAlreadySuspended
|
||||
model :users
|
||||
|
|
|
@ -24,6 +24,7 @@ module Chat
|
|||
# @option params [Array<String>] :usernames
|
||||
# @option params [Array<String>] :groups
|
||||
# @return [Service::Base::Context]
|
||||
|
||||
params do
|
||||
attribute :usernames, :array
|
||||
attribute :groups, :array
|
||||
|
@ -36,11 +37,13 @@ module Chat
|
|||
usernames.present? || groups.present?
|
||||
end
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :can_add_users_to_channel
|
||||
model :target_users, optional: true
|
||||
policy :satisfies_dms_max_users_limit,
|
||||
class_name: Chat::DirectMessageChannel::Policy::MaxUsersExcess
|
||||
|
||||
transaction do
|
||||
step :upsert_memberships
|
||||
step :recompute_users_count
|
||||
|
|
|
@ -31,6 +31,7 @@ module Chat
|
|||
|
||||
policy :public_channels_enabled
|
||||
policy :can_create_channel
|
||||
|
||||
params do
|
||||
attribute :name, :string
|
||||
attribute :description, :string
|
||||
|
@ -48,12 +49,15 @@ module Chat
|
|||
validates :category_id, presence: true
|
||||
validates :name, length: { maximum: SiteSetting.max_topic_title_length }
|
||||
end
|
||||
|
||||
model :category
|
||||
policy :category_channel_does_not_exist
|
||||
|
||||
transaction do
|
||||
model :channel, :create_channel
|
||||
model :membership, :create_membership
|
||||
end
|
||||
|
||||
step :auto_join_users_if_needed
|
||||
|
||||
private
|
||||
|
|
|
@ -38,6 +38,7 @@ module Chat
|
|||
target_usernames.present? || target_groups.present?
|
||||
end
|
||||
end
|
||||
|
||||
model :target_users
|
||||
policy :can_create_direct_message
|
||||
policy :satisfies_dms_max_users_limit,
|
||||
|
|
|
@ -72,6 +72,7 @@ module Chat
|
|||
policy :ensure_thread_matches_parent
|
||||
model :uploads, optional: true
|
||||
model :message_instance, :instantiate_message
|
||||
|
||||
transaction do
|
||||
step :create_excerpt
|
||||
step :update_created_by_sdk
|
||||
|
@ -83,6 +84,7 @@ module Chat
|
|||
step :update_membership_last_read
|
||||
step :process_direct_message_channel
|
||||
end
|
||||
|
||||
step :publish_new_thread
|
||||
step :process
|
||||
step :publish_user_tracking_state
|
||||
|
|
|
@ -25,14 +25,17 @@ module Chat
|
|||
validates :original_message_id, :channel_id, presence: true
|
||||
validates :title, length: { maximum: Chat::Thread::MAX_TITLE_LENGTH }
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :can_view_channel
|
||||
policy :threading_enabled_for_channel
|
||||
model :original_message
|
||||
|
||||
transaction do
|
||||
model :thread, :find_or_create_thread
|
||||
step :associate_thread_to_message
|
||||
end
|
||||
|
||||
step :publish_new_thread
|
||||
step :trigger_chat_thread_created_event
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ module Chat
|
|||
validates :channel_id, presence: true
|
||||
validates :flag_type_id, inclusion: { in: -> { ::ReviewableScore.types.values } }
|
||||
end
|
||||
|
||||
model :message
|
||||
policy :can_flag_message_in_channel
|
||||
step :flag_message
|
||||
|
|
|
@ -25,6 +25,7 @@ module Chat
|
|||
validates :user_ids, presence: true
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :can_view_channel
|
||||
model :users, optional: true
|
||||
|
|
|
@ -25,6 +25,7 @@ module Chat
|
|||
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :channel
|
||||
step :leave
|
||||
step :recompute_users_count
|
||||
|
|
|
@ -40,6 +40,7 @@ module Chat
|
|||
},
|
||||
allow_nil: true
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :can_view_channel
|
||||
model :membership, optional: true
|
||||
|
|
|
@ -41,6 +41,7 @@ module Chat
|
|||
},
|
||||
allow_nil: true
|
||||
end
|
||||
|
||||
model :thread
|
||||
policy :can_view_thread
|
||||
model :membership, optional: true
|
||||
|
|
|
@ -43,6 +43,7 @@ module Chat
|
|||
self.offset = [offset || 0, 0].max
|
||||
end
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :threading_enabled_for_channel
|
||||
policy :can_view_channel
|
||||
|
|
|
@ -23,6 +23,7 @@ module Chat
|
|||
|
||||
validates :thread_id, :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :thread
|
||||
policy :invalid_access
|
||||
policy :threading_enabled_for_channel
|
||||
|
|
|
@ -30,6 +30,7 @@ module Chat
|
|||
self.offset = [offset || 0, 0].max
|
||||
end
|
||||
end
|
||||
|
||||
model :threads
|
||||
step :fetch_tracking
|
||||
step :fetch_memberships
|
||||
|
|
|
@ -30,6 +30,7 @@ module Chat
|
|||
|
||||
validates :thread_id, :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :thread
|
||||
policy :threading_enabled_for_channel
|
||||
policy :can_view_channel
|
||||
|
|
|
@ -25,13 +25,16 @@ module Chat
|
|||
validates :message_id, presence: true
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :message
|
||||
policy :invalid_access
|
||||
|
||||
transaction do
|
||||
step :restore_message
|
||||
step :update_last_message_ids
|
||||
step :update_thread_reply_cache
|
||||
end
|
||||
|
||||
step :publish_events
|
||||
|
||||
private
|
||||
|
|
|
@ -27,6 +27,7 @@ module Chat
|
|||
|
||||
after_validation { self.term = term&.downcase&.strip&.gsub(/^[@#]+/, "") }
|
||||
end
|
||||
|
||||
model :memberships, optional: true
|
||||
model :users, optional: true
|
||||
model :groups, optional: true
|
||||
|
|
|
@ -41,6 +41,7 @@ module Chat
|
|||
attribute :include_threads, default: false
|
||||
attribute :include_read, default: true
|
||||
end
|
||||
|
||||
model :report
|
||||
|
||||
private
|
||||
|
|
|
@ -23,13 +23,16 @@ module Chat
|
|||
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :invalid_access
|
||||
|
||||
transaction do
|
||||
step :prevents_slug_collision
|
||||
step :soft_delete_channel
|
||||
step :log_channel_deletion
|
||||
end
|
||||
|
||||
step :enqueue_delete_channel_relations_job
|
||||
|
||||
private
|
||||
|
|
|
@ -25,8 +25,10 @@ module Chat
|
|||
validates :message_id, presence: true
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :message
|
||||
policy :invalid_access
|
||||
|
||||
transaction do
|
||||
step :trash_message
|
||||
step :destroy_notifications
|
||||
|
@ -34,6 +36,7 @@ module Chat
|
|||
step :update_tracking_state
|
||||
step :update_thread_reply_cache
|
||||
end
|
||||
|
||||
step :publish_events
|
||||
|
||||
private
|
||||
|
|
|
@ -25,8 +25,10 @@ module Chat
|
|||
validates :channel_id, presence: true
|
||||
validates :message_ids, length: { minimum: 1, maximum: 200 }
|
||||
end
|
||||
|
||||
model :messages
|
||||
policy :can_delete_all_chat_messages
|
||||
|
||||
transaction do
|
||||
step :trash_messages
|
||||
step :destroy_notifications
|
||||
|
@ -34,6 +36,7 @@ module Chat
|
|||
step :update_tracking_states
|
||||
step :update_thread_reply_cache
|
||||
end
|
||||
|
||||
step :publish_events
|
||||
|
||||
private
|
||||
|
|
|
@ -25,6 +25,7 @@ module Chat
|
|||
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :channel
|
||||
step :unfollow
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ module Chat
|
|||
validates :channel_id, presence: true
|
||||
validates :status, inclusion: { in: Chat::Channel.editable_statuses.keys }
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :check_channel_permission
|
||||
step :change_status
|
||||
|
|
|
@ -44,12 +44,14 @@ module Chat
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
model :message
|
||||
model :uploads, optional: true
|
||||
step :enforce_membership
|
||||
model :membership
|
||||
policy :can_modify_channel_message
|
||||
policy :can_modify_message
|
||||
|
||||
transaction do
|
||||
step :modify_message
|
||||
step :update_excerpt
|
||||
|
|
|
@ -26,6 +26,7 @@ module Chat
|
|||
validates :thread_id, presence: true
|
||||
validates :title, length: { maximum: Chat::Thread::MAX_TITLE_LENGTH }
|
||||
end
|
||||
|
||||
model :thread
|
||||
policy :can_view_channel
|
||||
policy :can_edit_thread
|
||||
|
|
|
@ -37,6 +37,7 @@ module Chat
|
|||
in: Chat::UserChatThreadMembership.notification_levels.values,
|
||||
}
|
||||
end
|
||||
|
||||
model :thread, :fetch_thread
|
||||
policy :can_view_channel
|
||||
policy :threading_enabled_for_channel
|
||||
|
|
|
@ -31,6 +31,7 @@ module Chat
|
|||
|
||||
validates :channel_id, presence: true
|
||||
end
|
||||
|
||||
model :channel
|
||||
policy :can_upsert_draft
|
||||
step :check_thread_exists
|
||||
|
|
|
@ -11,15 +11,18 @@ RSpec.describe Service::StepsInspector do
|
|||
|
||||
model :model
|
||||
policy :policy
|
||||
|
||||
params do
|
||||
attribute :parameter
|
||||
|
||||
validates :parameter, presence: true
|
||||
end
|
||||
|
||||
transaction do
|
||||
step :in_transaction_step_1
|
||||
step :in_transaction_step_2
|
||||
end
|
||||
|
||||
try { step :might_raise }
|
||||
step :final_step
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue