forked from e621ng/e621ng
[PostFlags] Allow uploading guidelines flag on approved posts (#764)
This commit is contained in:
parent
cffc480b23
commit
9c82b003a3
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user