Class: Decidim::Admin::BulkAction

Inherits:
Command
  • Object
show all
Defined in:
decidim-admin/app/commands/decidim/admin/bulk_action.rb

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(current_user, action, selected_moderations) ⇒ BulkAction

Public: Initializes the command.

current_user - the user that performs the action action - can be hide, unhide and unreport resources selected_moderations - all resources selected by current_user



11
12
13
14
15
16
# File 'decidim-admin/app/commands/decidim/admin/bulk_action.rb', line 11

def initialize(current_user, action, selected_moderations)
  @current_user = current_user
  @action = action
  @selected_moderations = selected_moderations
  @result = { ok: [], ko: [] }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

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

  • :invalid if the resource is not reported

Returns nothing.



24
25
26
27
28
29
30
31
# File 'decidim-admin/app/commands/decidim/admin/bulk_action.rb', line 24

def call
  return broadcast(:invalid) if selected_moderations.blank?

  process_reportables
  create_action_log if selected_moderations.first.reportable

  broadcast(:ok, **result)
end