Sha256: af155770928daf1dff5d07e385d352ec0483600145449de9719a155bf7e08330

Contents?: true

Size: 1 KB

Versions: 12

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 < Rectify::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

12 entries across 12 versions & 1 rubygems

Version Path
decidim-meetings-0.26.10 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.9 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.8 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.7 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.5 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.4 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.3 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.2 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.1 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.0 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.0.rc2 app/commands/decidim/meetings/withdraw_meeting.rb
decidim-meetings-0.26.0.rc1 app/commands/decidim/meetings/withdraw_meeting.rb