Skip to content

Commit

Permalink
fix: deletes the follows of destroyed private user for assembly that …
Browse files Browse the repository at this point in the history
…is not transparent and its components
  • Loading branch information
Stef-Rousset committed May 20, 2024
1 parent be194fe commit ede1275
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ def extra_params
}
}
end

def run_after_hooks
# A hook to destroy the follows of user on private non transparent assembly and its children
# when private user is destroyed
return unless resource.privatable_to_type == "Decidim::Assembly"

assembly = Decidim::Assembly.find(resource.privatable_to_id)
return unless assembly.private_space == true && assembly.is_transparent == false

user = Decidim::User.find(resource.decidim_user_id)
ids = []
ids << Decidim::Follow.where(user:)
.where(decidim_followable_type: "Decidim::Assembly")
.where(decidim_followable_id: assembly.id)
.first.id
children_ids = Decidim::Follow.where(user:)
.select { |follow| find_object(follow).respond_to?("decidim_component_id") }
.select { |follow| assembly.components.ids.include?(find_object(follow).decidim_component_id) }
.map(&:id)
ids << children_ids
Decidim::Follow.where(user:).where(id: ids.flatten).destroy_all if ids.present?
end

def find_object(follow)
follow.decidim_followable_type.constantize.find(follow.decidim_followable_id)
end
end
end
end

0 comments on commit ede1275

Please sign in to comment.