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
@ -155,7 +157,7 @@ module Redmine
def target_class
nil
end
def possible_custom_value_options(custom_value)
possible_values_options(custom_value.custom_field, custom_value.customized)
end
@ -183,7 +185,7 @@ module Redmine
def parse_keyword(custom_field, keyword, &block)
separator = Regexp.escape ","
keyword = keyword.to_s
keyword = keyword.dup.to_s
if custom_field.multiple?
values = []
@ -248,7 +250,10 @@ module Redmine
url = url_from_pattern(custom_field, single_value, customized)
[text, url]
end
links = texts_and_urls.sort_by(&:first).map {|text, url| view.link_to_if uri_with_safe_scheme?(url), text, url}
links = texts_and_urls.sort_by(&:first).map do |text, url|
css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
view.link_to_if uri_with_safe_scheme?(url), text, url, :class => css_class
end
links.join(', ').html_safe
else
casted
@ -300,8 +305,12 @@ module Redmine
if custom_field.is_required?
''.html_safe
else
view.content_tag('label',
view.check_box_tag(tag_name, '__none__', (value == '__none__'), :id => nil, :data => {:disables => "##{tag_id}"}) + l(:button_clear),
view.content_tag(
'label',
view.check_box_tag(
tag_name,
'__none__', (value == '__none__'), :id => nil,
:data => {:disables => "##{tag_id}"}) + l(:button_clear),
:class => 'inline'
)
end
@ -320,7 +329,7 @@ module Redmine
# Returns nil if the custom field can not be used for sorting.
def order_statement(custom_field)
# COALESCE is here to make sure that blank and NULL values are sorted equally
"COALESCE(#{join_alias custom_field}.value, '')"
Arel.sql "COALESCE(#{join_alias custom_field}.value, '')"
end
# Returns a GROUP BY clause that can used to group by custom value
@ -355,7 +364,7 @@ module Redmine
def validate_single_value(custom_field, value, customized=nil)
errs = super
value = value.to_s
unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
unless custom_field.regexp.blank? or Regexp.new(custom_field.regexp).match?(value)
errs << ::I18n.t('activerecord.errors.messages.invalid')
end
if custom_field.min_length && value.length < custom_field.min_length
@ -437,12 +446,13 @@ module Redmine
url = url_from_pattern(custom_field, value, customized)
else
url = value.to_s
unless url =~ %r{\A[a-z]+://}i
unless %r{\A[a-z]+://}i.match?(url)
# no protocol found, use http by default
url = "http://" + url
end
end
view.link_to value.to_s.truncate(40), url
css_class = (/^https?:\/\//.match?(url)) ? 'external' : nil
view.link_to value.to_s.truncate(40), url, :class => css_class
else
value.to_s
end
@ -457,7 +467,7 @@ module Redmine
# Make the database cast values into numeric
# Postgresql will raise an error if a value can not be casted!
# CustomValue validations should ensure that it doesn't occur
"CAST(CASE #{join_alias custom_field}.value WHEN '' THEN '0' ELSE #{join_alias custom_field}.value END AS decimal(30,3))"
Arel.sql "CAST(CASE #{join_alias custom_field}.value WHEN '' THEN '0' ELSE #{join_alias custom_field}.value END AS decimal(30,3))"
end
# Returns totals for the given scope
@ -486,7 +496,7 @@ module Redmine
def validate_single_value(custom_field, value, customized=nil)
errs = super
errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless value.to_s.strip =~ /^[+-]?\d+$/
errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip)
errs
end
@ -530,7 +540,7 @@ module Redmine
end
def validate_single_value(custom_field, value, customized=nil)
if value =~ /^\d{4}-\d{2}-\d{2}$/ && (value.to_date rescue false)
if /^\d{4}-\d{2}-\d{2}$/.match?(value) && (value.to_date rescue false)
[]
else
[::I18n.t('activerecord.errors.messages.not_a_date')]
@ -621,7 +631,7 @@ module Redmine
value ||= label
checked = (custom_value.value.is_a?(Array) && custom_value.value.include?(value)) || custom_value.value.to_s == value
tag = view.send(tag_method, tag_name, value, checked, :id => nil)
s << view.content_tag('label', tag + ' ' + label)
s << view.content_tag('label', tag + ' ' + label)
end
if custom_value.custom_field.multiple?
s << view.hidden_field_tag(tag_name, '', :id => nil)
@ -726,7 +736,7 @@ module Redmine
def reset_target_class
@target_class = nil
end
def possible_custom_value_options(custom_value)
options = possible_values_options(custom_value.custom_field, custom_value.customized)
missing = [custom_value.value_was].flatten.reject(&:blank?) - options.map(&:last)
@ -753,7 +763,7 @@ module Redmine
end
def group_statement(custom_field)
"COALESCE(#{join_alias custom_field}.value, '')"
Arel.sql "COALESCE(#{join_alias custom_field}.value, '')"
end
def join_for_order_statement(custom_field)
@ -782,7 +792,7 @@ module Redmine
class EnumerationFormat < RecordList
add 'enumeration'
self.form_partial = 'custom_fields/formats/enumeration'
def label
"label_field_format_enumeration"
end
@ -812,7 +822,10 @@ module Redmine
field_attributes :user_role
def possible_values_options(custom_field, object=nil)
possible_values_records(custom_field, object).map {|u| [u.name, u.id.to_s]}
users = possible_values_records(custom_field, object)
options = users.map {|u| [u.name, u.id.to_s]}
options = [["<< #{l(:label_me)} >>", User.current.id]] + options if users.include?(User.current)
options
end
def possible_values_records(custom_field, object=nil)
@ -970,7 +983,7 @@ module Redmine
end
else
if custom_value.value.present?
attachment = Attachment.where(:id => custom_value.value.to_s).first
attachment = Attachment.find_by(:id => custom_value.value.to_s)
extensions = custom_value.custom_field.extensions_allowed
if attachment && extensions.present? && !attachment.extension_in?(extensions)
errors << "#{::I18n.t('activerecord.errors.messages.invalid')} (#{l(:setting_attachment_extensions_allowed)}: #{extensions})"
@ -982,16 +995,16 @@ module Redmine
end
def after_save_custom_value(custom_field, custom_value)
if custom_value.value_changed?
if custom_value.saved_change_to_value?
if custom_value.value.present?
attachment = Attachment.where(:id => custom_value.value.to_s).first
attachment = Attachment.find_by(:id => custom_value.value.to_s)
if attachment
attachment.container = custom_value
attachment.save!
end
end
if custom_value.value_was.present?
attachment = Attachment.where(:id => custom_value.value_was.to_s).first
if custom_value.value_before_last_save.present?
attachment = Attachment.find_by(:id => custom_value.value_before_last_save.to_s)
if attachment
attachment.destroy
end