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

Ensure LDAP users can get activated with any registration setting

Oliver Günther894ba4ae6db8
diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rb
index 3c1759674e1..a6eae378ed2 100644
--- a/app/services/users/register_user_service.rb
+++ b/app/services/users/register_user_service.rb
@@ -38,6 +38,7 @@ module Users
def call
%i[
register_invited_user
+ register_ldap_user
ensure_registration_allowed!
ensure_user_limit_not_reached!
register_by_email_activation
@@ -86,6 +87,19 @@ module Users
end
end
+ ##
+ # Try to register a user with an auth source connection
+ # bypassing regular restrictions
+ def register_ldap_user
+ return unless user.auth_source_id.present?
+
+ user.activate
+
+ with_saved_user_result(success_message: I18n.t(:notice_account_registered_and_logged_in)) do
+ Rails.logger.info { "User #{user.login} was successfully activated after invitation." }
+ end
+ end
+
def register_by_email_activation
return unless Setting::SelfRegistration.by_email?
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index 3e321e63d53..7c43b6af584 100644
--- a/spec/controllers/account_controller_spec.rb
+++ b/spec/controllers/account_controller_spec.rb
@@ -879,7 +879,7 @@ describe AccountController, type: :controller do
}
}
- expect(response).to redirect_to '/my/account'
+ expect(response).to redirect_to home_path(first_time_user: true)
user = User.find_by_login('foo')
diff --git a/spec/services/users/register_user_service_spec.rb b/spec/services/users/register_user_service_spec.rb
index 6deab41658f..856c9bb9b78 100644
--- a/spec/services/users/register_user_service_spec.rb
+++ b/spec/services/users/register_user_service_spec.rb
@@ -59,6 +59,24 @@ describe Users::RegisterUserService do
end
end
+ describe '#register_ldap_user' do
+ it 'tries to activate that user regardless of settings' do
+ with_all_registration_options do |_type|
+ user = User.new(status: Principal::STATUSES[:registered])
+ instance = described_class.new(user)
+
+ allow(user).to receive(:auth_source_id).and_return 1234
+ expect(user).to receive(:activate)
+ expect(user).to receive(:save).and_return true
+
+ call = instance.call
+ expect(call).to be_success
+ expect(call.result).to eq user
+ expect(call.message).to eq I18n.t(:notice_account_registered_and_logged_in)
+ end
+ end
+ end
+
describe '#ensure_registration_allowed!' do
it 'returns an error for disabled' do
allow(Setting).to receive(:self_registration).and_return(0)