Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#65403] Primerize My Account > Settings page

Alexander Brandon Coles8567214338e6
diff --git a/app/components/my/locale_component.html.erb b/app/components/my/locale_component.html.erb
new file mode 100644
index 00000000000..8c80d0f491d
--- /dev/null
+++ b/app/components/my/locale_component.html.erb
@@ -0,0 +1,37 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) the OpenProject GmbH
+
+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-2013 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 COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<%=
+ settings_primer_form_with(
+ model:,
+ url: { action: "update_settings" }
+ ) do |f|
+ render My::LocaleForm.new(f)
+ end
+%>
diff --git a/app/components/my/locale_component.rb b/app/components/my/locale_component.rb
new file mode 100644
index 00000000000..05029c2cf87
--- /dev/null
+++ b/app/components/my/locale_component.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+module My
+ class LocaleComponent < ApplicationComponent
+ include ApplicationHelper
+
+ alias_method :user, :model
+ end
+end
diff --git a/app/forms/my/locale_form.rb b/app/forms/my/locale_form.rb
new file mode 100644
index 00000000000..cf93184faa0
--- /dev/null
+++ b/app/forms/my/locale_form.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+class My::LocaleForm < ApplicationForm
+ include ApplicationHelper
+
+ form do |f|
+ f.select_list(
+ name: :language,
+ label: attribute_name(:language),
+ required: true,
+ include_blank: include_auto? ? I18n.t(:label_auto_option) : false,
+ input_width: :medium
+ ) do |list|
+ available_languages.each do |label, value|
+ list.option(label:, value:, lang: value)
+ end
+ end
+
+ f.fields_for(:pref, model.pref, nested: false) do |builder|
+ ::My::TimeZoneForm.new(builder)
+ end
+
+ f.submit(name: :submit, label: I18n.t(:button_save), scheme: :primary)
+ end
+
+ private
+
+ def include_auto?
+ valid_languages.to_set == all_languages.to_set
+ end
+
+ def available_languages
+ @available_languages ||= valid_languages
+ .map { translate_language(it) }
+ .sort_by(&:last)
+ end
+end
diff --git a/app/forms/my/time_zone_form.rb b/app/forms/my/time_zone_form.rb
new file mode 100644
index 00000000000..69f4e8c7d0f
--- /dev/null
+++ b/app/forms/my/time_zone_form.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+class My::TimeZoneForm < ApplicationForm
+ form do |f|
+ f.select_list(
+ name: :time_zone,
+ label: attribute_name(:time_zone),
+ required: true,
+ include_blank: false,
+ input_width: :large
+ ) do |list|
+ available_time_zones.each do |label, value|
+ list.option(label:, value:)
+ end
+ end
+ end
+
+ private
+
+ def available_time_zones
+ @available_time_zones ||= UserPreferences::UpdateContract
+ .assignable_time_zones
+ .group_by { it.tzinfo.canonical_zone }
+ .map { |canonical_zone, included_zones| build_time_zone_entry(canonical_zone, included_zones) }
+ end
+
+ def build_time_zone_entry(canonical_zone, zones)
+ zone_names = zones.map(&:name).join(", ")
+ offset = ActiveSupport::TimeZone.seconds_to_utc_offset(canonical_zone.base_utc_offset)
+
+ ["(UTC#{offset}) #{zone_names}", canonical_zone.identifier]
+ end
+end
diff --git a/app/views/my/settings.html.erb b/app/views/my/settings.html.erb
index 491b268a3cf..1788638d178 100644
--- a/app/views/my/settings.html.erb
+++ b/app/views/my/settings.html.erb
@@ -39,22 +39,4 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= error_messages_for "user" %>
-<%= labelled_tabular_form_for @user, as: :user, url: { action: "update_settings" },
- lang: current_language,
- html: { id: "my_account_form", class: "form -wide-labels" } do |f| %>
- <fieldset class="form--fieldset">
- <div class="form--field">
- <%= f.select :language, lang_options_for_select, container_class: "-middle" %>
- </div>
- <%= fields_for :pref, @user.pref, builder: TabularFormBuilder, lang: current_language do |pref_fields| %>
- <%= render Settings::TimeZoneSettingComponent.new(
- "time_zone",
- form: pref_fields,
- include_blank: false,
- container_class: "-middle"
- ) %>
- <% end %>
- </fieldset>
- <%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %>
-<% end %>
+<%= render My::LocaleComponent.new(@user) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9c33395ee2d..ac15005985b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2830,6 +2830,7 @@ en:
label_api_access_key: "API access key"
label_api_access_key_created_on: "API access key created %{value} ago"
label_api_access_key_type: "API"
+ label_auto_option: "(auto)"
label_ical_access_key_type: "iCalendar"
label_ical_access_key_description: 'iCalendar token "%{token_name}" for "%{calendar_name}" in "%{project_name}"'
label_ical_access_key_not_present: "iCalendar token(s) not present."
diff --git a/spec/components/my/locale_component_spec.rb b/spec/components/my/locale_component_spec.rb
new file mode 100644
index 00000000000..18804755444
--- /dev/null
+++ b/spec/components/my/locale_component_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+require "rails_helper"
+
+RSpec.describe My::LocaleComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ def render_component(...)
+ render_inline(described_class.new(...))
+ end
+
+ let(:user) { build_stubbed(:user) }
+
+ subject(:rendered_component) do
+ with_controller_class(MyController) do
+ with_request_url("/my/settings") do
+ render_component(user)
+ end
+ end
+ end
+
+ it "renders form" do
+ expect(rendered_component).to have_element :form, action: my_settings_path
+ end
+end
diff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rb
index cd9a42f7f1d..5d2c5f8417f 100644
--- a/spec/features/users/my_spec.rb
+++ b/spec/features/users/my_spec.rb
@@ -67,21 +67,37 @@ RSpec.describe "my", :js do
shared_examples "common tests for normal and LDAP user" do
describe "settings" do
+ before do
+ visit my_settings_path
+ end
+
context "with a default time zone", with_settings: { user_default_timezone: "Asia/Tokyo" } do
- it "can override a time zone" do
+ it "override user time zone" do
expect(user.pref.time_zone).to eq "Asia/Tokyo"
- visit my_settings_path
- expect(page).to have_select "pref_time_zone", selected: "(UTC+09:00) Tokyo"
- select "(UTC+01:00) Paris", from: "pref_time_zone"
+ expect(page).to have_select "Time zone", selected: "(UTC+09:00) Tokyo"
+ select "(UTC+01:00) Paris", from: "Time zone"
click_on "Save"
- expect(page).to have_select "pref_time_zone", selected: "(UTC+01:00) Paris"
- wait_for_network_idle
- user.reload
+ expect_and_dismiss_flash type: :success, message: "Account was successfully updated."
+
+ expect(page).to have_select "Time zone", selected: "(UTC+01:00) Paris"
expect(user.pref.time_zone).to eq "Europe/Paris"
end
end
+
+ it "updates user language" do
+ expect(user.language).to eq "en"
+
+ expect(page).to have_select "Language", selected: "English"
+ select "Español", from: "Language"
+ click_on "Save"
+
+ expect_and_dismiss_flash type: :success, message: "Cuenta se actualizó correctamente."
+
+ expect(page).to have_select "Idioma", selected: "Español"
+ expect(user.language).to eq "es"
+ end
end
end
diff --git a/spec/forms/my/locale_form_spec.rb b/spec/forms/my/locale_form_spec.rb
new file mode 100644
index 00000000000..e936dd15014
--- /dev/null
+++ b/spec/forms/my/locale_form_spec.rb
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+#
+require "spec_helper"
+
+RSpec.describe My::LocaleForm, type: :forms do
+ before do
+ allow(Redmine::I18n)
+ .to receive(:all_languages)
+ .and_return %w[en de es ja zh-CN]
+ end
+
+ include_context "with rendered form"
+
+ let(:model) { build_stubbed(:user, language:) }
+ let(:language) { nil }
+
+ describe "'Language' select list" do
+ it "renders select list" do
+ expect(page).to have_select "Language", required: true do |select|
+ expect(select).to have_element :option, value: "en", text: "English", lang: "en"
+ expect(select).to have_element :option, value: "de", text: "Deutsch", lang: "de"
+ expect(select).to have_element :option, value: "es", text: "Español", lang: "es"
+ expect(select).to have_element :option, value: "ja", text: "日本語", lang: "ja"
+ expect(select).to have_element :option, value: "zh-CN", text: "简体中文", lang: "zh-CN"
+ end
+ end
+
+ it "renders options for available languages, if set", with_settings: { available_languages: %w[en es ja] } do
+ expect(page).to have_select "Language", options: [
+ "English",
+ "Español",
+ "日本語"
+ ]
+ end
+
+ it "renders auto option if all languages available", with_settings: { available_languages: %w[en de es ja zh-CN] } do
+ expect(page).to have_select "Language", with_options: ["(auto)"]
+ end
+
+ context "with no language set" do
+ it "renders no selected option" do
+ expect(page).to have_select "Language", selected: nil
+ end
+ end
+
+ context "with language set to 'es'" do
+ let(:language) { "es" }
+
+ it "renders selected option" do
+ expect(page).to have_select "Language", selected: "Español"
+ end
+ end
+ end
+
+ it "renders 'Time zone' select list" do
+ expect(page).to have_select "Time zone", required: true
+ end
+
+ it "renders submit button" do
+ expect(page).to have_button "Save", class: "Button--primary"
+ end
+end
diff --git a/spec/forms/my/time_zone_form_spec.rb b/spec/forms/my/time_zone_form_spec.rb
new file mode 100644
index 00000000000..1cc5f1f76ae
--- /dev/null
+++ b/spec/forms/my/time_zone_form_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+#
+require "spec_helper"
+
+RSpec.describe My::TimeZoneForm, type: :forms do
+ include_context "with rendered form"
+
+ let(:model) { build_stubbed(:user_preference) }
+
+ it "renders select list" do
+ expect(page).to have_select "Time zone", required: true do |select|
+ expect(select).to have_element :option, value: "America/Los_Angeles", text: "(UTC-08:00) Pacific Time (US & Canada)"
+ expect(select).to have_element :option, value: "Europe/Berlin", text: "(UTC+01:00) Berlin, Copenhagen, Stockholm"
+ expect(select).to have_element :option, value: "Asia/Shanghai", text: "(UTC+08:00) Beijing, Chongqing"
+ end
+ end
+end