Sha256: 7dcf79dfe2e596eca9022240680658cc9cb834c35e0ab9b0f8e3b97bbe91fa10

Contents?: true

Size: 1.37 KB

Versions: 33

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Decidim
  module Debates
    module Admin
      # A command with all the business logic when an admin closes a debate.
      class CloseDebate < Rectify::Command
        # Public: Initializes the command.
        #
        # form         - A form object with the params.
        def initialize(form)
          @form = form
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid, together with the debate.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if form.invalid?

          close_debate
          broadcast(:ok, debate)
        end

        private

        attr_reader :form

        def close_debate
          @debate = Decidim.traceability.perform_action!(
            :close,
            form.debate,
            form.current_user
          ) do
            form.debate.update!(
              conclusions: form.conclusions,
              closed_at: form.closed_at
            )
          end

          Decidim::EventsManager.publish(
            event: "decidim.events.debates.debate_closed",
            event_class: Decidim::Debates::CloseDebateEvent,
            resource: debate,
            followers: debate.followers
          )
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

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