Class: Decidim::Meetings::WithdrawMeeting

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/meetings/withdraw_meeting.rb

Overview

A command with all the business logic when a user withdraws a new proposal.

Instance Method Summary collapse

Constructor Details

#initialize(meeting, current_user) ⇒ WithdrawMeeting

Public: Initializes the command.

meeting - The meeting to withdraw. current_user - The current user.



11
12
13
14
# File 'app/commands/decidim/meetings/withdraw_meeting.rb', line 11

def initialize(meeting, current_user)
  @meeting = meeting
  @current_user = current_user
end

Instance Method Details

#callObject

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.



22
23
24
25
26
27
28
29
30
# File 'app/commands/decidim/meetings/withdraw_meeting.rb', line 22

def call
  return broadcast(:invalid) unless @meeting.authored_by?(@current_user)

  transaction do
    change_meeting_state_to_withdrawn
  end

  broadcast(:ok, @meeting)
end