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

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.rb
index 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::Settings
def show_local_breadcrumb
true
end
+
+ 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
+ end
end
end
diff --git a/app/views/admin/settings/users_settings/show.html.erb b/app/views/admin/settings/users_settings/show.html.erb
index 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.ts
index 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.rb
index 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' do
expect(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 } do
it 'does not show consent' do
login_with user.login, user_password
expect(page).not_to have_selector('.account-consent')
@@ -87,14 +79,16 @@ RSpec.describe 'Authentication Stages' do
end
end
- 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
+ } do
it 'does not show consent' do
expect(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_password
expect(page).not_to have_selector('.account-consent')
expect_logged_in
@@ -102,8 +96,10 @@ RSpec.describe 'Authentication Stages' do
end
context '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!' }
+ } do
around do |example|
Capybara.current_session.driver.header('Accept-Language', 'de')
@@ -120,10 +116,12 @@ RSpec.describe 'Authentication Stages' do
end
end
- 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
+ } do
after do
# Clear session to avoid that the onboarding tour starts
@@ -216,13 +214,18 @@ RSpec.describe 'Authentication Stages' do
end
it '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 true
login_with user.login, user_password, autologin: true
expect(page).to have_selector('.account-consent')
- expect(page).to have_selector('h2', text: 'Consent')
+ expect(page).to have_selector('h1', text: 'Consent header!')
# Confirm consent
SeleniumHubWaiter.wait