Class: Decidim::Feeds::Admin::UpdateFeed

Inherits:
Command
  • Object
show all
Includes:
MultipleAttachmentsMethods
Defined in:
app/commands/decidim/feeds/admin/update_feed.rb

Overview

A command with all the business logic when creating a new participatory feed in the system.

Instance Method Summary collapse

Constructor Details

#initialize(feed, form) ⇒ UpdateFeed

Public: Initializes the command.

feed - the Feed to update form - A form object with the params.



15
16
17
18
19
# File 'app/commands/decidim/feeds/admin/update_feed.rb', line 15

def initialize(feed, form)
  @feed = feed
  @form = form
  @attached_to = feed
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.
  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/commands/decidim/feeds/admin/update_feed.rb', line 27

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

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

  update_feed
  # link_participatory_processes(@feed)
  document_cleanup!(include_all_attachments: true)
  create_attachments if process_attachments?

  if @feed.valid?
    broadcast(:ok, @feed)
  else
    # form.errors.add(:hero_image, @feed.errors[:hero_image]) if @feed.errors.include? :hero_image
    # form.errors.add(:banner_image, @feed.errors[:banner_image]) if @feed.errors.include? :banner_image
    broadcast(:invalid)
  end
end