wikis: disallow renaming unless tag is empty (fix #2964).

This commit is contained in:
evazion
2017-04-08 02:23:42 -05:00
parent 8376c33980
commit 1b572c592c
4 changed files with 40 additions and 16 deletions

View File

@@ -254,9 +254,7 @@ class TagAlias < ActiveRecord::Base
if antecedent_wiki.present?
if WikiPage.titled(consequent_name).blank?
CurrentUser.scoped(creator, creator_ip_addr) do
antecedent_wiki.update_attributes(
:title => consequent_name
)
antecedent_wiki.update(title: consequent_name, skip_secondary_validations: true)
end
else
message = "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] (alias ##{id}) has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary."

View File

@@ -10,9 +10,11 @@ class WikiPage < ActiveRecord::Base
belongs_to :updater, :class_name => "User"
validates_uniqueness_of :title, :case_sensitive => false
validates_presence_of :title
validate :validate_rename
validate :validate_locker_is_builder
validate :validate_not_locked
attr_accessible :title, :body, :is_locked, :is_deleted, :other_names
attr_accessor :skip_secondary_validations
attr_accessible :title, :body, :is_locked, :is_deleted, :other_names, :skip_secondary_validations
has_one :tag, :foreign_key => "name", :primary_key => "title"
has_one :artist, lambda {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
has_many :versions, lambda {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
@@ -120,6 +122,15 @@ class WikiPage < ActiveRecord::Base
end
end
def validate_rename
return if !title_changed? || skip_secondary_validations
tag_was = Tag.find_by_name(Tag.normalize_name(title_was))
if tag_was.present? && tag_was.post_count > 0
errors.add(:title, "cannot be changed: '#{tag_was.name}' still has #{tag_was.post_count} posts. Move the posts and update any wikis linking to this page first.")
end
end
def revert_to(version)
if id != version.wiki_page_id
raise RevertError.new("You cannot revert to a previous version of another wiki page.")
@@ -145,6 +156,10 @@ class WikiPage < ActiveRecord::Base
self.other_names = normalized_other_names.uniq.join(" ")
end
def skip_secondary_validations=(value)
@skip_secondary_validations = (value == true || value == "1")
end
def creator_name
User.id_to_name(creator_id).tr("_", " ")
end