diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 5801cf280e..ac21dee346 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -32,6 +32,7 @@ class MyController < ApplicationController include Concerns::PasswordConfirmation include Concerns::UserPasswordChange include ActionView::Helpers::TagHelper + layout 'my' helper_method :gon diff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rb index 81d2d988e5..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 @@ -38,10 +37,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/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/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/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`. 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 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