fixes #2427: Prevent removing all tags from post
This commit is contained in:
@@ -481,6 +481,12 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
def update_tag_post_counts
|
def update_tag_post_counts
|
||||||
decrement_tags = tag_array_was - tag_array
|
decrement_tags = tag_array_was - tag_array
|
||||||
|
|
||||||
|
if decrement_tags.size > 1 && !CurrentUser.is_builder? && CurrentUser.created_at > 1.week.ago
|
||||||
|
self.errors.add(:updater_id, "must have an account at least 1 week old to remove tags")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
increment_tags = tag_array - tag_array_was
|
increment_tags = tag_array - tag_array_was
|
||||||
if increment_tags.any?
|
if increment_tags.any?
|
||||||
Tag.delay(:queue => "default").increment_post_counts(increment_tags)
|
Tag.delay(:queue => "default").increment_post_counts(increment_tags)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ en:
|
|||||||
post:
|
post:
|
||||||
approver: "You"
|
approver: "You"
|
||||||
approver_id: "You"
|
approver_id: "You"
|
||||||
|
updater_id: "You"
|
||||||
post_flag:
|
post_flag:
|
||||||
creator: "You"
|
creator: "You"
|
||||||
creator_id: "You"
|
creator_id: "You"
|
||||||
|
|||||||
@@ -430,6 +430,18 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
@post = FactoryGirl.create(:post)
|
@post = FactoryGirl.create(:post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "as a new user" do
|
||||||
|
setup do
|
||||||
|
CurrentUser.user = FactoryGirl.create(:user)
|
||||||
|
@post.update_attribute(:tag_string, "aaa bbb ccc ddd")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not allow you to remove more than 2 tags" do
|
||||||
|
@post.update_attributes(:tag_string => "aaa")
|
||||||
|
assert_equal(["You must have an account at least 1 week old to remove tags"], @post.errors.full_messages)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with a banned artist" do
|
context "with a banned artist" do
|
||||||
setup do
|
setup do
|
||||||
@artist = FactoryGirl.create(:artist)
|
@artist = FactoryGirl.create(:artist)
|
||||||
|
|||||||
Reference in New Issue
Block a user