mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 17:26:07 +08:00
FEATURE: Users cannot reflag recently handled items using the same reason unless the post was edited, or it was reviewed more than 24 hours ago. (#8969)
This commit is contained in:
@ -66,6 +66,13 @@ class PostActionCreator
|
||||
|
||||
PostAction.limit_action!(@created_by, @post, @post_action_type_id)
|
||||
|
||||
reviewable = Reviewable.includes(:reviewable_scores).find_by(target: @post)
|
||||
|
||||
if reviewable && flagging_post? && cannot_flag_again?(reviewable)
|
||||
result.add_error(I18n.t("reviewables.already_handled"))
|
||||
return result
|
||||
end
|
||||
|
||||
# create meta topic / post if needed
|
||||
if @message.present? && [:notify_moderators, :notify_user, :spam].include?(@post_action_name)
|
||||
creator = create_message_creator
|
||||
@ -115,6 +122,19 @@ class PostActionCreator
|
||||
|
||||
private
|
||||
|
||||
def flagging_post?
|
||||
PostActionType.notify_flag_type_ids.include?(@post_action_type_id)
|
||||
end
|
||||
|
||||
def cannot_flag_again?(reviewable)
|
||||
return false if @post_action_type_id == PostActionType.types[:notify_moderators]
|
||||
flag_type_already_used = reviewable.reviewable_scores.any? { |rs| rs.reviewable_score_type == @post_action_type_id }
|
||||
not_edited_since_last_review = @post.last_version_at.blank? || reviewable.updated_at > @post.last_version_at
|
||||
handled_recently = reviewable.updated_at > 24.hours.ago
|
||||
|
||||
!reviewable.pending? && flag_type_already_used && not_edited_since_last_review && handled_recently
|
||||
end
|
||||
|
||||
def notify_subscribers
|
||||
if self.class.notify_types.include?(@post_action_name)
|
||||
@post.publish_change_to_clients! :acted
|
||||
@ -261,7 +281,7 @@ private
|
||||
end
|
||||
|
||||
def create_reviewable(result)
|
||||
return unless PostActionType.notify_flag_type_ids.include?(@post_action_type_id)
|
||||
return unless flagging_post?
|
||||
return if @post.user_id.to_i < 0
|
||||
|
||||
result.reviewable = ReviewableFlaggedPost.needs_review!(
|
||||
|
Reference in New Issue
Block a user