Class: Decidim::EnhancedTextwork::DestroyParagraph

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

Overview

A command with all the business logic when a user destroys a draft paragraph.

Instance Method Summary collapse

Constructor Details

#initialize(paragraph, current_user) ⇒ DestroyParagraph

Public: Initializes the command.

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



11
12
13
14
# File 'app/commands/decidim/enhanced_textwork/destroy_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 and the paragraph is deleted.

  • :invalid if the paragraph is not a draft.

  • :invalid if the paragraph's author is not the current user.

Returns nothing.



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

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

  @paragraph.destroy!

  broadcast(:ok, @paragraph)
end