Sha256: ef2e18992c4792b0047abaceda11ea0f10bfcc3b8293b21c15de94fca4329983

Contents?: true

Size: 1 KB

Versions: 14

Compression:

Stored size: 1 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.find_by(meeting: @meeting, user: @user)
      end

      def destroy_registration
        registration.destroy!
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-meetings-0.14.4 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.14.3 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.14.2 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.14.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.13.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.12.2 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.13.0 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.12.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.13.0.pre1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.12.0 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.11.2 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.12.0.pre app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.11.1 app/commands/decidim/meetings/leave_meeting.rb
decidim-meetings-0.11.0.pre1 app/commands/decidim/meetings/leave_meeting.rb