discourse/app/services/user/action/trigger_post_action.rb
Krzysztof Kotlarek fcee78a327
FIX: bug when silence user and do nothing to post (#33819)
When the user was silenced or suspended by accepting a flag, and the
action on the post was `Do Nothing`, it was throwing a silent error.

That was fixed, but in addition, ensured that errors are always
displayed on the modal to inform the user that something went wrong.
2025-07-25 10:31:22 +08:00

38 lines
862 B
Ruby
Vendored

# frozen_string_literal: true
class User::Action::TriggerPostAction < Service::ActionBase
option :guardian
option :post
option :params
delegate :post_action, to: :params, private: true
delegate :user, to: :guardian, private: true
def call
return if post.blank? || post_action.blank? || post_action == "none"
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: params.post_edit },
skip_validations: true,
skip_revision: true,
)
end
end