Sha256: 55ad328cd49e9f2ae717a0545905722ab929900c89bdd6198fcb86299c140297

Contents?: true

Size: 1.84 KB

Versions: 39

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # This command is executed when the user updates the meeting registrations.
      class UpdateRegistrations < Rectify::Command
        # Initializes a UpdateRegistrations Command.
        #
        # form - The form from which to get the data.
        # meeting - The current instance of the meeting to be updated.
        def initialize(form, meeting)
          @form = form
          @meeting = meeting
        end

        # Updates the meeting if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          meeting.with_lock do
            return broadcast(:invalid) if form.invalid?

            update_meeting_registrations
            send_notification if should_notify_followers?
          end

          broadcast(:ok)
        end

        private

        attr_reader :form, :meeting

        def update_meeting_registrations
          meeting.registrations_enabled = form.registrations_enabled
          meeting.registration_form_enabled = form.registration_form_enabled

          if form.registrations_enabled
            meeting.available_slots = form.available_slots
            meeting.reserved_slots = form.reserved_slots
            meeting.registration_terms = form.registration_terms
          end

          meeting.save!
        end

        def send_notification
          Decidim::EventsManager.publish(
            event: "decidim.events.meetings.registrations_enabled",
            event_class: Decidim::Meetings::MeetingRegistrationsEnabledEvent,
            resource: meeting,
            followers: meeting.followers
          )
        end

        def should_notify_followers?
          meeting.previous_changes["registrations_enabled"].present? && meeting.registrations_enabled?
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
decidim-meetings-0.23.6 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.24.2 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.5 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.24.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.24.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.24.0.rc2 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.4 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.24.0.rc1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.3 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.2 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.1.rc1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.23.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.22.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.21.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.20.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.20.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.19.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.19.0 app/commands/decidim/meetings/admin/update_registrations.rb