Class: Decidim::Admin::UpdateOrganizationTosVersion

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

Overview

A command with the business logic for updating the current organization tos_version attribute.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(organization, page, form) ⇒ UpdateOrganizationTosVersion

Public: Initializes the command.

organization - The Organization that will be updated. page - A static_page instance (slug = “terms-of-service”). form - A form object with the params.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid or not the TOS page.

Returns nothing.



25
26
27
28
29
30
31
32
# File 'decidim-admin/app/commands/decidim/admin/update_organization_tos_version.rb', line 25

def call
  return broadcast(:invalid) if @form.nil?
  return broadcast(:invalid) if @page.nil?
  return broadcast(:invalid) unless @page.slug == "terms-of-service"

  update_organization_tos_version
  broadcast(:ok)
end