mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Move channel creation for category into service (#21167)
This commit moves the category channel creation out of the Chat::Api::Channel controller and into a dedicated CreateCategoryChannel service. A follow up commit will move the DM channel creation out of the old DirectMessageChannelCreator service. Also includes a new on_model_errors helper for chat service class usage, that collects model validation errors to present in a nice way. --------- Co-authored-by: Loïc Guitaut <loic@discourse.org>
This commit is contained in:
@ -66,6 +66,7 @@ module Chat
|
||||
# @!visibility private
|
||||
class Model < Step
|
||||
def error
|
||||
return result[name].errors.inspect if step_result.invalid
|
||||
step_result.exception.full_message
|
||||
end
|
||||
end
|
||||
|
@ -55,9 +55,15 @@ class ServiceRunner
|
||||
AVAILABLE_ACTIONS = {
|
||||
on_success: -> { result.success? },
|
||||
on_failure: -> { result.failure? },
|
||||
on_failed_step: ->(name) { failure_for?("result.step.#{name}") },
|
||||
on_failed_policy: ->(name = "default") { failure_for?("result.policy.#{name}") },
|
||||
on_failed_contract: ->(name = "default") { failure_for?("result.contract.#{name}") },
|
||||
on_model_not_found: ->(name = "model") { failure_for?("result.model.#{name}") },
|
||||
on_model_not_found: ->(name = "model") do
|
||||
failure_for?("result.model.#{name}") && result[name].blank?
|
||||
end,
|
||||
on_model_errors: ->(name = "model") do
|
||||
failure_for?("result.model.#{name}") && result["result.model.#{name}"].invalid
|
||||
end,
|
||||
}.with_indifferent_access.freeze
|
||||
|
||||
# @!visibility private
|
||||
|
Reference in New Issue
Block a user