2019-03-17 02:04:38 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2009-02-21 11:04:50 +00:00
|
|
|
module ActiveRecord
|
2012-08-13 14:23:33 +00:00
|
|
|
# Undefines private Kernel#open method to allow using `open` scopes in models.
|
|
|
|
|
# See Defect #11545 (http://www.redmine.org/issues/11545) for details.
|
2012-08-17 14:34:10 +00:00
|
|
|
class Base
|
|
|
|
|
class << self
|
|
|
|
|
undef open
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-19 08:47:05 +00:00
|
|
|
|
2012-08-13 14:23:33 +00:00
|
|
|
class Relation ; undef open ; end
|
2009-02-21 11:04:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
module ActionView
|
|
|
|
|
module Helpers
|
|
|
|
|
module DateHelper
|
|
|
|
|
# distance_of_time_in_words breaks when difference is greater than 30 years
|
|
|
|
|
def distance_of_date_in_words(from_date, to_date = 0, options = {})
|
|
|
|
|
from_date = from_date.to_date if from_date.respond_to?(:to_date)
|
|
|
|
|
to_date = to_date.to_date if to_date.respond_to?(:to_date)
|
|
|
|
|
distance_in_days = (to_date - from_date).abs
|
|
|
|
|
|
|
|
|
|
I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
|
|
|
|
|
case distance_in_days
|
2009-11-07 09:50:16 +00:00
|
|
|
when 0..60 then locale.t :x_days, :count => distance_in_days.round
|
2009-02-21 11:04:50 +00:00
|
|
|
when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round
|
2009-11-07 09:50:16 +00:00
|
|
|
else locale.t :over_x_years, :count => (distance_in_days / 365).floor
|
2009-02-21 11:04:50 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2008-07-04 17:58:14 +00:00
|
|
|
|
2012-05-25 16:50:25 +00:00
|
|
|
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
|
2009-01-31 11:43:54 +00:00
|
|
|
|
2013-10-26 08:08:45 +00:00
|
|
|
module ActionView
|
|
|
|
|
module Helpers
|
2023-03-30 01:11:19 +00:00
|
|
|
module FormHelper
|
|
|
|
|
alias :date_field_without_max :date_field
|
|
|
|
|
def date_field(object_name, method, options = {})
|
|
|
|
|
date_field_without_max(object_name, method, options.reverse_merge(max: '9999-12-31'))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-10-26 08:08:45 +00:00
|
|
|
module FormTagHelper
|
2023-03-30 01:11:19 +00:00
|
|
|
alias :date_field_tag_without_max :date_field_tag
|
|
|
|
|
def date_field_tag(name, value = nil, options = {})
|
|
|
|
|
date_field_tag_without_max(name, value, options.reverse_merge(max: '9999-12-31'))
|
|
|
|
|
end
|
2013-10-26 08:08:45 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-04-26 16:55:53 +00:00
|
|
|
require 'mail'
|
|
|
|
|
|
|
|
|
|
module DeliveryMethods
|
|
|
|
|
class TmpFile
|
|
|
|
|
def initialize(*args); end
|
|
|
|
|
|
|
|
|
|
def deliver!(mail)
|
|
|
|
|
dest_dir = File.join(Rails.root, 'tmp', 'emails')
|
|
|
|
|
Dir.mkdir(dest_dir) unless File.directory?(dest_dir)
|
2018-10-10 17:13:09 +00:00
|
|
|
filename = "#{Time.now.to_i}_#{mail.message_id.gsub(/[<>]/, '')}.eml"
|
2021-12-24 05:30:56 +00:00
|
|
|
File.binwrite(File.join(dest_dir, filename), mail.encoded)
|
2012-04-26 16:55:53 +00:00
|
|
|
end
|
2011-11-19 13:51:34 +00:00
|
|
|
end
|
2009-01-31 11:43:54 +00:00
|
|
|
end
|
|
|
|
|
|
2012-04-26 16:55:53 +00:00
|
|
|
ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
|
2010-09-26 17:13:52 +00:00
|
|
|
|
2010-12-03 11:45:55 +00:00
|
|
|
module ActionController
|
|
|
|
|
module MimeResponds
|
2012-04-25 17:17:49 +00:00
|
|
|
class Collector
|
2024-08-21 00:46:15 +00:00
|
|
|
def api(&)
|
|
|
|
|
any(:xml, :json, &)
|
2010-12-03 11:45:55 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-04-28 11:48:34 +00:00
|
|
|
|
|
|
|
|
module ActionController
|
|
|
|
|
class Base
|
|
|
|
|
# Displays an explicit message instead of a NoMethodError exception
|
|
|
|
|
# when trying to start Redmine with an old session_store.rb
|
|
|
|
|
# TODO: remove it in a later version
|
|
|
|
|
def self.session=(*args)
|
2012-05-01 15:50:16 +00:00
|
|
|
$stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" +
|
2015-01-17 17:02:55 +00:00
|
|
|
"Setting the session secret with ActionController.session= is no longer supported."
|
2012-04-28 11:48:34 +00:00
|
|
|
exit 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-04-03 05:49:16 +00:00
|
|
|
|
2023-11-27 20:58:55 +00:00
|
|
|
module ActionView
|
|
|
|
|
LookupContext.prepend(Module.new do
|
|
|
|
|
def formats=(values)
|
2024-08-20 23:40:58 +00:00
|
|
|
if Array(values).intersect?([:xml, :json])
|
2023-11-27 20:58:55 +00:00
|
|
|
values << :api
|
|
|
|
|
end
|
2024-05-23 11:25:16 +00:00
|
|
|
super
|
2023-11-27 20:58:55 +00:00
|
|
|
end
|
|
|
|
|
end)
|
2023-12-10 04:01:40 +00:00
|
|
|
end
|
2023-11-27 20:58:55 +00:00
|
|
|
|
2023-12-10 04:01:40 +00:00
|
|
|
module ActionController
|
|
|
|
|
Base.prepend(Module.new do
|
2023-11-27 20:58:55 +00:00
|
|
|
def rendered_format
|
|
|
|
|
if lookup_context.formats.first == :api
|
|
|
|
|
return request.format
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
super
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Mime::SET << 'api'
|
|
|
|
|
|
2024-01-25 05:38:33 +00:00
|
|
|
module Propshaft
|
|
|
|
|
Assembly.prepend(Module.new do
|
|
|
|
|
def initialize(config)
|
|
|
|
|
super
|
|
|
|
|
if Rails.application.config.assets.redmine_detect_update && (!manifest_path.exist? || manifest_outdated?)
|
|
|
|
|
processor.process
|
2017-04-03 05:49:16 +00:00
|
|
|
end
|
|
|
|
|
end
|
2024-01-25 05:38:33 +00:00
|
|
|
|
|
|
|
|
def manifest_outdated?
|
|
|
|
|
!!load_path.asset_files.detect{|f| f.mtime > manifest_path.mtime}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def load_path
|
2024-10-31 08:17:01 +00:00
|
|
|
@load_path ||= Redmine::AssetLoadPath.new(config, compilers)
|
2024-01-25 05:38:33 +00:00
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
Helper.prepend(Module.new do
|
|
|
|
|
def compute_asset_path(path, options = {})
|
|
|
|
|
super
|
|
|
|
|
rescue MissingAssetError => e
|
|
|
|
|
File.join Rails.application.assets.resolver.prefix, path
|
|
|
|
|
end
|
|
|
|
|
end)
|
2017-07-25 13:41:56 +00:00
|
|
|
end
|