A platform for community discussion. Free, open, simple.
DEV: Apply new Rubocop linting on services
Loïc Guitautcf2b4d993428
diff --git a/Gemfile.lock b/Gemfile.lockindex 4797847e1e9..391f6db80f1 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -465,7 +465,7 @@ GEMparser (>= 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)diff --git a/app/services/admin_notices/dismiss.rb b/app/services/admin_notices/dismiss.rbindex defcf52ba22..69567ea1cde 100644--- a/app/services/admin_notices/dismiss.rb+++ b/app/services/admin_notices/dismiss.rb@@ -4,12 +4,15 @@ class AdminNotices::Dismissinclude Service::Basepolicy :invalid_access+params doattribute :id, :integervalidates :id, presence: trueend+model :admin_notice, optional: true+transaction dostep :destroystep :reset_problem_checkdiff --git a/app/services/experiments/toggle.rb b/app/services/experiments/toggle.rbindex 9c63cc1c883..cfb3899ec2b 100644--- a/app/services/experiments/toggle.rb+++ b/app/services/experiments/toggle.rb@@ -4,10 +4,12 @@ class Experiments::Toggleinclude Service::Basepolicy :current_user_is_admin+params doattribute :setting_name, :stringvalidates :setting_name, presence: trueend+policy :setting_is_availabletransaction { step :toggle }diff --git a/app/services/flags/create_flag.rb b/app/services/flags/create_flag.rbindex 98d3b50934e..6f23b396692 100644--- a/app/services/flags/create_flag.rb+++ b/app/services/flags/create_flag.rb@@ -4,6 +4,7 @@ class Flags::CreateFlaginclude Service::Basepolicy :invalid_access+params doattribute :name, :stringattribute :description, :string@@ -18,8 +19,10 @@ class Flags::CreateFlagvalidates :description, length: { maximum: Flag::MAX_DESCRIPTION_LENGTH }validates :applies_to, inclusion: { in: -> { Flag.valid_applies_to_types } }, allow_nil: falseend+policy :unique_namemodel :flag, :instantiate_flag+transaction dostep :createstep :logdiff --git a/app/services/flags/destroy_flag.rb b/app/services/flags/destroy_flag.rbindex abaf3dd0155..6f0153e57b7 100644--- a/app/services/flags/destroy_flag.rb+++ b/app/services/flags/destroy_flag.rb@@ -8,10 +8,12 @@ class Flags::DestroyFlagvalidates :id, presence: trueend+model :flagpolicy :not_systempolicy :not_usedpolicy :invalid_access+transaction dostep :destroystep :logdiff --git a/app/services/flags/reorder_flag.rb b/app/services/flags/reorder_flag.rbindex c680d8ae55e..b1fa5a2405a 100644--- a/app/services/flags/reorder_flag.rb+++ b/app/services/flags/reorder_flag.rb@@ -10,10 +10,12 @@ class Flags::ReorderFlagvalidates :flag_id, presence: truevalidates :direction, inclusion: { in: %w[up down] }end+model :flagpolicy :invalid_accessmodel :all_flagspolicy :invalid_move+transaction dostep :movestep :logdiff --git a/app/services/flags/toggle_flag.rb b/app/services/flags/toggle_flag.rbindex 3b15f257717..06112b3b575 100644--- a/app/services/flags/toggle_flag.rb+++ b/app/services/flags/toggle_flag.rb@@ -4,12 +4,15 @@ class Flags::ToggleFlaginclude Service::Basepolicy :invalid_access+params doattribute :flag_id, :integervalidates :flag_id, presence: trueend+model :flag+transaction dostep :togglestep :logdiff --git a/app/services/flags/update_flag.rb b/app/services/flags/update_flag.rbindex ccd682b65a9..625243dda57 100644--- a/app/services/flags/update_flag.rb+++ b/app/services/flags/update_flag.rb@@ -19,11 +19,13 @@ class Flags::UpdateFlagvalidates :description, length: { maximum: Flag::MAX_DESCRIPTION_LENGTH }validates :applies_to, inclusion: { in: -> { Flag.valid_applies_to_types } }, allow_nil: falseend+model :flagpolicy :not_systempolicy :not_usedpolicy :invalid_accesspolicy :unique_name+transaction dostep :updatestep :logdiff --git a/app/services/site_setting/update.rb b/app/services/site_setting/update.rbindex 89c834d9687..c337b2f78f9 100644--- a/app/services/site_setting/update.rb+++ b/app/services/site_setting/update.rb@@ -6,6 +6,7 @@ class SiteSetting::Updateoptions { attribute :allow_changing_hidden, :boolean, default: false }policy :current_user_is_admin+params doattribute :setting_nameattribute :new_value@@ -34,6 +35,7 @@ class SiteSetting::Updateendendend+policy :setting_is_visiblepolicy :setting_is_configurablestep :savediff --git a/app/services/user/silence.rb b/app/services/user/silence.rbindex 28bbc6d0ade..13b70112c0d 100644--- a/app/services/user/silence.rb+++ b/app/services/user/silence.rb@@ -19,6 +19,7 @@ class User::Silencevalidates :other_user_ids, length: { maximum: User::MAX_SIMILAR_USERS }validates :post_action, inclusion: { in: %w[delete delete_replies edit] }, allow_blank: trueend+model :userpolicy :not_silenced_already, class_name: User::Policy::NotAlreadySilencedmodel :usersdiff --git a/app/services/user/suspend.rb b/app/services/user/suspend.rbindex 235fca39eb3..1802b1c056b 100644--- a/app/services/user/suspend.rb+++ b/app/services/user/suspend.rb@@ -19,6 +19,7 @@ class User::Suspendvalidates :other_user_ids, length: { maximum: User::MAX_SIMILAR_USERS }validates :post_action, inclusion: { in: %w[delete delete_replies edit] }, allow_blank: trueend+model :userpolicy :not_suspended_already, class_name: User::Policy::NotAlreadySuspendedmodel :usersdiff --git a/plugins/chat/app/services/chat/add_users_to_channel.rb b/plugins/chat/app/services/chat/add_users_to_channel.rbindex 628c999e746..1e70f1656fa 100644--- a/plugins/chat/app/services/chat/add_users_to_channel.rb+++ b/plugins/chat/app/services/chat/add_users_to_channel.rb@@ -24,6 +24,7 @@ module Chat# @option params [Array<String>] :usernames# @option params [Array<String>] :groups# @return [Service::Base::Context]+params doattribute :usernames, :arrayattribute :groups, :array@@ -36,11 +37,13 @@ module Chatusernames.present? || groups.present?endend+model :channelpolicy :can_add_users_to_channelmodel :target_users, optional: truepolicy :satisfies_dms_max_users_limit,class_name: Chat::DirectMessageChannel::Policy::MaxUsersExcess+transaction dostep :upsert_membershipsstep :recompute_users_countdiff --git a/plugins/chat/app/services/chat/create_category_channel.rb b/plugins/chat/app/services/chat/create_category_channel.rbindex 64e8c7b3f32..e6dfa61cf8b 100644--- a/plugins/chat/app/services/chat/create_category_channel.rb+++ b/plugins/chat/app/services/chat/create_category_channel.rb@@ -31,6 +31,7 @@ module Chatpolicy :public_channels_enabledpolicy :can_create_channel+params doattribute :name, :stringattribute :description, :string@@ -48,12 +49,15 @@ module Chatvalidates :category_id, presence: truevalidates :name, length: { maximum: SiteSetting.max_topic_title_length }end+model :categorypolicy :category_channel_does_not_exist+transaction domodel :channel, :create_channelmodel :membership, :create_membershipend+step :auto_join_users_if_neededprivatediff --git a/plugins/chat/app/services/chat/create_direct_message_channel.rb b/plugins/chat/app/services/chat/create_direct_message_channel.rbindex 79c28e56a15..6ea4e94475b 100644--- a/plugins/chat/app/services/chat/create_direct_message_channel.rb+++ b/plugins/chat/app/services/chat/create_direct_message_channel.rb@@ -38,6 +38,7 @@ module Chattarget_usernames.present? || target_groups.present?endend+model :target_userspolicy :can_create_direct_messagepolicy :satisfies_dms_max_users_limit,diff --git a/plugins/chat/app/services/chat/create_message.rb b/plugins/chat/app/services/chat/create_message.rbindex 21c6ae80d77..2d4c2aad2a4 100644--- a/plugins/chat/app/services/chat/create_message.rb+++ b/plugins/chat/app/services/chat/create_message.rb@@ -72,6 +72,7 @@ module Chatpolicy :ensure_thread_matches_parentmodel :uploads, optional: truemodel :message_instance, :instantiate_message+transaction dostep :create_excerptstep :update_created_by_sdk@@ -83,6 +84,7 @@ module Chatstep :update_membership_last_readstep :process_direct_message_channelend+step :publish_new_threadstep :processstep :publish_user_tracking_statediff --git a/plugins/chat/app/services/chat/create_thread.rb b/plugins/chat/app/services/chat/create_thread.rbindex 138154c579a..889a9a71482 100644--- a/plugins/chat/app/services/chat/create_thread.rb+++ b/plugins/chat/app/services/chat/create_thread.rb@@ -25,14 +25,17 @@ module Chatvalidates :original_message_id, :channel_id, presence: truevalidates :title, length: { maximum: Chat::Thread::MAX_TITLE_LENGTH }end+model :channelpolicy :can_view_channelpolicy :threading_enabled_for_channelmodel :original_message+transaction domodel :thread, :find_or_create_threadstep :associate_thread_to_messageend+step :publish_new_threadstep :trigger_chat_thread_created_eventdiff --git a/plugins/chat/app/services/chat/flag_message.rb b/plugins/chat/app/services/chat/flag_message.rbindex cf6cfe52876..7817ca62f64 100644--- a/plugins/chat/app/services/chat/flag_message.rb+++ b/plugins/chat/app/services/chat/flag_message.rb@@ -40,6 +40,7 @@ module Chatvalidates :channel_id, presence: truevalidates :flag_type_id, inclusion: { in: -> { ::ReviewableScore.types.values } }end+model :messagepolicy :can_flag_message_in_channelstep :flag_messagediff --git a/plugins/chat/app/services/chat/invite_users_to_channel.rb b/plugins/chat/app/services/chat/invite_users_to_channel.rbindex 06e8c183872..61f6178e9a0 100644--- a/plugins/chat/app/services/chat/invite_users_to_channel.rb+++ b/plugins/chat/app/services/chat/invite_users_to_channel.rb@@ -25,6 +25,7 @@ module Chatvalidates :user_ids, presence: truevalidates :channel_id, presence: trueend+model :channelpolicy :can_view_channelmodel :users, optional: truediff --git a/plugins/chat/app/services/chat/leave_channel.rb b/plugins/chat/app/services/chat/leave_channel.rbindex 83f49017e3d..908d5e528cb 100644--- a/plugins/chat/app/services/chat/leave_channel.rb+++ b/plugins/chat/app/services/chat/leave_channel.rb@@ -25,6 +25,7 @@ module Chatvalidates :channel_id, presence: trueend+model :channelstep :leavestep :recompute_users_countdiff --git a/plugins/chat/app/services/chat/list_channel_messages.rb b/plugins/chat/app/services/chat/list_channel_messages.rbindex 391f2c8cfec..def99e82d8e 100644--- a/plugins/chat/app/services/chat/list_channel_messages.rb+++ b/plugins/chat/app/services/chat/list_channel_messages.rb@@ -40,6 +40,7 @@ module Chat},allow_nil: trueend+model :channelpolicy :can_view_channelmodel :membership, optional: truediff --git a/plugins/chat/app/services/chat/list_channel_thread_messages.rb b/plugins/chat/app/services/chat/list_channel_thread_messages.rbindex c3bacfa8964..4b32e1da752 100644--- a/plugins/chat/app/services/chat/list_channel_thread_messages.rb+++ b/plugins/chat/app/services/chat/list_channel_thread_messages.rb@@ -41,6 +41,7 @@ module Chat},allow_nil: trueend+model :threadpolicy :can_view_threadmodel :membership, optional: truediff --git a/plugins/chat/app/services/chat/lookup_channel_threads.rb b/plugins/chat/app/services/chat/lookup_channel_threads.rbindex f8c34b2c5f8..ce2e8c02452 100644--- a/plugins/chat/app/services/chat/lookup_channel_threads.rb+++ b/plugins/chat/app/services/chat/lookup_channel_threads.rb@@ -43,6 +43,7 @@ module Chatself.offset = [offset || 0, 0].maxendend+model :channelpolicy :threading_enabled_for_channelpolicy :can_view_channeldiff --git a/plugins/chat/app/services/chat/lookup_thread.rb b/plugins/chat/app/services/chat/lookup_thread.rbindex 18738bbcef0..01b9c6eeaf4 100644--- a/plugins/chat/app/services/chat/lookup_thread.rb+++ b/plugins/chat/app/services/chat/lookup_thread.rb@@ -23,6 +23,7 @@ module Chatvalidates :thread_id, :channel_id, presence: trueend+model :threadpolicy :invalid_accesspolicy :threading_enabled_for_channeldiff --git a/plugins/chat/app/services/chat/lookup_user_threads.rb b/plugins/chat/app/services/chat/lookup_user_threads.rbindex eb5a2c10a78..a78a41672cd 100644--- a/plugins/chat/app/services/chat/lookup_user_threads.rb+++ b/plugins/chat/app/services/chat/lookup_user_threads.rb@@ -30,6 +30,7 @@ module Chatself.offset = [offset || 0, 0].maxendend+model :threadsstep :fetch_trackingstep :fetch_membershipsdiff --git a/plugins/chat/app/services/chat/mark_thread_title_prompt_seen.rb b/plugins/chat/app/services/chat/mark_thread_title_prompt_seen.rbindex 2402a23a1d9..bcf57d14b73 100644--- a/plugins/chat/app/services/chat/mark_thread_title_prompt_seen.rb+++ b/plugins/chat/app/services/chat/mark_thread_title_prompt_seen.rb@@ -30,6 +30,7 @@ module Chatvalidates :thread_id, :channel_id, presence: trueend+model :threadpolicy :threading_enabled_for_channelpolicy :can_view_channeldiff --git a/plugins/chat/app/services/chat/restore_message.rb b/plugins/chat/app/services/chat/restore_message.rbindex 65fac0aa9b8..4f171e36c18 100644--- a/plugins/chat/app/services/chat/restore_message.rb+++ b/plugins/chat/app/services/chat/restore_message.rb@@ -25,13 +25,16 @@ module Chatvalidates :message_id, presence: truevalidates :channel_id, presence: trueend+model :messagepolicy :invalid_access+transaction dostep :restore_messagestep :update_last_message_idsstep :update_thread_reply_cacheend+step :publish_eventsprivatediff --git a/plugins/chat/app/services/chat/search_chatable.rb b/plugins/chat/app/services/chat/search_chatable.rbindex abd6a0786a6..bc8c4b24773 100644--- a/plugins/chat/app/services/chat/search_chatable.rb+++ b/plugins/chat/app/services/chat/search_chatable.rb@@ -27,6 +27,7 @@ module Chatafter_validation { self.term = term&.downcase&.strip&.gsub(/^[@#]+/, "") }end+model :memberships, optional: truemodel :users, optional: truemodel :groups, optional: truediff --git a/plugins/chat/app/services/chat/tracking_state.rb b/plugins/chat/app/services/chat/tracking_state.rbindex b4e0b6375bc..0bb711aa88f 100644--- a/plugins/chat/app/services/chat/tracking_state.rb+++ b/plugins/chat/app/services/chat/tracking_state.rb@@ -41,6 +41,7 @@ module Chatattribute :include_threads, default: falseattribute :include_read, default: trueend+model :reportprivatediff --git a/plugins/chat/app/services/chat/trash_channel.rb b/plugins/chat/app/services/chat/trash_channel.rbindex 7bb88a75050..e69d341b81e 100644--- a/plugins/chat/app/services/chat/trash_channel.rb+++ b/plugins/chat/app/services/chat/trash_channel.rb@@ -23,13 +23,16 @@ module Chatvalidates :channel_id, presence: trueend+model :channelpolicy :invalid_access+transaction dostep :prevents_slug_collisionstep :soft_delete_channelstep :log_channel_deletionend+step :enqueue_delete_channel_relations_jobprivatediff --git a/plugins/chat/app/services/chat/trash_message.rb b/plugins/chat/app/services/chat/trash_message.rbindex ac3edc4a250..03365150f9f 100644--- a/plugins/chat/app/services/chat/trash_message.rb+++ b/plugins/chat/app/services/chat/trash_message.rb@@ -25,8 +25,10 @@ module Chatvalidates :message_id, presence: truevalidates :channel_id, presence: trueend+model :messagepolicy :invalid_access+transaction dostep :trash_messagestep :destroy_notifications@@ -34,6 +36,7 @@ module Chatstep :update_tracking_statestep :update_thread_reply_cacheend+step :publish_eventsprivatediff --git a/plugins/chat/app/services/chat/trash_messages.rb b/plugins/chat/app/services/chat/trash_messages.rbindex 3f1e21aaadb..0a6bc6cbd7d 100644--- a/plugins/chat/app/services/chat/trash_messages.rb+++ b/plugins/chat/app/services/chat/trash_messages.rb@@ -25,8 +25,10 @@ module Chatvalidates :channel_id, presence: truevalidates :message_ids, length: { minimum: 1, maximum: 200 }end+model :messagespolicy :can_delete_all_chat_messages+transaction dostep :trash_messagesstep :destroy_notifications@@ -34,6 +36,7 @@ module Chatstep :update_tracking_statesstep :update_thread_reply_cacheend+step :publish_eventsprivatediff --git a/plugins/chat/app/services/chat/unfollow_channel.rb b/plugins/chat/app/services/chat/unfollow_channel.rbindex 49fddd0107d..eb979e98a98 100644--- a/plugins/chat/app/services/chat/unfollow_channel.rb+++ b/plugins/chat/app/services/chat/unfollow_channel.rb@@ -25,6 +25,7 @@ module Chatvalidates :channel_id, presence: trueend+model :channelstep :unfollowdiff --git a/plugins/chat/app/services/chat/update_channel_status.rb b/plugins/chat/app/services/chat/update_channel_status.rbindex fbd84f38e1d..1050b34e4ed 100644--- a/plugins/chat/app/services/chat/update_channel_status.rb+++ b/plugins/chat/app/services/chat/update_channel_status.rb@@ -23,6 +23,7 @@ module Chatvalidates :channel_id, presence: truevalidates :status, inclusion: { in: Chat::Channel.editable_statuses.keys }end+model :channelpolicy :check_channel_permissionstep :change_statusdiff --git a/plugins/chat/app/services/chat/update_message.rb b/plugins/chat/app/services/chat/update_message.rbindex fc4c42f80e3..938e5c1b7a6 100644--- a/plugins/chat/app/services/chat/update_message.rb+++ b/plugins/chat/app/services/chat/update_message.rb@@ -44,12 +44,14 @@ module Chat)endend+model :messagemodel :uploads, optional: truestep :enforce_membershipmodel :membershippolicy :can_modify_channel_messagepolicy :can_modify_message+transaction dostep :modify_messagestep :update_excerptdiff --git a/plugins/chat/app/services/chat/update_thread.rb b/plugins/chat/app/services/chat/update_thread.rbindex 256d57c5a97..46f88cd8b7f 100644--- a/plugins/chat/app/services/chat/update_thread.rb+++ b/plugins/chat/app/services/chat/update_thread.rb@@ -26,6 +26,7 @@ module Chatvalidates :thread_id, presence: truevalidates :title, length: { maximum: Chat::Thread::MAX_TITLE_LENGTH }end+model :threadpolicy :can_view_channelpolicy :can_edit_threaddiff --git a/plugins/chat/app/services/chat/update_thread_notification_settings.rb b/plugins/chat/app/services/chat/update_thread_notification_settings.rbindex 0c776877a8b..049021ed533 100644--- a/plugins/chat/app/services/chat/update_thread_notification_settings.rb+++ b/plugins/chat/app/services/chat/update_thread_notification_settings.rb@@ -37,6 +37,7 @@ module Chatin: Chat::UserChatThreadMembership.notification_levels.values,}end+model :thread, :fetch_threadpolicy :can_view_channelpolicy :threading_enabled_for_channeldiff --git a/plugins/chat/app/services/chat/upsert_draft.rb b/plugins/chat/app/services/chat/upsert_draft.rbindex 0beae366d74..0930808c596 100644--- a/plugins/chat/app/services/chat/upsert_draft.rb+++ b/plugins/chat/app/services/chat/upsert_draft.rb@@ -31,6 +31,7 @@ module Chatvalidates :channel_id, presence: trueend+model :channelpolicy :can_upsert_draftstep :check_thread_existsdiff --git a/spec/lib/service/steps_inspector_spec.rb b/spec/lib/service/steps_inspector_spec.rbindex 142ad36c579..26a185b7836 100644--- a/spec/lib/service/steps_inspector_spec.rb+++ b/spec/lib/service/steps_inspector_spec.rb@@ -11,15 +11,18 @@ RSpec.describe Service::StepsInspector domodel :modelpolicy :policy+params doattribute :parametervalidates :parameter, presence: trueend+transaction dostep :in_transaction_step_1step :in_transaction_step_2end+try { step :might_raise }step :final_stepend