Sha256: 39caa23e2b25c7ae631e5513bf39ade1b565cbe16372c352de913c520e513f87
Contents?: true
Size: 1.55 KB
Versions: 7
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true module Decidim module Admin # Updates the newsletter given form data. class UpdateNewsletter < Decidim::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 ContentBlocks::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
7 entries across 7 versions & 1 rubygems