Merge pull request #3454 from evazion/fix-3448

Fix #3448: Lower the limit for tag category changes
This commit is contained in:
Albert Yi
2017-12-25 13:20:45 -08:00
committed by GitHub
6 changed files with 33 additions and 12 deletions

View File

@@ -36,7 +36,6 @@ class TagsController < ApplicationController
@tag = Tag.find(params[:id])
check_privilege(@tag)
@tag.update_attributes(params[:tag], :as => CurrentUser.role)
@tag.update_category_cache_for_all
respond_with(@tag)
end

View File

@@ -117,7 +117,6 @@ private
tag = Tag.find_by_name(token[1])
tag.category = Tag.categories.value_for(token[2])
tag.save
tag.update_category_cache_for_all
else
raise "Unknown token: #{token[0]}"

View File

@@ -15,6 +15,8 @@ class Tag < ApplicationRecord
validates :name, uniqueness: true, tag_name: true, on: :create
validates_inclusion_of :category, in: TagCategory.category_ids
after_save :update_category_cache_for_all, if: :category_changed?
module ApiMethods
def to_legacy_json
return {
@@ -200,7 +202,7 @@ class Tag < ApplicationRecord
names.map {|x| find_or_create_by_name(x).name}
end
def find_or_create_by_name(name, options = {})
def find_or_create_by_name(name, creator: CurrentUser.user)
name = normalize_name(name)
category = nil
@@ -220,9 +222,8 @@ class Tag < ApplicationRecord
# next few lines if the category is changed.
tag.update_category_cache
if category_id != tag.category && !tag.is_locked? && ((CurrentUser.is_builder? && tag.post_count < 10_000) || tag.post_count <= 50)
tag.update_column(:category, category_id)
tag.update_category_cache_for_all
if tag.editable_by?(creator)
tag.update(category: category_id)
end
end
@@ -948,7 +949,10 @@ class Tag < ApplicationRecord
end
def editable_by?(user)
user.is_builder? || (user.is_member? && post_count <= 50)
return true if user.is_admin?
return true if !is_locked? && user.is_builder? && post_count < 1_000
return true if !is_locked? && user.is_member? && post_count < 50
return false
end
include ApiMethods

View File

@@ -173,7 +173,6 @@ class TagAlias < TagRelationship
def ensure_category_consistency
if antecedent_tag.category != consequent_tag.category && antecedent_tag.category != Tag.categories.general
consequent_tag.update_attribute(:category, antecedent_tag.category)
consequent_tag.update_category_cache_for_all
end
true