Sha256: 2b5ec1142126056a571d25722238925446dfceaeac8abd067658f579136ed5e9

Contents?: true

Size: 1.01 KB

Versions: 34

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # This command is executed when the user leaves a meeting.
    class LeaveMeeting < Rectify::Command
      # Initializes a LeaveMeeting Command.
      #
      # meeting - The current instance of the meeting to be left.
      # user - The user leaving the meeting.
      def initialize(meeting, user)
        @meeting = meeting
        @user = user
      end

      # Destroys a meeting registration if the meeting has registrations enabled
      # and the registration exists.
      #
      # Broadcasts :ok if successful, :invalid otherwise.
      def call
        @meeting.with_lock do
          return broadcast(:invalid) unless registration
          destroy_registration
        end
        broadcast(:ok)
      end

      private

      def registration
        @registration ||= Decidim::Meetings::Registration.where(meeting: @meeting, user: @user).first
      end

      def destroy_registration
        registration.destroy!
      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/leave_meeting.rb
decidim-meetings-0.10.0 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.9.3 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.9.2 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.9.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.9.0 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.8.4 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.8.3 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.8.2 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.8.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.8.0 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.7.4 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.7.3 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.7.2 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.7.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.7.0 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.6.8 app/commands/decidim/meetings/leave_meeting.rb
decidim-0.6.8 decidim-meetings/app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.6.7 app/commands/decidim/meetings/leave_meeting.rb
decidim-0.6.7 decidim-meetings/app/commands/decidim/meetings/leave_meeting.rb