Prior to this commit, we may have left lingering podcast entries that required manual cleanup. As a bonus, I also added deleting podcasts when we delete users. Closes forem/forem#18041 In addition I adjusted rubocop to not complain about the require method call ``` spec/services/users/delete_spec.rb:1:1: C: \ Style/TopLevelMethodDefinition: \ Do not define methods at the top-level. \ (https://rubystyle.guide#top-level-methods) require "rails_helper" ^^^^^^^^^^^^^^^^^^^^^^ ```
31 lines
830 B
Ruby
31 lines
830 B
Ruby
module Users
|
|
module DeletePodcasts
|
|
def self.call(user)
|
|
return unless user
|
|
|
|
# We'll want to bust the podcast paths that match our criteria.
|
|
paths = []
|
|
user.podcast_ownerships.includes(:podcast).find_each do |ownership|
|
|
ownership.destroy
|
|
|
|
podcast = ownership.podcast
|
|
# Guard against ownership without podcast
|
|
next if podcast.blank?
|
|
|
|
# We have another owner, don't delete the podcast.
|
|
next if PodcastOwnership.where(podcast: podcast).where.not(user_id: user.id).exists?
|
|
|
|
# No sense keeping the roles around.
|
|
Role.where(resource: podcast).destroy_all
|
|
|
|
paths << podcast.path if podcast.path.present?
|
|
|
|
podcast.destroy
|
|
end
|
|
|
|
paths.each do |path|
|
|
EdgeCache::BustPodcast.call(path)
|
|
end
|
|
end
|
|
end
|
|
end
|