Sha256: 2e1d8f197a7f41426d5623b52a7b50aa426b06b69746cb9fb9517b73bb19213c

Contents?: true

Size: 1 KB

Versions: 20

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # A command with all the business logic when a user withdraws a new proposal.
    class WithdrawMeeting < Decidim::Command
      # Public: Initializes the command.
      #
      # meeting     - The meeting to withdraw.
      # current_user - The current user.
      def initialize(meeting, current_user)
        @meeting = meeting
        @current_user = current_user
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid, together with the meeting.
      # - :invalid if the meeting does not belong to current user.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) unless @meeting.authored_by?(@current_user)

        transaction do
          change_meeting_state_to_withdrawn
        end

        broadcast(:ok, @meeting)
      end

      private

      def change_meeting_state_to_withdrawn
        @meeting.update state: "withdrawn"
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
decidim-meetings-0.28.5 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.4 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.9 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.3 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.8 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.2 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.7 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.1 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.6 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.0 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.5 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.0.rc5 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.28.0.rc4 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.4 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.3 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.2 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.1 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.0 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.0.rc2 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.27.0.rc1 app/commands/decidim/meetings/withdraw_meeting.rb