DEV: Apply new Rubocop linting on services

This commit is contained in:
Loïc Guitaut 2024-11-28 16:51:43 +01:00 committed by Loïc Guitaut
parent a52b83333e
commit cf2b4d9934
38 changed files with 68 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -25,6 +25,7 @@ module Chat
validates :channel_id, presence: true
end
model :channel
step :leave
step :recompute_users_count

View File

@ -40,6 +40,7 @@ module Chat
},
allow_nil: true
end
model :channel
policy :can_view_channel
model :membership, optional: true

View File

@ -41,6 +41,7 @@ module Chat
},
allow_nil: true
end
model :thread
policy :can_view_thread
model :membership, optional: true

View File

@ -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

View File

@ -23,6 +23,7 @@ module Chat
validates :thread_id, :channel_id, presence: true
end
model :thread
policy :invalid_access
policy :threading_enabled_for_channel

View File

@ -30,6 +30,7 @@ module Chat
self.offset = [offset || 0, 0].max
end
end
model :threads
step :fetch_tracking
step :fetch_memberships

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -41,6 +41,7 @@ module Chat
attribute :include_threads, default: false
attribute :include_read, default: true
end
model :report
private

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -25,6 +25,7 @@ module Chat
validates :channel_id, presence: true
end
model :channel
step :unfollow

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -31,6 +31,7 @@ module Chat
validates :channel_id, presence: true
end
model :channel
policy :can_upsert_draft
step :check_thread_exists

View File

@ -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