Sha256: 216edb4098bee6c22cbf33e66e7a1143f7b043d9b840d688a27fc23a6abba3e3

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # A command with all the business logic to invite users to join a meeting.
      #
      class InviteUserToJoinMeeting < Rectify::Command
        # Public: Initializes the command.
        #
        # form         - A form object with the params.
        # meeting      - The meeting which the user is invited to.
        # invited_by   - The user performing the operation
        def initialize(form, meeting, invited_by)
          @form = form
          @meeting = meeting
          @invited_by = invited_by
        end

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

          invite_user

          broadcast(:ok)
        end

        private

        attr_reader :form, :invited_by, :meeting

        def invite_user
          if user.persisted?
            InviteJoinMeetingMailer.invite(user, meeting, invited_by).deliver_later
          else
            user.name = form.name
            user.skip_reconfirmation!
            user.invite!(invited_by, invitation_instructions: "join_meeting", meeting: meeting)
          end
        end

        def user
          @user ||= Decidim::User.find_or_create_by(
            organization: form.current_organization,
            email: form.email.downcase
          )
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-meetings-0.9.2 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.9.1 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.9.0 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.8.4 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.8.3 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.8.2 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.8.1 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.8.0 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.7.4 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.7.3 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.7.2 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.7.1 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb
decidim-meetings-0.7.0 app/commands/decidim/meetings/admin/invite_user_to_join_meeting.rb