diff --git a/app/assets/javascripts/app/controllers/_integration/ldap.coffee b/app/assets/javascripts/app/controllers/_integration/ldap.coffee index 282d2785c..dc0bbbdef 100644 --- a/app/assets/javascripts/app/controllers/_integration/ldap.coffee +++ b/app/assets/javascripts/app/controllers/_integration/ldap.coffee @@ -124,7 +124,7 @@ class Form extends App.Controller if _.isEmpty(job) @lastImport.html('') return - countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped + job.result.failed + job.result.deactivated + countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped + job.result.failed if !job.result.roles job.result.roles = {} for role_id, statistic of job.result.role_ids @@ -545,8 +545,6 @@ class ConnectionWizard extends App.WizardModal total += job.result.unchanged if job.result.updated total += job.result.updated - if job.result.deactivated - total += job.result.deactivated @$('.js-progress progress').attr('value', total) @$('.js-progress progress').attr('max', job.result.sum) if job.finished_at @@ -568,7 +566,7 @@ class ConnectionWizard extends App.WizardModal for role_id, statistic of job.result.role_ids role = App.Role.find(role_id) job.result.roles[role.displayName()] = statistic - countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped + job.result.deactivated + countDone = job.result.created + job.result.updated + job.result.unchanged + job.result.skipped @showSlide('js-try') el = $(App.view('integration/ldap_summary')(job: job, countDone: countDone)) @el.find('.js-summary').html(el) diff --git a/lib/import/ldap/user.rb b/lib/import/ldap/user.rb index a474be240..19eaba32f 100644 --- a/lib/import/ldap/user.rb +++ b/lib/import/ldap/user.rb @@ -6,7 +6,7 @@ module Import @remote_id end - def self.lost_ids(found_remote_ids) + def self.lost_map(found_remote_ids) ExternalSync.joins('INNER JOIN users ON (users.id = external_syncs.o_id)') .where( source: source, @@ -18,7 +18,6 @@ module Import .pluck(:source_id, :o_id) .to_h .except(*found_remote_ids) - .values end def self.deactivate_lost(lost_ids) diff --git a/lib/import/ldap/user_factory.rb b/lib/import/ldap/user_factory.rb index 49a4b3c02..3ed6f40ee 100644 --- a/lib/import/ldap/user_factory.rb +++ b/lib/import/ldap/user_factory.rb @@ -33,7 +33,8 @@ module Import relevant_attributes = config[:user_attributes].keys relevant_attributes.push('dn') - @found_remote_ids = [] + @found_lost_remote_ids = [] + @found_remote_ids = [] @ldap.search(config[:user_filter], attributes: relevant_attributes) do |entry| backend_instance = create_instance(entry, config, user_roles, signup_role_ids, kargs) post_import_hook(entry, backend_instance, config, user_roles, signup_role_ids, kargs) @@ -122,23 +123,32 @@ module Import end def self.track_found_remote_ids(backend_instance) + remote_id = backend_instance.remote_id(nil) @deactivation_actions ||= %i(skipped failed) - return if @deactivation_actions.include?(backend_instance.action) - - @found_remote_ids.push(backend_instance.remote_id(nil)) + if @deactivation_actions.include?(backend_instance.action) + @found_lost_remote_ids.push(remote_id) + else + @found_remote_ids.push(remote_id) + end end def self.handle_lost backend_class = backend_class(nil) - lost_ids = backend_class.lost_ids(@found_remote_ids) + lost_map = backend_class.lost_map(@found_remote_ids) - # track disabled count and substract it from - # skipped where they are logged till now - @statistics[:deactivated] = lost_ids.size - @statistics[:skipped] -= lost_ids.size + # disabled count is tracked as a separate number + # since they don't have to be in the sum (e.g. deleted in LDAP) + @statistics[:deactivated] = lost_map.size + + # skipped deactivated are those who + # were found, skipped and will get deactivated + skipped_deactivated = @found_lost_remote_ids & lost_map.keys + @statistics[:skipped] -= skipped_deactivated.size # loop over every lost user ID and add the # deactivated count to the statistics + lost_ids = lost_map.values + lost_ids.each do |user_id| role_ids = ::User.joins(:roles) .where(id: user_id)