Class: Decidim::ReportingProposals::CreateReportingProposal

Inherits:
Proposals::CreateProposal
  • Object
show all
Includes:
MultipleAttachmentsMethods, Proposals::GalleryMethods
Defined in:
app/commands/decidim/reporting_proposals/create_reporting_proposal.rb

Instance Method Summary collapse

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/commands/decidim/reporting_proposals/create_reporting_proposal.rb', line 9

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

  if process_attachments?
    build_attachments
    return broadcast(:invalid) if attachments_invalid?
  end

  if process_gallery?
    build_gallery
    return broadcast(:invalid) if gallery_invalid?
  end

  if proposal_limit_reached?
    form.errors.add(:base, I18n.t("decidim.proposals.new.limit_reached"))
    return broadcast(:invalid)
  end

  transaction do
    create_reporting_proposal

    @attached_to = @proposal
    create_gallery if process_gallery?
    create_attachments if process_attachments?
  end

  broadcast(:ok, proposal)
end