Sha256: 6576b032e8b0b81929d9221f1778f160b7b3cc58100279accbf039814eac0bb1

Contents?: true

Size: 1.72 KB

Versions: 34

Compression:

Stored size: 1.72 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

          if form.registrations_enabled
            meeting.available_slots = form.available_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,
            recipient_ids: meeting.followers.pluck(:id)
          )
        end

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

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
decidim-meetings-0.10.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.10.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.9.3 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.9.2 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.9.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.9.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.8.4 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.8.3 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.8.2 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.8.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.8.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.7.4 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.7.3 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.7.2 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.7.1 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.7.0 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.6.8 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-0.6.8 decidim-meetings/app/commands/decidim/meetings/admin/update_registrations.rb
decidim-meetings-0.6.7 app/commands/decidim/meetings/admin/update_registrations.rb
decidim-0.6.7 decidim-meetings/app/commands/decidim/meetings/admin/update_registrations.rb