Class: Decidim::Admin::CreateNewsletter

Inherits:
Rectify::Command
  • Object
show all
Defined in:
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, user) ⇒ CreateNewsletter

Initializes the command.

form - The source fo data for this newsletter. user - The User that authored this newsletter.



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

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

Instance Method Details

#callObject



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

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

  newsletter = Decidim.traceability.create!(
    Newsletter,
    @user,
    subject: @form.subject,
    body: @form.body,
    author: @user,
    organization: @user.organization
  )

  broadcast(:ok, newsletter)
end