Sha256: 5247eb374ccf8841779b5a70881dacef075c4da3a017677c25dc9ca5454359aa

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

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

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

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

          destroy_answer

          broadcast(:ok, answer)
        end

        private

        attr_reader :answer, :current_user

        def invalid?
          answer.question.election.blocked?
        end

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

Version data entries

8 entries across 8 versions & 1 rubygems

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