Sha256: 1925690d2354f945e6b591f6242aa250c0696a13d064ab548019d92c50998daa

Contents?: true

Size: 1.52 KB

Versions: 48

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # A command with all the business logic when updating a conference
      # speaker in the system.
      class UpdateMediaLink < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        # media_link - The ConferenceSpeaker to update
        def initialize(form, media_link)
          @form = form
          @media_link = media_link
        end

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

          transaction do
            update_media_link!
          end

          broadcast(:ok)
        end

        private

        attr_reader :form, :media_link

        def update_media_link!
          log_info = {
            resource: {
              title: media_link.title
            },
            participatory_space: {
              title: media_link.conference.title
            }
          }

          Decidim.traceability.update!(
            media_link,
            form.current_user,
            form.attributes.slice(
              :title,
              :link,
              :weight,
              :date
            ),
            log_info
          )
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

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