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
Fix flickering tests and deprecation warnings
Christophe Bliard9c7d115bde0b
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rbindex a018534a3b9..d3bed857f2b 100644--- a/app/controllers/account_controller.rb+++ b/app/controllers/account_controller.rb@@ -140,7 +140,7 @@ class AccountController < ApplicationControllerenddef allow_registration?- allow = Setting.self_registration? && !OpenProject::Configuration.disable_password_login?+ allow = Setting::SelfRegistration.enabled? && !OpenProject::Configuration.disable_password_login?invited = session[:invitation_token].present?get = request.get? && allow@@ -163,7 +163,7 @@ class AccountController < ApplicationControllerhandle_expired_token tokenelsif token.user.invited?activate_by_invite_token token- elsif Setting.self_registration?+ elsif Setting::SelfRegistration.enabled?activate_self_registered tokenelseinvalid_token_and_redirectdiff --git a/app/controllers/concerns/accounts/current_user.rb b/app/controllers/concerns/accounts/current_user.rbindex 49d068af4d9..2207b1cc985 100644--- a/app/controllers/concerns/accounts/current_user.rb+++ b/app/controllers/concerns/accounts/current_user.rb@@ -70,7 +70,7 @@ module Accounts::CurrentUserif session[:user_id]# existing sessionUser.active.find_by(id: session[:user_id])- elsif cookies[OpenProject::Configuration['autologin_cookie_name']] && Setting.autologin?+ elsif cookies[OpenProject::Configuration['autologin_cookie_name']] && Setting::Autologin.enabled?# auto-login feature starts a new sessionuser = User.try_to_autologin(cookies[OpenProject::Configuration['autologin_cookie_name']])session[:user_id] = user.id if userdiff --git a/app/controllers/concerns/accounts/user_login.rb b/app/controllers/concerns/accounts/user_login.rbindex bde69d21168..0fb1faf7a3a 100644--- a/app/controllers/concerns/accounts/user_login.rb+++ b/app/controllers/concerns/accounts/user_login.rb@@ -4,7 +4,7 @@ module Accounts::UserLogindef login_user!(user)# generate a key and set cookie if autologin- if Setting.autologin? && (params[:autologin] || session.delete(:autologin_requested))+ if Setting::Autologin.enabled? && (params[:autologin] || session.delete(:autologin_requested))set_autologin_cookie(user)enddiff --git a/app/controllers/concerns/accounts/user_password_change.rb b/app/controllers/concerns/accounts/user_password_change.rbindex 3bf19717e20..67aeb84df12 100644--- a/app/controllers/concerns/accounts/user_password_change.rb+++ b/app/controllers/concerns/accounts/user_password_change.rb@@ -71,7 +71,7 @@ module Accounts::UserPasswordChangeendflash_error_message(log_reason: 'invalid credentials', flash_now:) do- if Setting.brute_force_block_after_failed_logins?+ if Setting.brute_force_block_after_failed_logins.to_i > 0:notice_account_invalid_credentials_or_blockedelse:notice_account_invalid_credentialsdiff --git a/app/models/setting/autologin.rb b/app/models/setting/autologin.rbnew file mode 100644index 00000000000..ef4cc102f5e--- /dev/null+++ b/app/models/setting/autologin.rb@@ -0,0 +1,35 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class Setting+ module Autologin+ def self.enabled?+ Setting.autologin.presence != 0+ end+ end+enddiff --git a/app/models/setting/self_registration.rb b/app/models/setting/self_registration.rbindex e030998eda5..60b768639a3 100644--- a/app/models/setting/self_registration.rb+++ b/app/models/setting/self_registration.rb@@ -36,6 +36,7 @@ class Settingmanual_activation: 2,automatic_activation: 3}.freeze+ KEYS = VALUES.invert.merge(VALUES.invert.transform_keys(&:to_s)).freezedef self.valuesVALUES@@ -46,7 +47,7 @@ class Settingenddef self.key(value:)- VALUES.find { |_k, v| v == value || v.to_s == value.to_s }&.first+ KEYS[value]enddef self.disabled@@ -57,6 +58,10 @@ class Settingkey(value: Setting.self_registration) == :disabledend+ def self.enabled?+ !disabled?+ end+def self.by_emailvalue key: :activation_by_emailenddiff --git a/app/views/account/_login.html.erb b/app/views/account/_login.html.erbindex f4d5484d99f..6a27052e3fc 100644--- a/app/views/account/_login.html.erb+++ b/app/views/account/_login.html.erb@@ -39,10 +39,10 @@ See COPYRIGHT and LICENSE files for more details.<%= styled_text_field_tag 'username', nil, id: 'username-pulldown', tabindex: 1, autocapitalize: 'none' %></div><div class="form--field-extra-actions">- <% if Setting.autologin? %>+ <% if Setting::Autologin.enabled? %><label class="form--label-with-check-box"><%= styled_check_box_tag 'autologin', 1, false, id: 'autologin-pulldown' %> <%= t(:label_stay_logged_in) %></label>- <% elsif Setting.self_registration? %>+ <% elsif Setting::SelfRegistration.enabled? %><%# show here if autologin is disabled, otherwise below lost_password link %><%= link_to t(:label_register),account_register_path,@@ -60,7 +60,7 @@ See COPYRIGHT and LICENSE files for more details.<% if Setting.lost_password? %><%= link_to t(:label_password_lost), {controller: '/account', action: 'lost_password'} %><% end %>- <% if Setting.autologin? && Setting.self_registration? %>+ <% if Setting::Autologin.enabled? && Setting::SelfRegistration.enabled? %><%# show here if autologin is enabled, otherwise below login field %><%= '<br>'.html_safe if Setting.lost_password? %><%= link_to t(:label_register),diff --git a/app/views/account/_password_login_form.html.erb b/app/views/account/_password_login_form.html.erbindex 652283888b4..65266d65af9 100644--- a/app/views/account/_password_login_form.html.erb+++ b/app/views/account/_password_login_form.html.erb@@ -44,7 +44,7 @@ See COPYRIGHT and LICENSE files for more details.</div></div>- <% if Setting.autologin? %>+ <% if Setting::Autologin.enabled? %><div class="form--field -no-label"><div class="form--field-container"><label class="form--label-with-check-box">@@ -66,7 +66,7 @@ See COPYRIGHT and LICENSE files for more details.<%= link_to t(:label_password_lost), { controller: '/account', action: 'lost_password' } %><br><% end %>- <% if Setting.self_registration? %>+ <% if Setting::SelfRegistration.enabled? %><%= link_to t(:label_register),'',title: t(:label_register),diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex c83b9391375..23d1a3e3199 100644--- a/spec/controllers/account_controller_spec.rb+++ b/spec/controllers/account_controller_spec.rb@@ -189,12 +189,11 @@ describe AccountController,expect(response).to redirect_to my_page_pathend- context 'with an auth source' do+ context 'with an auth source',+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dolet(:auth_source) { create :ldap_auth_source }it 'creates the user on the fly' do- allow(Setting).to receive(:self_registration).and_return('0')- allow(Setting).to receive(:self_registration?).and_return(false)allow(AuthSource).to receive(:authenticate).and_return(login: 'foo',firstname: 'Foo',lastname: 'Smith',@@ -405,7 +404,8 @@ describe AccountController,endend- context 'with an auth source' do+ context 'with an auth source',+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dolet(:auth_source) { create :ldap_auth_source }let(:user_attributes) do@@ -421,8 +421,6 @@ describe AccountController,let(:authenticate) { true }before do- allow(Setting).to receive(:self_registration).and_return('0')- allow(Setting).to receive(:self_registration?).and_return(false)allow(AuthSource).to receive(:authenticate).and_return(authenticate ? user_attributes : nil)# required so that the register view can be rendered@@ -550,11 +548,8 @@ describe AccountController,endcontext 'GET #register' do- context 'with self registration on' do- before do- allow(Setting).to receive(:self_registration).and_return('3')- end-+ context 'with self registration on',+ with_settings: { self_registration: Setting::SelfRegistration.automatic } docontext 'and password login enabled' dobefore doget :register@@ -579,22 +574,20 @@ describe AccountController,endend- context 'with self registration off' do+ context 'with self registration off',+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dobefore do- allow(Setting).to receive(:self_registration).and_return('0')- allow(Setting).to receive(:self_registration?).and_return(false)get :registerendit_behaves_like 'registration disabled'end- context 'with self registration off but an ongoing invitation activation' do+ context 'with self registration off but an ongoing invitation activation',+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dolet(:token) { create :invitation_token }before do- allow(Setting).to receive(:self_registration).and_return('0')- allow(Setting).to receive(:self_registration?).and_return(false)session[:invitation_token] = token.valueget :register@@ -610,10 +603,10 @@ describe AccountController,# See integration/account_test.rb for the full testcontext 'POST #register' do- context 'with self registration on automatic' do+ context 'with self registration on automatic',+ with_settings: { self_registration: Setting::SelfRegistration.automatic } dobefore doallow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(false)- allow(Setting).to receive(:self_registration).and_return('3')endcontext 'with password login enabled' do@@ -718,11 +711,8 @@ describe AccountController,endend- context 'with self registration by email' do- before do- allow(Setting).to receive(:self_registration).and_return('1')- end-+ context 'with self registration by email',+ with_settings: { self_registration: Setting::SelfRegistration.by_email } docontext 'with password login enabled' dobefore doToken::Invitation.delete_all@@ -769,7 +759,8 @@ describe AccountController,endend- context 'with manual activation' do+ context 'with manual activation',+ with_settings: { self_registration: Setting::SelfRegistration.manual } dolet(:user_hash) do{ login: 'register',password: 'adminADMIN!',@@ -779,10 +770,6 @@ describe AccountController,mail: '[email protected]' }end- before do- allow(Setting).to receive(:self_registration).and_return('2')- end-context 'without back_url' dobefore dopost :register, params: { user: user_hash }@@ -834,10 +821,9 @@ describe AccountController,endend- context 'with self registration off' do+ context 'with self registration off',+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dobefore do- allow(Setting).to receive(:self_registration).and_return('0')- allow(Setting).to receive(:self_registration?).and_return(false)post :register,params: {user: {@@ -854,10 +840,9 @@ describe AccountController,it_behaves_like 'registration disabled'end- context 'with on-the-fly registration' do+ context 'with on-the-fly registration',+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dobefore do- allow(Setting).to receive(:self_registration).and_return('0')- allow(Setting).to receive(:self_registration?).and_return(false)allow_any_instance_of(User).to receive(:change_password_allowed?).and_return(false)allow(AuthSource).to receive(:authenticate).and_return(login: 'foo',lastname: 'Smith',diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rbindex 59352c3d587..23ed42be921 100644--- a/spec/controllers/concerns/omniauth_login_spec.rb+++ b/spec/controllers/concerns/omniauth_login_spec.rb@@ -468,7 +468,7 @@ describe AccountController,endcontext 'with a locked account',- with_settings: { brute_force_block_after_failed_logins?: false } do+ with_settings: { brute_force_block_after_failed_logins: 0 } dobefore douser.lockuser.save!diff --git a/spec/features/auth/consent_auth_stage_spec.rb b/spec/features/auth/consent_auth_stage_spec.rbindex b8f70749cbe..abe0ca14aa9 100644--- a/spec/features/auth/consent_auth_stage_spec.rb+++ b/spec/features/auth/consent_auth_stage_spec.rb@@ -74,7 +74,7 @@ describe 'Authentication Stages', type: :feature doit 'keeps the autologin request (Regression #33696)',with_settings: { autologin: '1' } do- expect(Setting.autologin?).to be true+ expect(Setting::Autologin.enabled?).to be truelogin_with user.login, user_password, autologin: trueexpect(page).to have_no_selector('.account-consent')@@ -211,7 +211,7 @@ describe 'Authentication Stages', type: :feature doit 'keeps the autologin request (Regression #33696)',with_settings: { autologin: '1' } do- expect(Setting.autologin?).to be true+ expect(Setting::Autologin.enabled?).to be truelogin_with user.login, user_password, autologin: truediff --git a/spec/features/auth/login_spec.rb b/spec/features/auth/login_spec.rbindex ff2383fa4d9..08ee87c84bb 100644--- a/spec/features/auth/login_spec.rb+++ b/spec/features/auth/login_spec.rb@@ -138,12 +138,6 @@ describe 'Login', type: :feature dopage.driver.browser.set_cookie(OpenProject::Configuration['session_cookie_name'])end- before do- allow(Setting)- .to receive(:autologin?)- .and_return(true)- end-it 'logs in the user automatically if enabled' dologin_with(user.login, user_password, autologin: true)@@ -155,9 +149,7 @@ describe 'Login', type: :feature dofake_browser_closed# faking having changed the autologin setting- allow(Setting)- .to receive(:autologin?)- .and_return(false)+ with_settings(autologin: 0)visit my_page_path# expect not being logged in automaticallydiff --git a/spec/features/auth/omniauth_spec.rb b/spec/features/auth/omniauth_spec.rbindex 94428089c7a..c71aaf01568 100644--- a/spec/features/auth/omniauth_spec.rb+++ b/spec/features/auth/omniauth_spec.rb@@ -175,7 +175,7 @@ describe 'Omniauth authentication', type: :feature docontext 'register on the fly',with_settings: {self_registration?: true,- self_registration: '3',+ self_registration: Setting::SelfRegistration.automatic,available_languages: [:en]} dolet(:user) do@@ -218,8 +218,7 @@ describe 'Omniauth authentication', type: :feature docontext 'registration by email',with_settings: {- self_registration?: true,- self_registration: Setting::SelfRegistration.by_email.to_s+ self_registration: Setting::SelfRegistration.by_email} doshared_examples 'registration with registration by email' doit 'shows a note explaining that the account has to be activated' do