Sha256: 4233da7a475b0deb046206510a53e13e2656e2e49bb853813e96a2858ed2a8a1

Contents?: true

Size: 1.42 KB

Versions: 21

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # This command is executed when the admin validates a registration code in the admin panel.
      class ValidateRegistrationCode < Rectify::Command
        # Initializes a ValidateRegistrationCode 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

        # Validates the registration code the meeting if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if form.invalid?

          validate_registration_code
          send_notification

          broadcast(:ok)
        end

        private

        attr_reader :form, :meeting

        def validate_registration_code
          form.registration.update!(validated_at: Time.current)
        end

        def send_notification
          Decidim::EventsManager.publish(
            event: "decidim.events.meetings.registration_code_validated",
            event_class: Decidim::Meetings::RegistrationCodeValidatedEvent,
            resource: meeting,
            affected_users: [form.registration.user],
            extra: {
              registration: form.registration
            }
          )
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-meetings-0.23.6 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.5 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.4 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.3 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.2 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.1.rc1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.23.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.22.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.21.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.20.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.20.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.19.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.18.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.19.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.17.2 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.18.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.17.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.16.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.17.0 app/commands/decidim/meetings/admin/validate_registration_code.rb