Sha256: dba61435a8f85451f647740d69788ac0c5b30be70cf99d8723cdbe124599eaa2
Contents?: true
Size: 1.53 KB
Versions: 34
Compression:
Stored size: 1.53 KB
Contents
# frozen_string_literal: true module Decidim module Admin # Updates the newsletter given form data. class UpdateNewsletter < Rectify::Command # Initializes the command. # # newsletter - The Newsletter to update. # form - The form object containing the data to update. # user - The user that updates the newsletter. def initialize(newsletter, form, user) @newsletter = newsletter @content_block = newsletter.template @form = form @user = user @organization = user.organization end 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 private attr_reader :user, :newsletter, :content_block, :organization, :form def update_newsletter @newsletter = Decidim.traceability.update!( newsletter, user, subject: form.subject, author: user ) end def update_content_block UpdateContentBlock.call(form, content_block, user) do on(:ok) do |content_block| @content_block = content_block end on(:invalid) do raise "There was a problem persisting the changes to the content block" end end end end end end
Version data entries
34 entries across 34 versions & 1 rubygems