Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -16,7 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'diff'
require 'enumerator'
class WikiPage < ActiveRecord::Base
include Redmine::SafeAttributes
@ -41,18 +42,18 @@ class WikiPage < ActiveRecord::Base
:project_key => "#{Wiki.table_name}.project_id"
attr_accessor :redirect_existing_links
attr_writer :deleted_attachment_ids
validates_presence_of :title
validates_format_of :title, :with => /\A[^,\.\/\?\;\|\s]*\z/
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
validates_length_of :title, maximum: 255
validates_associated :content
attr_protected :id
validate :validate_parent_title
before_destroy :delete_redirects
before_save :handle_rename_or_move
after_save :handle_children_move
before_save :handle_rename_or_move, :update_wiki_start_page
after_save :handle_children_move, :delete_selected_attachments
# eager load information about last updates, without loading text
scope :with_updated_on, lambda { preload(:content_without_text) }
@ -61,7 +62,13 @@ class WikiPage < ActiveRecord::Base
DEFAULT_PROTECTED_PAGES = %w(sidebar)
safe_attributes 'parent_id', 'parent_title', 'title', 'redirect_existing_links', 'wiki_id',
:if => lambda {|page, user| page.new_record? || user.allowed_to?(:rename_wiki_pages, page.project)}
:if => lambda {|page, user| page.new_record? || user.allowed_to?(:rename_wiki_pages, page.project)}
safe_attributes 'is_start_page',
:if => lambda {|page, user| user.allowed_to?(:manage_wiki, page.project)}
safe_attributes 'deleted_attachment_ids',
:if => lambda {|page, user| page.attachments_deletable?(user)}
def initialize(attributes=nil, *args)
super
@ -80,6 +87,10 @@ class WikiPage < ActiveRecord::Base
end
def safe_attributes=(attrs, user=User.current)
if attrs.respond_to?(:to_unsafe_hash)
attrs = attrs.to_unsafe_hash
end
return unless attrs.is_a?(Hash)
attrs = attrs.deep_dup
@ -122,7 +133,7 @@ class WikiPage < ActiveRecord::Base
# Moves child pages if page was moved
def handle_children_move
if !new_record? && wiki_id_changed?
if !new_record? && saved_change_to_wiki_id?
children.each do |child|
child.wiki_id = wiki_id
child.redirect_existing_links = redirect_existing_links
@ -209,6 +220,24 @@ class WikiPage < ActiveRecord::Base
self.parent = parent_page
end
def is_start_page
if @is_start_page.nil?
@is_start_page = wiki.try(:start_page) == title_was
end
@is_start_page
end
def is_start_page=(arg)
@is_start_page = arg == '1' || arg == true
end
def update_wiki_start_page
if is_start_page
wiki.update_attribute :start_page, title
end
end
private :update_wiki_start_page
# Saves the page and its content if text was changed
# Return true if the page was saved
def save_with_content(content)
@ -218,7 +247,6 @@ class WikiPage < ActiveRecord::Base
if content.text_changed?
begin
self.content = content
ret = ret && content.changed?
rescue ActiveRecord::RecordNotSaved
ret = false
end
@ -228,6 +256,17 @@ class WikiPage < ActiveRecord::Base
ret
end
def deleted_attachment_ids
Array(@deleted_attachment_ids).map(&:to_i)
end
def delete_selected_attachments
if deleted_attachment_ids.present?
objects = attachments.where(:id => deleted_attachment_ids.map(&:to_i))
attachments.delete(objects)
end
end
protected
def validate_parent_title
@ -265,7 +304,7 @@ class WikiAnnotate
@lines = current_lines.collect {|t| [nil, nil, t]}
positions = []
current_lines.size.times {|i| positions << i}
while (current.previous)
while current.previous
d = current.previous.text.split(/\r?\n/).diff(current.text.split(/\r?\n/)).diffs.flatten
d.each_slice(3) do |s|
sign, line = s[0], s[1]