Class: Decidim::Admin::UpdateOrganization

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

Overview

A command with all the business logic for updating the current organization.

Instance Method Summary collapse

Constructor Details

#initialize(organization, form) ⇒ UpdateOrganization

Public: Initializes the command.

organization - The Organization that will be updated. form - A form object with the params.



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

def initialize(organization, form)
  @organization = organization
  @form = form
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :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
# File 'decidim-admin/app/commands/decidim/admin/update_organization.rb', line 23

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

  update_organization

  if @organization.valid?
    broadcast(:ok, @organization)
  else
    form.errors.add(:official_img_header, @organization.errors[:official_img_header]) if @organization.errors.include? :official_img_header
    form.errors.add(:official_img_footer, @organization.errors[:official_img_footer]) if @organization.errors.include? :official_img_footer
    broadcast(:invalid)
  end
end