##// END OF EJS Templates
Adds 4h, 8h and 12h as options for session maximum lifetime (#20933)....
Jean-Philippe Lang -
r14265:b0be968d36f5
parent child
Show More
@@ -1,173 +1,192
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2015 Jean-Philippe Lang
4 # Copyright (C) 2006-2015 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module SettingsHelper
20 module SettingsHelper
21 def administration_settings_tabs
21 def administration_settings_tabs
22 tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
22 tabs = [{:name => 'general', :partial => 'settings/general', :label => :label_general},
23 {:name => 'display', :partial => 'settings/display', :label => :label_display},
23 {:name => 'display', :partial => 'settings/display', :label => :label_display},
24 {:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
24 {:name => 'authentication', :partial => 'settings/authentication', :label => :label_authentication},
25 {:name => 'api', :partial => 'settings/api', :label => :label_api},
25 {:name => 'api', :partial => 'settings/api', :label => :label_api},
26 {:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
26 {:name => 'projects', :partial => 'settings/projects', :label => :label_project_plural},
27 {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
27 {:name => 'issues', :partial => 'settings/issues', :label => :label_issue_tracking},
28 {:name => 'attachments', :partial => 'settings/attachments', :label => :label_attachment_plural},
28 {:name => 'attachments', :partial => 'settings/attachments', :label => :label_attachment_plural},
29 {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
29 {:name => 'notifications', :partial => 'settings/notifications', :label => :field_mail_notification},
30 {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
30 {:name => 'mail_handler', :partial => 'settings/mail_handler', :label => :label_incoming_emails},
31 {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
31 {:name => 'repositories', :partial => 'settings/repositories', :label => :label_repository_plural}
32 ]
32 ]
33 end
33 end
34
34
35 def setting_select(setting, choices, options={})
35 def setting_select(setting, choices, options={})
36 if blank_text = options.delete(:blank)
36 if blank_text = options.delete(:blank)
37 choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
37 choices = [[blank_text.is_a?(Symbol) ? l(blank_text) : blank_text, '']] + choices
38 end
38 end
39 setting_label(setting, options).html_safe +
39 setting_label(setting, options).html_safe +
40 select_tag("settings[#{setting}]",
40 select_tag("settings[#{setting}]",
41 options_for_select(choices, Setting.send(setting).to_s),
41 options_for_select(choices, Setting.send(setting).to_s),
42 options).html_safe
42 options).html_safe
43 end
43 end
44
44
45 def setting_multiselect(setting, choices, options={})
45 def setting_multiselect(setting, choices, options={})
46 setting_values = Setting.send(setting)
46 setting_values = Setting.send(setting)
47 setting_values = [] unless setting_values.is_a?(Array)
47 setting_values = [] unless setting_values.is_a?(Array)
48
48
49 content_tag("label", l(options[:label] || "setting_#{setting}")) +
49 content_tag("label", l(options[:label] || "setting_#{setting}")) +
50 hidden_field_tag("settings[#{setting}][]", '').html_safe +
50 hidden_field_tag("settings[#{setting}][]", '').html_safe +
51 choices.collect do |choice|
51 choices.collect do |choice|
52 text, value = (choice.is_a?(Array) ? choice : [choice, choice])
52 text, value = (choice.is_a?(Array) ? choice : [choice, choice])
53 content_tag(
53 content_tag(
54 'label',
54 'label',
55 check_box_tag(
55 check_box_tag(
56 "settings[#{setting}][]",
56 "settings[#{setting}][]",
57 value,
57 value,
58 setting_values.include?(value),
58 setting_values.include?(value),
59 :id => nil
59 :id => nil
60 ) + text.to_s,
60 ) + text.to_s,
61 :class => (options[:inline] ? 'inline' : 'block')
61 :class => (options[:inline] ? 'inline' : 'block')
62 )
62 )
63 end.join.html_safe
63 end.join.html_safe
64 end
64 end
65
65
66 def setting_text_field(setting, options={})
66 def setting_text_field(setting, options={})
67 setting_label(setting, options).html_safe +
67 setting_label(setting, options).html_safe +
68 text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
68 text_field_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
69 end
69 end
70
70
71 def setting_text_area(setting, options={})
71 def setting_text_area(setting, options={})
72 setting_label(setting, options).html_safe +
72 setting_label(setting, options).html_safe +
73 text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
73 text_area_tag("settings[#{setting}]", Setting.send(setting), options).html_safe
74 end
74 end
75
75
76 def setting_check_box(setting, options={})
76 def setting_check_box(setting, options={})
77 setting_label(setting, options).html_safe +
77 setting_label(setting, options).html_safe +
78 hidden_field_tag("settings[#{setting}]", 0, :id => nil).html_safe +
78 hidden_field_tag("settings[#{setting}]", 0, :id => nil).html_safe +
79 check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
79 check_box_tag("settings[#{setting}]", 1, Setting.send("#{setting}?"), options).html_safe
80 end
80 end
81
81
82 def setting_label(setting, options={})
82 def setting_label(setting, options={})
83 label = options.delete(:label)
83 label = options.delete(:label)
84 if label == false
84 if label == false
85 ''
85 ''
86 else
86 else
87 text = label.is_a?(String) ? label : l(label || "setting_#{setting}")
87 text = label.is_a?(String) ? label : l(label || "setting_#{setting}")
88 label_tag("settings_#{setting}", text, options[:label_options])
88 label_tag("settings_#{setting}", text, options[:label_options])
89 end
89 end
90 end
90 end
91
91
92 # Renders a notification field for a Redmine::Notifiable option
92 # Renders a notification field for a Redmine::Notifiable option
93 def notification_field(notifiable)
93 def notification_field(notifiable)
94 tag_data = notifiable.parent.present? ?
94 tag_data = notifiable.parent.present? ?
95 {:parent_notifiable => notifiable.parent} :
95 {:parent_notifiable => notifiable.parent} :
96 {:disables => "input[data-parent-notifiable=#{notifiable.name}]"}
96 {:disables => "input[data-parent-notifiable=#{notifiable.name}]"}
97
97
98 tag = check_box_tag('settings[notified_events][]',
98 tag = check_box_tag('settings[notified_events][]',
99 notifiable.name,
99 notifiable.name,
100 Setting.notified_events.include?(notifiable.name),
100 Setting.notified_events.include?(notifiable.name),
101 :id => nil,
101 :id => nil,
102 :data => tag_data)
102 :data => tag_data)
103
103
104 text = l_or_humanize(notifiable.name, :prefix => 'label_')
104 text = l_or_humanize(notifiable.name, :prefix => 'label_')
105
105
106 options = {}
106 options = {}
107 if notifiable.parent.present?
107 if notifiable.parent.present?
108 options[:class] = "parent"
108 options[:class] = "parent"
109 end
109 end
110
110
111 content_tag(:label, tag + text, options)
111 content_tag(:label, tag + text, options)
112 end
112 end
113
113
114 def session_lifetime_options
115 options = [[l(:label_disabled), 0]]
116 options += [4, 8, 12].map {|hours|
117 [l('datetime.distance_in_words.x_hours', :count => hours), (hours * 60).to_s]
118 }
119 options += [1, 7, 30, 60, 365].map {|days|
120 [l('datetime.distance_in_words.x_days', :count => days), (days * 24 * 60).to_s]
121 }
122 options
123 end
124
125 def session_timeout_options
126 options = [[l(:label_disabled), 0]]
127 options += [1, 2, 4, 8, 12, 24, 48].map {|hours|
128 [l('datetime.distance_in_words.x_hours', :count => hours), (hours * 60).to_s]
129 }
130 options
131 end
132
114 def link_copied_issue_options
133 def link_copied_issue_options
115 options = [
134 options = [
116 [:general_text_Yes, 'yes'],
135 [:general_text_Yes, 'yes'],
117 [:general_text_No, 'no'],
136 [:general_text_No, 'no'],
118 [:label_ask, 'ask']
137 [:label_ask, 'ask']
119 ]
138 ]
120
139
121 options.map {|label, value| [l(label), value.to_s]}
140 options.map {|label, value| [l(label), value.to_s]}
122 end
141 end
123
142
124 def cross_project_subtasks_options
143 def cross_project_subtasks_options
125 options = [
144 options = [
126 [:label_disabled, ''],
145 [:label_disabled, ''],
127 [:label_cross_project_system, 'system'],
146 [:label_cross_project_system, 'system'],
128 [:label_cross_project_tree, 'tree'],
147 [:label_cross_project_tree, 'tree'],
129 [:label_cross_project_hierarchy, 'hierarchy'],
148 [:label_cross_project_hierarchy, 'hierarchy'],
130 [:label_cross_project_descendants, 'descendants']
149 [:label_cross_project_descendants, 'descendants']
131 ]
150 ]
132
151
133 options.map {|label, value| [l(label), value.to_s]}
152 options.map {|label, value| [l(label), value.to_s]}
134 end
153 end
135
154
136 def parent_issue_dates_options
155 def parent_issue_dates_options
137 options = [
156 options = [
138 [:label_parent_task_attributes_derived, 'derived'],
157 [:label_parent_task_attributes_derived, 'derived'],
139 [:label_parent_task_attributes_independent, 'independent']
158 [:label_parent_task_attributes_independent, 'independent']
140 ]
159 ]
141
160
142 options.map {|label, value| [l(label), value.to_s]}
161 options.map {|label, value| [l(label), value.to_s]}
143 end
162 end
144
163
145 def parent_issue_priority_options
164 def parent_issue_priority_options
146 options = [
165 options = [
147 [:label_parent_task_attributes_derived, 'derived'],
166 [:label_parent_task_attributes_derived, 'derived'],
148 [:label_parent_task_attributes_independent, 'independent']
167 [:label_parent_task_attributes_independent, 'independent']
149 ]
168 ]
150
169
151 options.map {|label, value| [l(label), value.to_s]}
170 options.map {|label, value| [l(label), value.to_s]}
152 end
171 end
153
172
154 def parent_issue_done_ratio_options
173 def parent_issue_done_ratio_options
155 options = [
174 options = [
156 [:label_parent_task_attributes_derived, 'derived'],
175 [:label_parent_task_attributes_derived, 'derived'],
157 [:label_parent_task_attributes_independent, 'independent']
176 [:label_parent_task_attributes_independent, 'independent']
158 ]
177 ]
159
178
160 options.map {|label, value| [l(label), value.to_s]}
179 options.map {|label, value| [l(label), value.to_s]}
161 end
180 end
162
181
163 # Returns the options for the date_format setting
182 # Returns the options for the date_format setting
164 def date_format_setting_options(locale)
183 def date_format_setting_options(locale)
165 Setting::DATE_FORMATS.map do |f|
184 Setting::DATE_FORMATS.map do |f|
166 today = ::I18n.l(Date.today, :locale => locale, :format => f)
185 today = ::I18n.l(Date.today, :locale => locale, :format => f)
167 format = f.gsub('%', '').gsub(/[dmY]/) do
186 format = f.gsub('%', '').gsub(/[dmY]/) do
168 {'d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy'}[$&]
187 {'d' => 'dd', 'm' => 'mm', 'Y' => 'yyyy'}[$&]
169 end
188 end
170 ["#{today} (#{format})", f]
189 ["#{today} (#{format})", f]
171 end
190 end
172 end
191 end
173 end
192 end
@@ -1,40 +1,40
1 <%= form_tag({:action => 'edit', :tab => 'authentication'}) do %>
1 <%= form_tag({:action => 'edit', :tab => 'authentication'}) do %>
2
2
3 <div class="box tabular settings">
3 <div class="box tabular settings">
4 <p><%= setting_check_box :login_required %></p>
4 <p><%= setting_check_box :login_required %></p>
5
5
6 <p><%= setting_select :autologin, [[l(:label_disabled), 0]] + [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]} %></p>
6 <p><%= setting_select :autologin, [[l(:label_disabled), 0]] + [1, 7, 30, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]} %></p>
7
7
8 <p><%= setting_select :self_registration, [[l(:label_disabled), "0"],
8 <p><%= setting_select :self_registration, [[l(:label_disabled), "0"],
9 [l(:label_registration_activation_by_email), "1"],
9 [l(:label_registration_activation_by_email), "1"],
10 [l(:label_registration_manual_activation), "2"],
10 [l(:label_registration_manual_activation), "2"],
11 [l(:label_registration_automatic_activation), "3"]] %></p>
11 [l(:label_registration_automatic_activation), "3"]] %></p>
12
12
13 <p><%= setting_check_box :unsubscribe %></p>
13 <p><%= setting_check_box :unsubscribe %></p>
14
14
15 <p><%= setting_text_field :password_min_length, :size => 6 %></p>
15 <p><%= setting_text_field :password_min_length, :size => 6 %></p>
16
16
17 <p>
17 <p>
18 <%= setting_select :password_max_age, [[l(:label_disabled), 0]] + [7, 30, 60, 90, 180, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]} %>
18 <%= setting_select :password_max_age, [[l(:label_disabled), 0]] + [7, 30, 60, 90, 180, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), days.to_s]} %>
19 </p>
19 </p>
20
20
21 <p><%= setting_check_box :lost_password, :label => :label_password_lost %></p>
21 <p><%= setting_check_box :lost_password, :label => :label_password_lost %></p>
22
22
23 <p><%= setting_text_field :max_additional_emails, :size => 6 %></p>
23 <p><%= setting_text_field :max_additional_emails, :size => 6 %></p>
24
24
25 <p><%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %></p>
25 <p><%= setting_check_box :openid, :disabled => !Object.const_defined?(:OpenID) %></p>
26 </div>
26 </div>
27
27
28 <fieldset class="box">
28 <fieldset class="box">
29 <legend><%= l(:label_session_expiration) %></legend>
29 <legend><%= l(:label_session_expiration) %></legend>
30
30
31 <div class="tabular settings">
31 <div class="tabular settings">
32 <p><%= setting_select :session_lifetime, [[l(:label_disabled), 0]] + [1, 7, 30, 60, 365].collect{|days| [l('datetime.distance_in_words.x_days', :count => days), (days * 60 * 24).to_s]} %></p>
32 <p><%= setting_select :session_lifetime, session_lifetime_options %></p>
33 <p><%= setting_select :session_timeout, [[l(:label_disabled), 0]] + [1, 2, 4, 8, 12, 24, 48].collect{|hours| [l('datetime.distance_in_words.x_hours', :count => hours), (hours * 60).to_s]} %></p>
33 <p><%= setting_select :session_timeout, session_timeout_options %></p>
34 </div>
34 </div>
35
35
36 <p><em class="info"><%= l(:text_session_expiration_settings) %></em></p>
36 <p><em class="info"><%= l(:text_session_expiration_settings) %></em></p>
37 </fieldset>
37 </fieldset>
38
38
39 <%= submit_tag l(:button_save) %>
39 <%= submit_tag l(:button_save) %>
40 <% end %>
40 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now