Sha256: 256b4e22ecbe93bf2b67d5d81db597dab17a1603f3df20574704d2225dd6e216

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Verifications
    # A command to revoke authorizations
    class RevokeAllAuthorizations < Decidim::Command
      # Public: Initializes the command.
      #
      # organization - Organization object.
      # current_user - The current user.
      def initialize(organization, current_user)
        @organization = organization
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the handler wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless @organization

        auths = Decidim::Verifications::Authorizations.new(
          organization: organization,
          granted: true
        ).query

        auths.find_each do |auth|
          Decidim.traceability.perform_action!(
            :destroy,
            auth,
            current_user
          ) do
            auth.destroy
          end
        end

        broadcast(:ok)
      end

      private

      attr_reader :organization, :current_user
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-verifications-0.27.9 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.8 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.7 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.6 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.5 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.4 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.3 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.2 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.1 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.0 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.0.rc2 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.27.0.rc1 app/commands/decidim/verifications/revoke_all_authorizations.rb