Sha256: 82bc7d495e624f65fa7b93d45cc9e1d60c5fc9e325ba851f28d80a3a0de81351

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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

      # Creates a conference registration if the conference 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 :conference, :user

      def decline_invitation
        invitation.decline!
      end

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

      def invitation
        @invitation ||= conference.conference_invites.find_by(user:)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-conferences-0.29.1 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.4 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.29.0 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.3 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.29.0.rc4 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.29.0.rc3 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.29.0.rc2 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.29.0.rc1 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.2 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.1 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.0 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.0.rc5 app/commands/decidim/conferences/decline_invitation.rb
decidim-conferences-0.28.0.rc4 app/commands/decidim/conferences/decline_invitation.rb