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
Rewrite consent without JS
Oliver Güntherf88bfaade174
diff --git a/app/controllers/admin/settings/users_settings_controller.rb b/app/controllers/admin/settings/users_settings_controller.rbindex 0021e563942..322667aea46 100644--- a/app/controllers/admin/settings/users_settings_controller.rb+++ b/app/controllers/admin/settings/users_settings_controller.rb@@ -44,5 +44,13 @@ module Admin::Settingsdef show_local_breadcrumbtrueend++ def settings_params+ super.tap do |settings|+ if settings["consent_required"] == '1' && params['toggle_consent_time'] == '1'+ settings["consent_time"] = Time.zone.now.iso8601+ end+ end+ endendenddiff --git a/app/views/admin/settings/users_settings/show.html.erb b/app/views/admin/settings/users_settings/show.html.erbindex c6e2d5bc4b0..25fd7574e2c 100644--- a/app/views/admin/settings/users_settings/show.html.erb+++ b/app/views/admin/settings/users_settings/show.html.erb@@ -83,7 +83,6 @@ See COPYRIGHT and LICENSE files for more details.<div class="form--field"><%= setting_block("consent_time") do %><span class="form--check-box-field-container -slim">- <input type="hidden" name="settings[consent_time]" disabled id="settings_consent_time"><%= check_box_tag 'toggle_consent_time','1',!Setting.consent_time.present?,diff --git a/frontend/src/app/core/setup/globals/global-listeners/settings.ts b/frontend/src/app/core/setup/globals/global-listeners/settings.tsindex 11c3cfd5c4e..9392ea046b9 100644--- a/frontend/src/app/core/setup/globals/global-listeners/settings.ts+++ b/frontend/src/app/core/setup/globals/global-listeners/settings.ts@@ -62,17 +62,6 @@ export function listenToSettingChanges() {});/* end Javascript for Settings::TextSettingComponent */- jQuery('.admin-settings--form').submit(() => {- /* Update consent time if consent required */- if (jQuery('#settings_consent_required').is(':checked') && jQuery('#toggle_consent_time').is(':checked')) {- jQuery('#settings_consent_time')- .val(new Date().toISOString())- .prop('disabled', false);- }-- return true;- });-/** Toggle notification settings fields */jQuery('#email_delivery_method_switch').on('change', function () {const delivery_method = jQuery(this).val();diff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rbindex cf3de8bbb5b..38d554a6f60 100644--- a/spec/features/auth/consent_auth_stage_spec.rb+++ b/spec/features/auth/consent_auth_stage_spec.rb@@ -47,12 +47,6 @@ RSpec.describe 'Authentication Stages' do)end- before do- allow(Setting)- .to receive(:consent_required?)- .and_return(consent_required)- end-def expect_logged_in(path = my_page_path)expect(page).to have_current_path(path)visit my_account_path@@ -64,9 +58,7 @@ RSpec.describe 'Authentication Stages' doexpect(page).not_to have_selector('.form--field-container', text: user.login)end- context 'when disabled' do- let(:consent_required) { false }-+ context 'when disabled', with_settings: { consent_required: false } doit 'does not show consent' dologin_with user.login, user_passwordexpect(page).not_to have_selector('.account-consent')@@ -87,14 +79,16 @@ RSpec.describe 'Authentication Stages' doendend- context 'when enabled, but no consent info', with_settings: { consent_info: {} } do- let(:consent_required) { true }-+ context 'when enabled, but no consent info',+ with_settings: {+ consent_info: {},+ consent_required: true+ } doit 'does not show consent' doexpect(Rails.logger).to receive(:error)- .at_least(:once)- .with('Instance is configured to require consent, but no consent_info has been set.')+ .at_least(:once)+ .with('Instance is configured to require consent, but no consent_info has been set.')login_with user.login, user_passwordexpect(page).not_to have_selector('.account-consent')expect_logged_in@@ -102,8 +96,10 @@ RSpec.describe 'Authentication Stages' doendcontext 'when enabled, localized consent exists',- with_settings: { consent_info: { de: '# Einwilligung', en: '# Consent header!' } } do- let(:consent_required) { true }+ with_settings: {+ consent_required: true,+ consent_info: { de: '# Einwilligung', en: '# Consent header!' }+ } doaround do |example|Capybara.current_session.driver.header('Accept-Language', 'de')@@ -120,10 +116,12 @@ RSpec.describe 'Authentication Stages' doendend- context 'when enabled, but consent exists',+ context 'when enabled, and consent exists',:js,- with_settings: { consent_info: { en: '# Consent header!' } } do- let(:consent_required) { true }+ with_settings: {+ consent_info: { en: '# Consent header!' },+ consent_required: true+ } doafter do# Clear session to avoid that the onboarding tour starts@@ -216,13 +214,18 @@ RSpec.describe 'Authentication Stages' doendit 'keeps the autologin request (Regression #33696)',- with_settings: { autologin: 1 } do+ with_settings: {+ autologin: 1,+ consent_info: { en: '# Consent header!' },+ consent_required: true+ } do+expect(Setting::Autologin.enabled?).to be truelogin_with user.login, user_password, autologin: trueexpect(page).to have_selector('.account-consent')- expect(page).to have_selector('h2', text: 'Consent')+ expect(page).to have_selector('h1', text: 'Consent header!')# Confirm consentSeleniumHubWaiter.wait