Class: Decidim::EnhancedTextwork::WithdrawParagraph

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/enhanced_textwork/withdraw_paragraph.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(paragraph, current_user) ⇒ WithdrawParagraph

Public: Initializes the command.

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



11
12
13
14
# File 'app/commands/decidim/enhanced_textwork/withdraw_paragraph.rb', line 11

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid, together with the paragraph.

  • :has_supports if the paragraph already has supports or does not belong to current user.

Returns nothing.



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

def call
  return broadcast(:has_supports) if @paragraph.votes.any?

  transaction do
    change_paragraph_state_to_withdrawn
    reject_emendations_if_any
  end

  broadcast(:ok, @paragraph)
end