forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cfc85e
commit 1a5e2b2
Showing
2 changed files
with
39 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
decidim-admin/app/jobs/decidim/admin/destroy_private_users_follows_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Admin | ||
# Custom ApplicationJob scoped to the admin panel. | ||
# | ||
class DestroyPrivateUsersFollowsJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(decidim_user_id, privatable_to_type, space) | ||
follows = Decidim::Follow.where(user: decidim_user_id) | ||
destroy_space_follow(follows, privatable_to_type, space) | ||
destroy_children_follows(follows, space) | ||
end | ||
|
||
def destroy_space_follow(follows, privatable_to_type, space) | ||
follows.where(decidim_followable_type: privatable_to_type) | ||
.where(decidim_followable_id: space.id).destroy_all | ||
end | ||
|
||
def destroy_children_follows(follows, space) | ||
follows.map do |follow| | ||
object = find_object_followed(follow).presence | ||
next unless object.respond_to?("decidim_component_id") | ||
|
||
follow.destroy if space.component_ids.include?(object.decidim_component_id) | ||
end | ||
end | ||
|
||
def find_object_followed(follow) | ||
follow.decidim_followable_type.constantize.find(follow.decidim_followable_id) | ||
end | ||
end | ||
end | ||
end |