OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/app/services/ldap/synchronize_users_service.rb

37 lines
988 B

module Ldap
class SynchronizeUsersService < BaseService
attr_reader :logins
def initialize(ldap, logins = nil)
super(ldap)
@logins = logins
end
private
def perform
ldap_con = new_ldap_connection
applicable_users.find_each do |user|
synchronize_user(user, ldap_con)
rescue ::AuthSource::Error => e
Rails.logger.error { "Failed to synchronize user #{ldap.name} due to LDAP error: #{e.message}" }
# Reset the LDAP connection
ldap_con = new_ldap_connection
rescue StandardError => e
Rails.logger.error { "Failed to synchronize user #{ldap.name}: #{e.message}" }
end
end
# Get the applicable users
# as the service can be called with just a subset of users
# from rake/external services.
def applicable_users
if logins.present?
ldap.users.where("LOWER(login) in (?)", logins.map(&:downcase))
else
ldap.users
end
end
end
end