Class: Decidim::Verifications::RevokeAuthorizationsByConditionJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/decidim/verifications/revoke_authorizations_by_condition_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(organization, current_user, before_date, impersonated_only) ⇒ Object

Revokes the organization’s granted authorizations created before the given date, optionally limited to impersonated users only.

Parameters:

  • organization (Decidim::Organization)

    The organization whose authorizations will be revoked

  • current_user (Decidim::User)

    the current user.

  • before_date (Date)

    Only authorizations created before this date are revoked

  • impersonated_only (Boolean)

    When true, only impersonated users’ authorizations are revoked



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/jobs/decidim/verifications/revoke_authorizations_by_condition_job.rb', line 15

def perform(organization, current_user, before_date, impersonated_only)
  authorizations_to_revoke = if impersonated_only
                               Decidim::Verifications::AuthorizationsBeforeDate.new(
                                 organization:,
                                 date: before_date,
                                 granted: true,
                                 impersonated_only:
                               )
                             else
                               Decidim::Verifications::AuthorizationsBeforeDate.new(
                                 organization:,
                                 date: before_date,
                                 granted: true
                               )
                             end

  auths = authorizations_to_revoke.query.includes(transfers: :records)
  auths.find_each do |auth|
    Decidim.traceability.perform_action!(
      :destroy,
      auth,
      current_user
    ) do
      auth.destroy
    end
  end
end