Sha256: 562539c5b7eab6e55e73eac429f5c13b2db43b1bbd82ec9405b5ec47980d2c96

Contents?: true

Size: 1.42 KB

Versions: 7

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,
            recipient_ids: [form.registration.user.id],
            extra: {
              registration: form.registration
            }
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-meetings-0.15.2 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.15.1 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.15.0 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.14.4 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.14.3 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.14.2 app/commands/decidim/meetings/admin/validate_registration_code.rb
decidim-meetings-0.14.1 app/commands/decidim/meetings/admin/validate_registration_code.rb