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
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.rbindex 3c1759674e1..a6eae378ed2 100644--- a/app/services/users/register_user_service.rb+++ b/app/services/users/register_user_service.rb@@ -38,6 +38,7 @@ module Usersdef call%i[register_invited_user+ register_ldap_userensure_registration_allowed!ensure_user_limit_not_reached!register_by_email_activation@@ -86,6 +87,19 @@ module Usersendend+ ##+ # 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_activationreturn unless Setting::SelfRegistration.by_email?diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex 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 domail: '[email protected]'}}- 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.rbindex 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 doendend+ 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!' doit 'returns an error for disabled' doallow(Setting).to receive(:self_registration).and_return(0)