user default time zone setting

pull/6183/head
Markus Kahl 7 years ago
parent 1ad161ace3
commit 56e9843b3c
  1. 54
      app/cells/settings/time_zone_setting_cell.rb
  2. 3
      app/cells/views/settings/time_zone_setting/show.erb
  3. 6
      app/models/user.rb
  4. 9
      app/views/settings/_display.html.erb
  5. 14
      app/views/users/_preferences.html.erb
  6. 3
      config/locales/en.yml
  7. 2
      config/settings.yml
  8. 45
      spec/models/users/default_timezone_spec.rb

@ -0,0 +1,54 @@
module Settings
##
# A text field to enter numeric values.
class TimeZoneSettingCell < ::RailsCell
include ActionView::Helpers::FormOptionsHelper
include SettingsHelper
options :form, :title
options container_class: "-wide"
options include_blank: true
def name # name of setting and tag
model
end
def render_select
if form.nil?
render_setting_select
else
render_form_select
end
end
def render_form_select
form.select(
name,
time_zone_entries,
include_blank: include_blank,
container_class: container_class,
title: title
)
end
def render_setting_select
setting_select(
name,
time_zone_entries,
include_blank: include_blank,
container_class: container_class,
title: title
)
end
def time_zones
ActiveSupport::TimeZone.all
end
##
# Returns time zone (label, value) tuples to be used for a select field.
def time_zone_entries
time_zones.map { |tz| [tz.to_s, tz.name ] }
end
end
end

@ -0,0 +1,3 @@
<div class="form--field">
<%= render_select %>
</div>

@ -127,6 +127,8 @@ class User < Principal
validate :password_meets_requirements
after_save :update_password
after_save :set_default_timezone!
before_create :sanitize_mail_notification_setting
before_destroy :delete_associated_private_queries
before_destroy :reassign_associated
@ -694,6 +696,10 @@ class User < Principal
system_user
end
def set_default_timezone!
pref.time_zone = pref.time_zone.presence || Setting.user_default_timezone.presence
end
protected
# Login must not be special value 'me'

@ -44,6 +44,15 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="form--field"><%= setting_select :user_format, @options[:user_format], container_class: '-slim' %></div>
<%=
cell(
Settings::TimeZoneSettingCell,
"user_default_timezone",
container_class: "-slim",
title: I18n.t("tooltip_user_default_timezone")
)
%>
<div class="form--field"><%= setting_text_field :journal_aggregation_time_minutes, unit: t(:label_minute_plural), container_class: '-xslim' %>
<span class="form--field-instructions">
<%= t(:text_journal_aggregation_time_explanation) %><br/>

@ -27,12 +27,14 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
<%= fields_for :pref, @user.pref, builder: TabularFormBuilder, lang: current_language do |pref_fields| %>
<div class="form--field">
<%= pref_fields.select :time_zone,
ActiveSupport::TimeZone.all.collect {|z| [ z.to_s, z.name ]},
include_blank: true,
container_class: (defined? input_size) ? "-#{input_size}" : '-wide' %>
</div>
<%=
cell(
Settings::TimeZoneSettingCell,
"time_zone",
form: pref_fields,
container_class: (defined? input_size) ? "-#{input_size}" : "-wide"
)
%>
<div class="form--field">
<%= pref_fields.select :comments_sorting,
[[t(:label_chronological_order), 'asc'],

@ -2007,6 +2007,7 @@ en:
setting_time_format: "Time format"
setting_accessibility_mode_for_anonymous: "Enable accessibility mode for anonymous users"
setting_user_format: "Users display format"
setting_user_default_timezone: "Users default timezone"
setting_users_deletable_by_admins: "User accounts deletable by admins"
setting_users_deletable_by_self: "Users allowed to delete their accounts"
setting_welcome_text: "Welcome block text"
@ -2335,6 +2336,8 @@ en:
title_remove_and_delete_user: Remove the invited user from the project and delete him/her.
tooltip_user_default_timezone: >
The default timezone for new users. Can be changed in a user's settings.
tooltip_resend_invitation: >
Sends another invitation email with a fresh token in
case the old one expired or the user did not get the original email.

@ -305,6 +305,8 @@ emails_header:
en: ''
work_package_startdate_is_adddate:
default: 1
user_default_timezone:
default: ""
users_deletable_by_admins:
default: 0
users_deletable_by_self:

@ -0,0 +1,45 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require "spec_helper"
describe User, "default time zone" do
let(:user) { FactoryGirl.create :user }
context "with no system default set" do
it "is not set" do
expect(user.pref.time_zone).to be_nil
end
end
context "with a system default set", with_settings: { user_default_timezone: "Edinburgh" } do
it "is set to the default" do
expect(user.pref.time_zone).to eq "Edinburgh"
end
end
end
Loading…
Cancel
Save