From 148a90645eea04bc13237320b1bcd78917e1b669 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Wed, 22 May 2024 10:04:54 +0200 Subject: [PATCH] fix: update code to handle case where there are no follows --- .../admin/destroy_participatory_space_private_user.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/decidim-admin/app/commands/decidim/admin/destroy_participatory_space_private_user.rb b/decidim-admin/app/commands/decidim/admin/destroy_participatory_space_private_user.rb index 9b6e72de1199f..7304270c42b0e 100644 --- a/decidim-admin/app/commands/decidim/admin/destroy_participatory_space_private_user.rb +++ b/decidim-admin/app/commands/decidim/admin/destroy_participatory_space_private_user.rb @@ -28,11 +28,12 @@ def run_after_hooks follows = Decidim::Follow.where(user:) ids << follows.where(decidim_followable_type: resource.privatable_to_type) .where(decidim_followable_id: space.id) - .first.id + &.first&.id children_ids = follows.select { |follow| find_object_followed(follow).respond_to?("decidim_component_id") } .select { |follow| space.components.ids.include?(find_object_followed(follow).decidim_component_id) } - .map(&:id) + &.map(&:id) ids << children_ids + follows.where(id: ids.flatten).destroy_all if ids.present? end