From dc34c68353a760fcbee196b5c20293dc758ec40b Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 21 Jul 2015 14:14:08 -0700 Subject: [PATCH] fixes #2427: Prevent removing all tags from post --- app/models/post.rb | 6 ++++++ config/locales/en.yml | 1 + test/unit/post_test.rb | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index aa0b812c3..0ae3e88af 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -481,6 +481,12 @@ class Post < ActiveRecord::Base def update_tag_post_counts 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 if increment_tags.any? Tag.delay(:queue => "default").increment_post_counts(increment_tags) diff --git a/config/locales/en.yml b/config/locales/en.yml index 3ba3c2f17..305dc293e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,6 +8,7 @@ en: post: approver: "You" approver_id: "You" + updater_id: "You" post_flag: creator: "You" creator_id: "You" diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 2fb71f993..51ec43ebe 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -430,6 +430,18 @@ class PostTest < ActiveSupport::TestCase @post = FactoryGirl.create(:post) 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 setup do @artist = FactoryGirl.create(:artist)