mirror of
https://github.com/discourse/discourse.git
synced 2024-12-25 16:04:11 +08:00
05b8ff436c
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.
39 lines
843 B
Ruby
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
|