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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Modify set_localization to respect session[:authenticated_user_id].
Pavel Balashou3572d18352e1
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 1f77a494fd0..564973057f7 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -220,7 +220,15 @@ class ApplicationController < ActionController::Baseenddef set_localization- SetLocalizationService.new(User.current, request.env['HTTP_ACCEPT_LANGUAGE']).call+ # 1. Use completely autheticated user+ # 2. Use user with some authenticated stages not compelted.+ # In this case user is not considered logged in, but identified.+ # It covers localization for extra authentication stages(like :consent, for example)+ # 3. Use anonymous instance.+ user = RequestStore[:current_user] ||+ (session[:authenticated_user_id].present? && User.find_by(id: session[:authenticated_user_id])) ||+ User.anonymous+ SetLocalizationService.new(user, request.env['HTTP_ACCEPT_LANGUAGE']).callenddef deny_access(not_found: false)diff --git a/app/controllers/concerns/accounts/user_consent.rb b/app/controllers/concerns/accounts/user_consent.rbindex 74cf7f9d00c..a2603dfae3e 100644--- a/app/controllers/concerns/accounts/user_consent.rb+++ b/app/controllers/concerns/accounts/user_consent.rb@@ -33,8 +33,8 @@ module Accounts::UserConsentinclude ::UserConsentHelperdef consent- if consent_required?- render 'account/consent', locals: { consenting_user: }+ if user_consent_required? && consenting_user&.consent_expired?+ render 'account/consent'elseconsent_finishedend@@ -50,14 +50,6 @@ module Accounts::UserConsentendend- def consent_required?- # Ensure consent is enabled and a text is provided- return false unless user_consent_required?-- # Require the user to consent if he hasn't already- consent_expired?- end-def decline_consentmessage = I18n.t('consent.decline_warning_message') + "\n"message <<@@ -71,19 +63,6 @@ module Accounts::UserConsentredirect_to authentication_stage_failure_path :consentend- def consent_expired?- consented_at = consenting_user.try(:consented_at)-- # Always if the user has not consented- return true if consented_at.blank?-- # Did not expire if no consent_time set, but user has consented at some point- return false if Setting.consent_time.blank?-- # Otherwise, expires when consent_time is newer than last consented_at- consented_at < Setting.consent_time- end-def consenting_userUser.find_by id: session[:authenticated_user_id]enddiff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rbindex 0b4bdbdfe89..66d5a6dafbe 100644--- a/app/helpers/user_consent_helper.rb+++ b/app/helpers/user_consent_helper.rb@@ -52,6 +52,8 @@ module ::UserConsentHelperI18n.t('consent.checkbox_label', locale:)end+ private+def consent_configured?if Setting.consent_info.count == 0Rails.logger.error 'Instance is configured to require consent, but no consent_info has been set.'diff --git a/app/models/user.rb b/app/models/user.rbindex 22e7c63f525..806f40ebddc 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -470,6 +470,17 @@ class User < Principal!logged?end+ def consent_expired?+ # Always if the user has not consented+ return true if consented_at.blank?++ # Did not expire if no consent_time set, but user has consented at some point+ return false if Setting.consent_time.blank?++ # Otherwise, expires when consent_time is newer than last consented_at+ consented_at < Setting.consent_time+ end+# Cheap version of Project.visible.countdef number_of_known_projectsif admin?diff --git a/app/views/account/_register.html.erb b/app/views/account/_register.html.erbindex 8331c2c9447..8ea86ce868b 100644--- a/app/views/account/_register.html.erb+++ b/app/views/account/_register.html.erb@@ -90,7 +90,7 @@ See COPYRIGHT and LICENSE files for more details.<% if user_consent_required? %><hr/>- <%= render partial: 'account/user_consent_check', locals: { consenting_user: @user } %>+ <%= render partial: 'account/user_consent_check' %><% end %><%= render partial: 'account/auth_providers', locals: { omniauth_title: I18n.t('account.signup_with_auth_provider'), wide: true } %>diff --git a/app/views/account/_user_consent_check.html.erb b/app/views/account/_user_consent_check.html.erbindex 62ec2b7cf44..26020ae4bd9 100644--- a/app/views/account/_user_consent_check.html.erb+++ b/app/views/account/_user_consent_check.html.erb@@ -1,6 +1,6 @@<section class="form--section op-user-consent-form"><p>- <%= format_text(user_consent_instructions(consenting_user.language || ::I18n.locale), { target: '_blank' }) %>+ <%= format_text(user_consent_instructions(::I18n.locale), { target: '_blank' }) %></p><label class="form--label-with-check-box -required -no-ellipsis op-user-consent-form--agreement">diff --git a/app/views/account/consent.html.erb b/app/views/account/consent.html.erbindex bebd9fdfb00..6a5548fa882 100644--- a/app/views/account/consent.html.erb+++ b/app/views/account/consent.html.erb@@ -34,7 +34,7 @@ See COPYRIGHT and LICENSE files for more details.<%= form_tag(account_confirm_consent_path, method: :post, class: "form -wide-labels") do %>- <%= render partial: 'user_consent_check', locals: { consenting_user: consenting_user } %>+ <%= render partial: 'user_consent_check' %><section class="form--section"><button type="submit" class="button -highlight"><span class="button--text"><%= t(:button_continue) %></span>diff --git a/spec/views/account/register.html.erb_spec.rb b/spec/views/account/register.html.erb_spec.rbindex db97c84a12d..2609ab84776 100644--- a/spec/views/account/register.html.erb_spec.rb+++ b/spec/views/account/register.html.erb_spec.rb@@ -113,9 +113,7 @@ RSpec.describe 'account/register' dolet(:locale) { raise "you have to define the locale" }before do- I18n.with_locale(locale) do- render- end+ I18n.with_locale(locale) { render }endcontext "for English (locale: en) users" do