Sha256: 93f65ee31f53b7ffd4940c89dad371a4404fd850aad1540aeb0bb90f0324b39d

Contents?: true

Size: 1 KB

Versions: 13

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # A command with all the business logic related with an admin discarding participatory text proposals.
      class DiscardParticipatoryText < Decidim::Command
        # Public: Initializes the command.
        #
        # form - A PreviewParticipatoryTextForm form object with the params.
        def initialize(component)
          @component = component
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if the form was not valid and we could not proceed.
        #
        # Returns nothing.
        def call
          transaction do
            discard_drafts
          end

          broadcast(:ok)
        end

        private

        attr_reader :form

        def discard_drafts
          proposals = Decidim::Proposals::Proposal.drafts.where(component: @component)
          proposals.destroy_all
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-proposals-0.29.1 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.4 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.29.0 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.3 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.29.0.rc4 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.29.0.rc3 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.29.0.rc2 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.29.0.rc1 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.2 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.1 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.0 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.0.rc5 app/commands/decidim/proposals/admin/discard_participatory_text.rb
decidim-proposals-0.28.0.rc4 app/commands/decidim/proposals/admin/discard_participatory_text.rb