Class: Decidim::CreateReport

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

Overview

A command with all the business logic when a user creates a report.

Instance Method Summary collapse

Constructor Details

#initialize(form, reportable, current_user) ⇒ CreateReport

Public: Initializes the command.

form - A form object with the params. reportable - The resource being reported current_user - The current user.



11
12
13
14
15
# File 'app/commands/decidim/create_report.rb', line 11

def initialize(form, reportable, current_user)
  @form = form
  @reportable = reportable
  @current_user = current_user
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

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

  • :invalid if the form wasn’t valid and we couldn’t proceed.

Returns nothing.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/commands/decidim/create_report.rb', line 23

def call
  return broadcast(:invalid) if form.invalid?

  transaction do
    find_or_create_moderation!
    create_report!
    update_report_count!
  end

  send_report_notification_to_moderators

  if hideable?
    hide!
    send_hide_notification_to_moderators
  end

  broadcast(:ok, report)
end