You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10-patches.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # frozen_string_literal: true
  2. module ActiveRecord
  3. # Undefines private Kernel#open method to allow using `open` scopes in models.
  4. # See Defect #11545 (http://www.redmine.org/issues/11545) for details.
  5. class Base
  6. class << self
  7. undef open
  8. end
  9. end
  10. class Relation ; undef open ; end
  11. end
  12. module ActionView
  13. module Helpers
  14. module DateHelper
  15. # distance_of_time_in_words breaks when difference is greater than 30 years
  16. def distance_of_date_in_words(from_date, to_date = 0, options = {})
  17. from_date = from_date.to_date if from_date.respond_to?(:to_date)
  18. to_date = to_date.to_date if to_date.respond_to?(:to_date)
  19. distance_in_days = (to_date - from_date).abs
  20. I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
  21. case distance_in_days
  22. when 0..60 then locale.t :x_days, :count => distance_in_days.round
  23. when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
  24. else locale.t :over_x_years, :count => (distance_in_days / 365).floor
  25. end
  26. end
  27. end
  28. end
  29. end
  30. end
  31. ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
  32. module ActionView
  33. module Helpers
  34. module FormHelper
  35. alias :date_field_without_max :date_field
  36. def date_field(object_name, method, options = {})
  37. date_field_without_max(object_name, method, options.reverse_merge(max: '9999-12-31'))
  38. end
  39. end
  40. module FormTagHelper
  41. alias :date_field_tag_without_max :date_field_tag
  42. def date_field_tag(name, value = nil, options = {})
  43. date_field_tag_without_max(name, value, options.reverse_merge(max: '9999-12-31'))
  44. end
  45. end
  46. end
  47. end
  48. require 'mail'
  49. module DeliveryMethods
  50. class TmpFile
  51. def initialize(*args); end
  52. def deliver!(mail)
  53. dest_dir = File.join(Rails.root, 'tmp', 'emails')
  54. Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
  55. filename = "#{Time.now.to_i}_#{mail.message_id.gsub(/[<>]/, '')}.eml"
  56. File.binwrite(File.join(dest_dir, filename), mail.encoded)
  57. end
  58. end
  59. end
  60. ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
  61. module ActionController
  62. module MimeResponds
  63. class Collector
  64. def api(&block)
  65. any(:xml, :json, &block)
  66. end
  67. end
  68. end
  69. end
  70. module ActionController
  71. class Base
  72. # Displays an explicit message instead of a NoMethodError exception
  73. # when trying to start Redmine with an old session_store.rb
  74. # TODO: remove it in a later version
  75. def self.session=(*args)
  76. $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" +
  77. "Setting the session secret with ActionController.session= is no longer supported."
  78. exit 1
  79. end
  80. end
  81. end
  82. module ActionView
  83. LookupContext.prepend(Module.new do
  84. def formats=(values)
  85. if (Array(values) & [:xml, :json]).any?
  86. values << :api
  87. end
  88. super(values)
  89. end
  90. end)
  91. end
  92. module ActionController
  93. Base.prepend(Module.new do
  94. def rendered_format
  95. if lookup_context.formats.first == :api
  96. return request.format
  97. end
  98. super
  99. end
  100. end)
  101. end
  102. Mime::SET << 'api'
  103. module Propshaft
  104. Assembly.prepend(Module.new do
  105. def initialize(config)
  106. super
  107. if Rails.application.config.assets.redmine_detect_update && (!manifest_path.exist? || manifest_outdated?)
  108. processor.process
  109. end
  110. end
  111. def manifest_outdated?
  112. !!load_path.asset_files.detect{|f| f.mtime > manifest_path.mtime}
  113. end
  114. def load_path
  115. @load_path ||= Redmine::AssetLoadPath.new(config)
  116. end
  117. end)
  118. Helper.prepend(Module.new do
  119. def compute_asset_path(path, options = {})
  120. super
  121. rescue MissingAssetError => e
  122. File.join Rails.application.assets.resolver.prefix, path
  123. end
  124. end)
  125. end