From c6353928652e9a098c47cb2f3a217eacbd2d6509 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 16 Oct 2019 10:26:36 +0100 Subject: [PATCH 1/4] render consent info in correct locale --- app/helpers/user_consent_helper.rb | 14 ++++++-- .../account/_user_consent_check.html.erb | 1 - spec/views/account/register.html.erb_spec.rb | 34 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rb index 81d2d988e5..a0c3c3b140 100644 --- a/app/helpers/user_consent_helper.rb +++ b/app/helpers/user_consent_helper.rb @@ -38,10 +38,18 @@ module ::UserConsentHelper Setting.consent_required? && consent_configured? end - def user_consent_instructions(user) - language = user.try(:language) || Setting.default_language + ## + # Gets consent instructions for the given user. + # + # @param user [User] The user to get instructions for. + # @param locale [String] ISO-639-1 code for the desired locale (e.g. de, en, fr). + # `I18n.locale` is set for each request individually depending + # among other things on the user's Accept-Language headers. + # @return [String] Instructions in the respective language. + def user_consent_instructions(user, locale: I18n.locale) all = Setting.consent_info - all.fetch(language) { all.values.first } + + all.fetch(locale) { all.values.first } end def consent_configured? diff --git a/app/views/account/_user_consent_check.html.erb b/app/views/account/_user_consent_check.html.erb index 42adf4a919..9d7519588b 100644 --- a/app/views/account/_user_consent_check.html.erb +++ b/app/views/account/_user_consent_check.html.erb @@ -11,4 +11,3 @@ <%= t('consent.checkbox_label') %> - diff --git a/spec/views/account/register.html.erb_spec.rb b/spec/views/account/register.html.erb_spec.rb index e050899418..bbeb2c490c 100644 --- a/spec/views/account/register.html.erb_spec.rb +++ b/spec/views/account/register.html.erb_spec.rb @@ -114,4 +114,38 @@ describe 'account/register', type: :view do end end end + + context "with consent required", with_settings: { + consent_required: true, + consent_info: { + en: "You must consent!", + de: "Du musst zustimmen!" + } + } do + let(:locale) { raise "you have to define the locale" } + + before do + I18n.with_locale(locale) do + render + end + end + + context "for English (locale: en) users" do + let(:locale) { :en } + + it "shows the registration page and consent info in English" do + expect(rendered).to include "new account" + expect(rendered).to include "consent!" + end + end + + context "for German (locale: de) users" do + let(:locale) { :de } + + it "shows the registration page consent info in German" do + expect(rendered).to include "Neues Konto" + expect(rendered).to include "zustimmen!" + end + end + end end From 0a39aa9e27be15c9d53d974201bcc07bbef95698 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 16 Oct 2019 14:31:21 +0100 Subject: [PATCH 2/4] instructions for dumping the database from within the docker container --- docs/operations/backup/docker/backup.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/operations/backup/docker/backup.md b/docs/operations/backup/docker/backup.md index a47bb0518c..3aa8c5b919 100644 --- a/docs/operations/backup/docker/backup.md +++ b/docs/operations/backup/docker/backup.md @@ -21,3 +21,19 @@ S3 or FTP). If at any point you want to restore from a backup, just put your backup in `/var/lib/openproject` on your local host, and re-launch the docker container. + +## Dumping the database + +**Note:** this only applies for the self-contained OpenProject container not using +an external database but instead a database right in the container. + +If you need a SQL dump of your database straight from the container you can do the +following to dump it into the current directory: + +``` +docker exec $CONTAINER_ID bash -c \ + 'export PGPASSWORD=openproject && pg_dump -U openproject -h 127.0.0.1' \ + > openproject.sql +``` + +If you don't know the container id (or name) you can find it out using `docker ps`. From d02b0db93cbd970ece8348158fe05329cb4d8739 Mon Sep 17 00:00:00 2001 From: ulferts Date: Thu, 17 Oct 2019 14:23:07 +0200 Subject: [PATCH 3/4] include module required for content_tag rendering --- app/controllers/my_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index c05339aa41..ac21dee346 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -31,6 +31,8 @@ class MyController < ApplicationController include Concerns::PasswordConfirmation include Concerns::UserPasswordChange + include ActionView::Helpers::TagHelper + layout 'my' helper_method :gon From 1c81ff519cdbb2c8a8a8f1c851f73c7ff4665504 Mon Sep 17 00:00:00 2001 From: ulferts Date: Thu, 17 Oct 2019 14:54:06 +0200 Subject: [PATCH 4/4] adapt feature spec to altered accept language precedence --- app/helpers/user_consent_helper.rb | 1 - app/services/set_localization_service.rb | 5 ++++- spec/features/auth/consent_auth_stage_spec.rb | 12 ++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rb index a0c3c3b140..f7aaa07de5 100644 --- a/app/helpers/user_consent_helper.rb +++ b/app/helpers/user_consent_helper.rb @@ -28,7 +28,6 @@ #++ module ::UserConsentHelper - def consent_param? params[:consent_check].present? end diff --git a/app/services/set_localization_service.rb b/app/services/set_localization_service.rb index 3decce3504..c226f40810 100644 --- a/app/services/set_localization_service.rb +++ b/app/services/set_localization_service.rb @@ -29,6 +29,7 @@ class SetLocalizationService def header_language return unless http_accept_header + accept_lang = parse_qvalues(http_accept_header).first find_language_or_prefix accept_lang end @@ -54,13 +55,15 @@ class SetLocalizationService tmp = tmp.sort_by { |_val, q| -q } tmp.map! { |val, _q| val } end - return tmp + + tmp rescue nil end def find_language_or_prefix(language) return nil unless language + language = language.to_s.downcase find_language(language) || find_language(language.split('-').first) end diff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rb index 86a104ef78..322c2a1ff0 100644 --- a/spec/features/auth/consent_auth_stage_spec.rb +++ b/spec/features/auth/consent_auth_stage_spec.rb @@ -28,7 +28,7 @@ require 'spec_helper' -describe 'Authentication Stages', type: :feature, js: true do +describe 'Authentication Stages', type: :feature do let(:language) { 'en' } let(:user_password) { 'bob' * 4 } let(:user) do @@ -84,12 +84,16 @@ describe 'Authentication Stages', type: :feature, js: true do expect_logged_in end end + context 'when enabled, localized consent exists', with_settings: { consent_info: { de: '# Einwilligung', en: '# Consent header!' } } do let(:consent_required) { true } - let(:language) { 'de' } - it 'should show localized consent' do + before do + Capybara.current_session.driver.header('Accept-Language', 'de') + end + + it 'should show localized consent as defined by the accept language header (ignoring users language)' do login_with user.login, user_password expect(page).to have_selector('.account-consent') @@ -97,7 +101,7 @@ describe 'Authentication Stages', type: :feature, js: true do end end - context 'when enabled, but consent exists', with_settings: { consent_info: { en: '# Consent header!' } } do + context 'when enabled, but consent exists', js: true, with_settings: { consent_info: { en: '# Consent header!' } } do let(:consent_required) { true } after do