[PostFlags] Allow uploading guidelines flag on approved posts (#764)

This commit is contained in:
Donovan Daniels 2024-09-29 15:08:45 -05:00 committed by GitHub
parent cffc480b23
commit 9c82b003a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 8 deletions

View File

@ -1767,9 +1767,7 @@ class Post < ApplicationRecord
end
def flaggable_for_guidelines?
return true if is_pending?
return true if CurrentUser.is_privileged? && !has_tag?("grandfathered_content") && created_at.after?("2015-01-01")
false
!has_tag?("grandfathered_content") && created_at.after?("2015-01-01")
end
def visible_comment_count(_user)

View File

@ -143,7 +143,7 @@ class PostFlag < ApplicationRecord
end
errors.add(:parent_id, "cannot be set to the post being flagged") if parent_post.id == post.id
when 'uploading_guidelines'
errors.add(:reason, "cannot be used. The post is either not pending, or grandfathered") unless post.flaggable_for_guidelines?
errors.add(:reason, "cannot be used. The post is grandfathered") unless post.flaggable_for_guidelines?
else
errors.add(:reason, "is not one of the available choices") unless MAPPED_REASONS.key?(reason_name)
end

View File

@ -39,15 +39,14 @@ class PostFlagTest < ActiveSupport::TestCase
assert_match(/Post is deleted/, error.message)
end
should "not be able to flag a non-pending post with the uploading_guidelines reason" do
should "not be able to flag grandfathered posts with the uploading_guidelines reason" do
error = assert_raises(ActiveRecord::RecordInvalid) do
as(@bob) do
@post_flag = create(:post_flag, post: @post, reason_name: "uploading_guidelines")
@post_flag = create(:post_flag, post: create(:post, tag_string: "grandfathered_content"), reason_name: "uploading_guidelines")
end
end
assert_match(/not pending/, error.message)
assert_match(/grandfathered/, error.message)
@post = create(:post, is_pending: true)
as(@bob) do
@post_flag = create(:post_flag, post: @post, reason_name: "uploading_guidelines")
end