0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/app/services/user/action/trigger_post_action.rb
Krzysztof Kotlarek d792c77895
FEATURE: Link staff action log entries to originating reviewable (#39519)
The staff action log records moderation actions (post deletions, user
suspensions, silences, user approvals, etc.) as `UserHistory` rows, but
entries triggered from the reviewable queue have no reference back to
the reviewable that caused them. When auditing a decision in the log,
staff can't jump to the flagged post, queued post, or user-approval
review that produced it.

Link to review is visible in the log:
<img width="900" height="674" alt="Screenshot 2026-04-24 at 2 17 04 pm"
src="https://github.com/user-attachments/assets/791ebc58-0a4d-4c2c-a363-efe482f5f755"
/>
2026-04-30 09:15:45 +08:00

39 lines
971 B
Ruby
Vendored

# frozen_string_literal: true
class User::Action::TriggerPostAction < Service::ActionBase
option :guardian
option :post
option :params
delegate :post_action, :reviewable_id, 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, reviewable_id: reviewable_id).destroy
end
def delete_replies
return unless guardian.can_delete_post_or_topic?(post)
PostDestroyer.delete_with_replies(user, post, reviewable_id)
end
def edit
return unless guardian.can_edit_post?(post)
# 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