Sha256: 19f3db9256bf3b2f31a62fd60a3eaaed66f9d9bc2cd7d2d4f521ac3dd4a3f3c7

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 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 < Rectify::Command
        include ::Decidim::AttachmentMethods
        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.started?
        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

31 entries across 31 versions & 1 rubygems

Version Path
decidim-elections-0.26.7 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.5 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.4 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.3 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.2 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.1 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.0 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.2 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.1 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.0 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.24.3 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.23.6 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.24.2 app/commands/decidim/elections/admin/destroy_answer.rb
decidim-elections-0.23.5 app/commands/decidim/elections/admin/destroy_answer.rb