@@ -1,180 +1,180 | |||
|
1 | 1 | require 'active_record' |
|
2 | 2 | |
|
3 | 3 | module ActiveRecord |
|
4 | 4 | class Base |
|
5 | 5 | include Redmine::I18n |
|
6 | 6 | # Translate attribute names for validation errors display |
|
7 | 7 | def self.human_attribute_name(attr, *args) |
|
8 | 8 | attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '') |
|
9 | 9 | l("field_#{name.underscore.gsub('/', '_')}_#{attr}", :default => ["field_#{attr}".to_sym, attr]) |
|
10 | 10 | end |
|
11 | 11 | end |
|
12 | 12 | |
|
13 | 13 | # Undefines private Kernel#open method to allow using `open` scopes in models. |
|
14 | 14 | # See Defect #11545 (http://www.redmine.org/issues/11545) for details. |
|
15 | 15 | class Base |
|
16 | 16 | class << self |
|
17 | 17 | undef open |
|
18 | 18 | end |
|
19 | 19 | end |
|
20 | 20 | class Relation ; undef open ; end |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | module ActionView |
|
24 | 24 | module Helpers |
|
25 | 25 | module DateHelper |
|
26 | 26 | # distance_of_time_in_words breaks when difference is greater than 30 years |
|
27 | 27 | def distance_of_date_in_words(from_date, to_date = 0, options = {}) |
|
28 | 28 | from_date = from_date.to_date if from_date.respond_to?(:to_date) |
|
29 | 29 | to_date = to_date.to_date if to_date.respond_to?(:to_date) |
|
30 | 30 | distance_in_days = (to_date - from_date).abs |
|
31 | 31 | |
|
32 | 32 | I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| |
|
33 | 33 | case distance_in_days |
|
34 | 34 | when 0..60 then locale.t :x_days, :count => distance_in_days.round |
|
35 | 35 | when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round |
|
36 | 36 | else locale.t :over_x_years, :count => (distance_in_days / 365).floor |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | end |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | class Resolver |
|
44 | 44 | def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[]) |
|
45 | 45 | cached(key, [name, prefix, partial], details, locals) do |
|
46 | if details[:formats] & [:xml, :json] | |
|
46 | if (details[:formats] & [:xml, :json]).any? | |
|
47 | 47 | details = details.dup |
|
48 | 48 | details[:formats] = details[:formats].dup + [:api] |
|
49 | 49 | end |
|
50 | 50 | find_templates(name, prefix, partial, details) |
|
51 | 51 | end |
|
52 | 52 | end |
|
53 | 53 | end |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe } |
|
57 | 57 | |
|
58 | 58 | # HTML5: <option value=""></option> is invalid, use <option value=""> </option> instead |
|
59 | 59 | module ActionView |
|
60 | 60 | module Helpers |
|
61 | 61 | module Tags |
|
62 | 62 | class Base |
|
63 | 63 | private |
|
64 | 64 | def add_options_with_non_empty_blank_option(option_tags, options, value = nil) |
|
65 | 65 | if options[:include_blank] == true |
|
66 | 66 | options = options.dup |
|
67 | 67 | options[:include_blank] = ' '.html_safe |
|
68 | 68 | end |
|
69 | 69 | add_options_without_non_empty_blank_option(option_tags, options, value) |
|
70 | 70 | end |
|
71 | 71 | alias_method_chain :add_options, :non_empty_blank_option |
|
72 | 72 | end |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | module FormTagHelper |
|
76 | 76 | def select_tag_with_non_empty_blank_option(name, option_tags = nil, options = {}) |
|
77 | 77 | if options.delete(:include_blank) |
|
78 | 78 | options[:prompt] = ' '.html_safe |
|
79 | 79 | end |
|
80 | 80 | select_tag_without_non_empty_blank_option(name, option_tags, options) |
|
81 | 81 | end |
|
82 | 82 | alias_method_chain :select_tag, :non_empty_blank_option |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | module FormOptionsHelper |
|
86 | 86 | def options_for_select_with_non_empty_blank_option(container, selected = nil) |
|
87 | 87 | if container.is_a?(Array) |
|
88 | 88 | container = container.map {|element| element.blank? ? [" ".html_safe, ""] : element} |
|
89 | 89 | end |
|
90 | 90 | options_for_select_without_non_empty_blank_option(container, selected) |
|
91 | 91 | end |
|
92 | 92 | alias_method_chain :options_for_select, :non_empty_blank_option |
|
93 | 93 | end |
|
94 | 94 | end |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | require 'mail' |
|
98 | 98 | |
|
99 | 99 | module DeliveryMethods |
|
100 | 100 | class AsyncSMTP < ::Mail::SMTP |
|
101 | 101 | def deliver!(*args) |
|
102 | 102 | Thread.start do |
|
103 | 103 | super *args |
|
104 | 104 | end |
|
105 | 105 | end |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | class AsyncSendmail < ::Mail::Sendmail |
|
109 | 109 | def deliver!(*args) |
|
110 | 110 | Thread.start do |
|
111 | 111 | super *args |
|
112 | 112 | end |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | class TmpFile |
|
117 | 117 | def initialize(*args); end |
|
118 | 118 | |
|
119 | 119 | def deliver!(mail) |
|
120 | 120 | dest_dir = File.join(Rails.root, 'tmp', 'emails') |
|
121 | 121 | Dir.mkdir(dest_dir) unless File.directory?(dest_dir) |
|
122 | 122 | File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) } |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP |
|
128 | 128 | ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail |
|
129 | 129 | ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile |
|
130 | 130 | |
|
131 | 131 | # Changes how sent emails are logged |
|
132 | 132 | # Rails doesn't log cc and bcc which is misleading when using bcc only (#12090) |
|
133 | 133 | module ActionMailer |
|
134 | 134 | class LogSubscriber < ActiveSupport::LogSubscriber |
|
135 | 135 | def deliver(event) |
|
136 | 136 | recipients = [:to, :cc, :bcc].inject("") do |s, header| |
|
137 | 137 | r = Array.wrap(event.payload[header]) |
|
138 | 138 | if r.any? |
|
139 | 139 | s << "\n #{header}: #{r.join(', ')}" |
|
140 | 140 | end |
|
141 | 141 | s |
|
142 | 142 | end |
|
143 | 143 | info("\nSent email \"#{event.payload[:subject]}\" (%1.fms)#{recipients}" % event.duration) |
|
144 | 144 | debug(event.payload[:mail]) |
|
145 | 145 | end |
|
146 | 146 | end |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | # #deliver is deprecated in Rails 4.2 |
|
150 | 150 | # Prevents massive deprecation warnings |
|
151 | 151 | module ActionMailer |
|
152 | 152 | class MessageDelivery < Delegator |
|
153 | 153 | def deliver |
|
154 | 154 | deliver_now |
|
155 | 155 | end |
|
156 | 156 | end |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | module ActionController |
|
160 | 160 | module MimeResponds |
|
161 | 161 | class Collector |
|
162 | 162 | def api(&block) |
|
163 | 163 | any(:xml, :json, &block) |
|
164 | 164 | end |
|
165 | 165 | end |
|
166 | 166 | end |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | module ActionController |
|
170 | 170 | class Base |
|
171 | 171 | # Displays an explicit message instead of a NoMethodError exception |
|
172 | 172 | # when trying to start Redmine with an old session_store.rb |
|
173 | 173 | # TODO: remove it in a later version |
|
174 | 174 | def self.session=(*args) |
|
175 | 175 | $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" + |
|
176 | 176 | "Setting the session secret with ActionController.session= is no longer supported." |
|
177 | 177 | exit 1 |
|
178 | 178 | end |
|
179 | 179 | end |
|
180 | 180 | end |
General Comments 0
You need to be logged in to leave comments.
Login now