Sha256: f4bc9c947548a8f5325b5d80d6e514885823e1494328f8b95f07fb7998cdb33b

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # A command with all the business logic that publishes an
      # existing conference speaker.
      class PublishConferenceSpeaker < Decidim::Command
        # Public: Initializes the command.
        #
        # conference_speaker - Decidim::Conferences::Admin::ConferenceSpeaker
        # current_user - the user performing the action
        def initialize(conference_speaker, current_user)
          @conference_speaker = conference_speaker
          @current_user = current_user
        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
          return broadcast(:invalid) if conference_speaker.published?

          transaction do
            publish_conference_speaker
          end

          broadcast(:ok, conference_speaker)
        end

        private

        attr_reader :conference_speaker, :current_user

        def publish_conference_speaker
          @conference_speaker = Decidim.traceability.perform_action!(
            :publish,
            conference_speaker,
            current_user
          ) do
            conference_speaker.publish!
            conference_speaker
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-conferences-0.29.1 app/commands/decidim/conferences/admin/publish_conference_speaker.rb
decidim-conferences-0.29.0 app/commands/decidim/conferences/admin/publish_conference_speaker.rb
decidim-conferences-0.29.0.rc4 app/commands/decidim/conferences/admin/publish_conference_speaker.rb
decidim-conferences-0.29.0.rc3 app/commands/decidim/conferences/admin/publish_conference_speaker.rb
decidim-conferences-0.29.0.rc2 app/commands/decidim/conferences/admin/publish_conference_speaker.rb
decidim-conferences-0.29.0.rc1 app/commands/decidim/conferences/admin/publish_conference_speaker.rb