Sha256: 64483ad66e8ab9b42e03a9c6e39e7afc670d7412dad5d40fa924e0eccc60fa9e

Contents?: true

Size: 1.46 KB

Versions: 39

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    module Admin
      # A command that sets an conference as published.
      class PublishConference < Rectify::Command
        # Public: Initializes the command.
        #
        # conference - A Conference that will be published
        # current_user - the user performing the action
        def initialize(conference, current_user)
          @conference = conference
          @current_user = current_user
        end

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

          Decidim.traceability.perform_action!("publish", conference, current_user) do
            conference.publish!
          end

          broadcast(:ok)
          send_notification
        end

        private

        attr_reader :conference, :current_user

        def send_notification
          return unless conference.registrations_enabled?

          Decidim::EventsManager.publish(
            event: "decidim.events.conferences.registrations_enabled",
            event_class: Decidim::Conferences::ConferenceRegistrationsEnabledEvent,
            resource: conference,
            followers: conference.followers
          )
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

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