Class: Decidim::Admin::UpdateOrganizationAppearance

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(organization, form) ⇒ UpdateOrganizationAppearance

Public: Initializes the command.

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


12
13
14
15
16
17
18
# File 'decidim-admin/app/commands/decidim/admin/update_organization_appearance.rb', line 12

def initialize(organization, form)
  image_fields.each do |field|
    form.send("#{field}=".to_sym, organization.send(field)) if form.send(field).blank?
  end
  @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.


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-admin/app/commands/decidim/admin/update_organization_appearance.rb', line 26

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

  begin
    update_organization
    broadcast(:ok, organization)
  rescue ActiveRecord::RecordInvalid
    image_fields.each do |field|
      form.errors.add(field, organization.errors[field]) if organization.errors.include? field
    end
    broadcast(:invalid)
  end
end