Class: Decidim::EnhancedTextwork::Admin::UpdateParagraphScope

Inherits:
Rectify::Command
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
app/commands/decidim/enhanced_textwork/admin/update_paragraph_scope.rb

Overview

A command with all the business logic when an admin batch updates paragraphs scope.

Instance Method Summary collapse

Constructor Details

#initialize(scope_id, paragraph_ids) ⇒ UpdateParagraphScope

Public: Initializes the command.

scope_id - the scope id to update paragraph_ids - the paragraphs ids to update.



13
14
15
16
17
# File 'app/commands/decidim/enhanced_textwork/admin/update_paragraph_scope.rb', line 13

def initialize(scope_id, paragraph_ids)
  @scope = Decidim::Scope.find_by id: scope_id
  @paragraph_ids = paragraph_ids
  @response = { scope_name: "", successful: [], errored: [] }
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :update_paragraphs_scope - when everything is ok, returns @response.

  • :invalid_scope - if the scope is blank.

  • :invalid_paragraph_ids - if the paragraph_ids is blank.

Returns @response hash:

  • :scope_name - the translated_name of the scope assigned

  • :successful - Array of names of the updated paragraphs

  • :errored - Array of names of the paragraphs not updated because they already had the scope assigned



30
31
32
33
34
35
36
37
# File 'app/commands/decidim/enhanced_textwork/admin/update_paragraph_scope.rb', line 30

def call
  return broadcast(:invalid_scope) if @scope.blank?
  return broadcast(:invalid_paragraph_ids) if @paragraph_ids.blank?

  update_paragraphs_scope

  broadcast(:update_paragraphs_scope, @response)
end