discourse/app/services/user/action/trigger_post_action.rb
Loïc Guitaut 05b8ff436c DEV: Introduce a Service::ActionBase class for service actions
This will help to enforce a consistent pattern for creating service
actions.

This patch also namespaces actions and policies, making everything
related to a service available directly in
`app/services/<concept-name>`, making things more consistent at that
level too.
2024-09-18 17:02:46 +02:00

39 lines
843 B
Ruby

# frozen_string_literal: true
class User::Action::TriggerPostAction < Service::ActionBase
option :guardian
option :post
option :contract
delegate :post_action, to: :contract, private: true
delegate :user, to: :guardian, private: true
def call
return if post.blank? || post_action.blank?
send(post_action)
rescue NoMethodError
end
private
def delete
return unless guardian.can_delete_post_or_topic?(post)
PostDestroyer.new(user, post).destroy
end
def delete_replies
return unless guardian.can_delete_post_or_topic?(post)
PostDestroyer.delete_with_replies(user, post)
end
def edit
# Take what the moderator edited in as gospel
PostRevisor.new(post).revise!(
user,
{ raw: contract.post_edit },
skip_validations: true,
skip_revision: true,
)
end
end