Sha256: f85f6cb2a0418afa21368595ddb6958f12a358ebcbda0e8b965679da0d9dbe9b

Contents?: true

Size: 1.15 KB

Versions: 34

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Decidim
  module Verifications
    # A command to revoke authorizations
    class RevokeAllAuthorizations < Rectify::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

34 entries across 34 versions & 1 rubygems

Version Path
decidim-verifications-0.26.10 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.9 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.8 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.7 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.5 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.4 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.3 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.2 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.1 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.0 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.0.rc2 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.26.0.rc1 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.2 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.1 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.0 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.0.rc4 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.0.rc3 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.0.rc2 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.25.0.rc1 app/commands/decidim/verifications/revoke_all_authorizations.rb
decidim-verifications-0.24.3 app/commands/decidim/verifications/revoke_all_authorizations.rb