mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 23:48:44 +08:00
DEV: Apply new Rubocop linting on services
This commit is contained in:

committed by
Loïc Guitaut

parent
a52b83333e
commit
cf2b4d9934
@ -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
|
||||
|
Reference in New Issue
Block a user