Class: Decidim::Admin::UpdateNewsletter

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

Overview

Updates the newsletter given form data.

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(newsletter, form, user) ⇒ UpdateNewsletter

Initializes the command.

newsletter - The Newsletter to update. form - The form object containing the data to update. user - The user that updates the newsletter.


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

def initialize(newsletter, form, user)
  @newsletter = newsletter
  @content_block = newsletter.template
  @form = form
  @user = user
  @organization = user.organization
end

Dynamic Method Handling

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

Instance Method Details

#callObject


20
21
22
23
24
25
26
27
28
29
30
31
# File 'decidim-admin/app/commands/decidim/admin/update_newsletter.rb', line 20

def call
  return broadcast(:invalid) unless form.valid?
  return broadcast(:invalid) if newsletter.sent?
  return broadcast(:invalid) unless organization == newsletter.organization

  transaction do
    update_newsletter
    update_content_block
  end

  broadcast(:ok, newsletter)
end