Sha256: 4c71cffa5768a3f01d1499a437de1b1e3af621746b3260e9ed068e2a7c49be3d

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # A command with all the business logic when creating a new
      # media link for conference in the system.
      class CreateMediaLink < Decidim::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        # conference - The Conference that will hold the speaker
        def initialize(form, current_user, conference)
          @form = form
          @current_user = current_user
          @conference = conference
        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 form.invalid?

          transaction do
            create_media_link!
          end

          broadcast(:ok)
        end

        private

        attr_reader :form, :conference, :current_user

        def create_media_link!
          log_info = {
            resource: {
              title: form.title
            },
            participatory_space: {
              title: conference.title
            }
          }

          @media_link = Decidim.traceability.create!(
            Decidim::Conferences::MediaLink,
            current_user,
            form.attributes.slice(
              "title",
              "link",
              "weight",
              "date"
            ).symbolize_keys.merge(
              conference:
            ),
            log_info
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-conferences-0.28.4 app/commands/decidim/conferences/admin/create_media_link.rb
decidim-conferences-0.28.3 app/commands/decidim/conferences/admin/create_media_link.rb
decidim-conferences-0.28.2 app/commands/decidim/conferences/admin/create_media_link.rb
decidim-conferences-0.28.1 app/commands/decidim/conferences/admin/create_media_link.rb
decidim-conferences-0.28.0 app/commands/decidim/conferences/admin/create_media_link.rb
decidim-conferences-0.28.0.rc5 app/commands/decidim/conferences/admin/create_media_link.rb
decidim-conferences-0.28.0.rc4 app/commands/decidim/conferences/admin/create_media_link.rb