sub_sequence.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Ldap::Users::SubSequence < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Import::Common::SubSequence::Mixin::ImportJob
  4. uses :ldap_config, :ldap_connection, :dn_roles, :model_class, :external_sync_source
  5. provides :found_ids
  6. def process
  7. ldap_connection.search(ldap_config[:user_filter], attributes: relevant_attributes) do |entry|
  8. result = sequence_resource(entry)
  9. next if result[:instance].blank?
  10. found_ids.push(result[:instance].id)
  11. end
  12. state.provide(:found_ids, found_ids)
  13. end
  14. private
  15. def found_ids
  16. @found_ids ||= []
  17. end
  18. def default_params
  19. super.merge(
  20. dn_roles: dn_roles,
  21. ldap_config: ldap_config,
  22. model_class: model_class,
  23. external_sync_source: external_sync_source,
  24. signup_role_ids: signup_role_ids,
  25. found_ids: found_ids,
  26. )
  27. end
  28. def signup_role_ids
  29. @signup_role_ids ||= Role.signup_role_ids.sort
  30. end
  31. def sequence
  32. 'Import::Ldap::User'
  33. end
  34. def relevant_attributes
  35. # limit the fetched attributes for an entry to only
  36. # those which are needed to improve the performance
  37. attributes = ldap_config[:user_attributes].keys
  38. attributes.push('dn')
  39. attributes.push(ldap_config[:user_uid])
  40. attributes.uniq
  41. end
  42. end