Class: Decidim::Admin::CreateNewsletter

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

Overview

Creates a newsletter and assigns the right author and organization.

Instance Method Summary collapse

Constructor Details

#initialize(form, content_block, user) ⇒ CreateNewsletter

Initializes the command.

form - The source fo data for this newsletter. content_block - An instance of `Decidim::ContentBlock` that holds the

newsletter attributes.

user - The User that authored this newsletter.


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

def initialize(form, content_block, user)
  @form = form
  @content_block = content_block
  @user = user
end

Instance Method Details

#callObject


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

def call
  return broadcast(:invalid) unless form.valid?

  transaction do
    create_newsletter
    create_content_block
  end

  broadcast(:ok, newsletter)
end