Class: Decidim::Admin::BulkAction

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

Instance Method Summary collapse

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 '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

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 '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