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

Adapt account controller so that we can find existing, but e.g, locked users

Oliver Günther1f112eb94dbd
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index a66b018587a..9ff7cc1a411 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -272,7 +272,7 @@ class AccountController < ApplicationController
def auth_source_sso_failed
failure = session.delete :auth_source_sso_failure
login = failure[:login]
- user = build_user_from_auth_source(login)
+ user = find_user_from_auth_source(login) || build_user_from_auth_source(login)
if user.try(:new_record?)
return onthefly_creation_failed user, login: user.login, ldap_auth_source_id: user.ldap_auth_source_id
diff --git a/app/controllers/concerns/auth_source_sso.rb b/app/controllers/concerns/auth_source_sso.rb
index 08d4d9d45d4..dbfaef94258 100644
--- a/app/controllers/concerns/auth_source_sso.rb
+++ b/app/controllers/concerns/auth_source_sso.rb
@@ -111,6 +111,13 @@ module AuthSourceSSO
end
end
+ def find_user_from_auth_source(login)
+ User
+ .by_login(login)
+ .where.not(ldap_auth_source_id: nil)
+ .first
+ end
+
def build_user_from_auth_source(login)
attrs = LdapAuthSource.get_user_attributes(login)
return unless attrs
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index 0d7b01e0e75..da3db97aecd 100644
--- a/spec/controllers/account_controller_spec.rb
+++ b/spec/controllers/account_controller_spec.rb
@@ -1101,7 +1101,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
before do
- allow(LdapAuthSource).to receive(:find_user).and_return attrs
+ allow(LdapAuthSource).to receive(:get_user_attributes).and_return attrs
end
it "shows the account creation form with an error" do
@@ -1122,7 +1122,7 @@ RSpec.describe AccountController, :skip_2fa_stage do
end
before do
- allow(LdapAuthSource).to receive(:find_user).and_return attrs
+ allow(LdapAuthSource).to receive(:get_user_attributes).and_return attrs
end
it "shows the account creation form with an error" do
diff --git a/spec/models/ldap_auth_source_spec.rb b/spec/models/ldap_auth_source_spec.rb
index e932106156d..3c581cc6e09 100644
--- a/spec/models/ldap_auth_source_spec.rb
+++ b/spec/models/ldap_auth_source_spec.rb
@@ -273,7 +273,8 @@ RSpec.describe LdapAuthSource do
expect(user.firstname).to eq 'Bob'
expect(user).not_to be_admin
- user = ldap.find_user('ldap_admin')
+ ldap.find_user('ldap_admin')
+ user.reload
expect(user).to be_a User
expect(user.firstname).to eq 'LDAP'
expect(user.lastname).to eq 'Adminuser'
@@ -311,7 +312,8 @@ RSpec.describe LdapAuthSource do
it 'updates the user' do
expect(user.firstname).to eq 'Bob'
- user = ldap.find_user('bb459')
+ ldap.find_user('bb459')
+ user.reload
expect(user).to be_a User
expect(user.firstname).to eq 'Belle'
expect(user.lastname).to eq 'Baldwin'
@@ -402,7 +404,7 @@ RSpec.describe LdapAuthSource do
context 'with a filter string returning only users with a*' do
let(:filter_string) { '(uid=a*)' }
- it 'no longer authenticates bb254' do
+ it 'no longer authenticates bb459' do
expect(ldap.authenticate('bb459', 'niwdlab')).to be_nil
end
diff --git a/spec/requests/auth/auth_source_sso_spec.rb b/spec/requests/auth/auth_source_sso_spec.rb
index 164649e4446..b6477d4f095 100644
--- a/spec/requests/auth/auth_source_sso_spec.rb
+++ b/spec/requests/auth/auth_source_sso_spec.rb
@@ -60,7 +60,7 @@ RSpec.describe AuthSourceSSO, :skip_2fa_stage, # Prevent redirects to 2FA stage
expect(user).to be_active
expect(session[:user_id]).to eq user.id
expect(session[:user_from_auth_header]).to eq true
- expect(response).to redirect_to '/?first_time_user=true'
+ expect(response).to redirect_to '/projects'
end
end
diff --git a/spec/services/ldap/post_login_sync_service_spec.rb b/spec/services/ldap/post_login_sync_service_spec.rb
index d2ea4f0cba9..602342b0064 100644
--- a/spec/services/ldap/post_login_sync_service_spec.rb
+++ b/spec/services/ldap/post_login_sync_service_spec.rb
@@ -28,6 +28,7 @@ RSpec.describe Ldap::PostLoginSyncService do
expect(subject).to be_success
expect(subject.result).to be_a User
+ expect(subject.result).to eq user.reload
expect(subject.result).to be_valid
expect(subject.result.firstname).to eq 'Alexandra'
expect(subject.result.lastname).to eq 'Adams'