mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +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:
parent
ea0f20e331
commit
fadb2b7157
|
@ -4650,6 +4650,7 @@ en:
|
|||
restored: Restored
|
||||
|
||||
reviewables:
|
||||
already_handled: "Thanks, but we've already reviewed that post and determined it does not need to be flagged again."
|
||||
priorities:
|
||||
low: "Low"
|
||||
medium: "Medium"
|
||||
|
|
|
@ -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!(
|
||||
|
|
|
@ -115,6 +115,38 @@ describe PostActionCreator do
|
|||
expect(score.reviewed_by).to be_blank
|
||||
expect(score.reviewed_at).to be_blank
|
||||
end
|
||||
|
||||
describe "When the post was already reviewed by staff" do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
before { reviewable.perform(admin, :ignore) }
|
||||
|
||||
it "fails because the post was recently reviewed" do
|
||||
result = PostActionCreator.create(user, post, :inappropriate)
|
||||
|
||||
expect(result.success?).to eq(false)
|
||||
end
|
||||
|
||||
it "succesfully flags the post if it was edited after being reviewed" do
|
||||
reviewable.update!(updated_at: 25.hours.ago)
|
||||
post.last_version_at = 30.hours.ago
|
||||
|
||||
result = PostActionCreator.create(user, post, :inappropriate)
|
||||
|
||||
expect(result.success?).to eq(true)
|
||||
expect(result.reviewable).to be_present
|
||||
end
|
||||
|
||||
it 'succesfully flags the post if it was reviewed more than 24 hours ago' do
|
||||
reviewable.update!(updated_at: 10.minutes.ago)
|
||||
post.last_version_at = 1.minute.ago
|
||||
|
||||
result = PostActionCreator.create(user, post, :inappropriate)
|
||||
|
||||
expect(result.success?).to eq(true)
|
||||
expect(result.reviewable).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ RSpec.describe Reviewable, type: :model do
|
|||
end
|
||||
|
||||
it "triggers a notification on update" do
|
||||
reviewable = PostActionCreator.spam(moderator, post).reviewable
|
||||
reviewable = PostActionCreator.create(moderator, post, :inappropriate).reviewable
|
||||
reviewable.perform(moderator, :disagree)
|
||||
|
||||
expect { PostActionCreator.spam(Fabricate(:user), post) }
|
||||
|
|
Loading…
Reference in New Issue
Block a user