Sha256: 2fc568272a15cb84b1b15cab3308c0a87a7d2bd51d769e194e5d280432a30fcc

Contents?: true

Size: 1.12 KB

Versions: 12

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # This command is executed when the user declines an invite to the meeting.
    class DeclineInvitation < Decidim::Command
      # Initializes a DeclineInvitation Command.
      #
      # meeting - The current instance of the meeting where user has been invited.
      # user - The user that declines their invitation
      def initialize(meeting, user)
        @meeting = meeting
        @user = user
      end

      # Creates a meeting registration if the meeting has registrations enabled
      # and there are available slots.
      #
      # Broadcasts :ok if successful, :invalid otherwise.
      def call
        return broadcast(:invalid) unless can_decline_invitation?

        decline_invitation

        broadcast(:ok)
      end

      private

      attr_reader :meeting, :user

      def decline_invitation
        invitation.decline!
      end

      def can_decline_invitation?
        meeting.registrations_enabled? && invitation.present?
      end

      def invitation
        @invitation ||= meeting.invites.find_by(user: user)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-meetings-0.27.9 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.8 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.7 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.6 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.5 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.4 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.3 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.2 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.1 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.0 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.0.rc2 app/commands/decidim/meetings/decline_invitation.rb
decidim-meetings-0.27.0.rc1 app/commands/decidim/meetings/decline_invitation.rb