Ensure LDAP users can get activated with any registration setting

LDAP users get an auth_source_id attached to them during registration,
since they are effectively not self-registrating in the system,
the register service should allow them with any self_registration setting.

At the same time, the refactoring ensure that even an LDAP user that logs in for the first
time is being redirected to home to get the welcome tour.
pull/8452/head
Oliver Günther 4 years ago
parent 6d6d6aeb09
commit 894ba4ae6d
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 14
      app/services/users/register_user_service.rb
  2. 2
      spec/controllers/account_controller_spec.rb
  3. 18
      spec/services/users/register_user_service_spec.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?

@ -879,7 +879,7 @@ describe AccountController, type: :controller do
mail: 'foo@bar.com'
}
}
expect(response).to redirect_to '/my/account'
expect(response).to redirect_to home_path(first_time_user: true)
user = User.find_by_login('foo')

@ -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)

Loading…
Cancel
Save