Sha256: 3696634619a2963cca184588e2de87b7aa401f88fe937a6e023f4eaaa3554748

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command is executed when the user destroys an Election
      # from the admin panel.
      class DestroyElection < Decidim::Command
        include ::Decidim::GalleryMethods

        def initialize(election, current_user)
          @election = election
          @current_user = current_user
          @attached_to = election
        end

        # Destroys the election if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if invalid?

          destroy_election!

          broadcast(:ok, election)
        end

        private

        attr_reader :election, :current_user

        def invalid?
          election.blocked?
        end

        def destroy_election!
          Decidim.traceability.perform_action!(
            :delete,
            election,
            current_user,
            visibility: "all"
          ) do
            election.destroy!
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/commands/decidim/elections/admin/destroy_election.rb
decidim-elections-0.28.3 app/commands/decidim/elections/admin/destroy_election.rb
decidim-elections-0.28.2 app/commands/decidim/elections/admin/destroy_election.rb
decidim-elections-0.28.1 app/commands/decidim/elections/admin/destroy_election.rb
decidim-elections-0.28.0 app/commands/decidim/elections/admin/destroy_election.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/elections/admin/destroy_election.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/elections/admin/destroy_election.rb