Sha256: 88fbcb1d754a6e07b94da2e212e2053fecf2bea800c3c0b15069833ba6f56e20
Contents?: true
Size: 1.22 KB
Versions: 14
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Decidim module Blogs module Admin # This command is executed when the user creates a Post from the admin # panel. class CreatePost < Rectify::Command def initialize(form, current_user) @form = form @current_user = current_user end # Creates the post if valid. # # Broadcasts :ok if successful, :invalid otherwise. def call return broadcast(:invalid) if @form.invalid? transaction do create_post! send_notification end broadcast(:ok, @post) end private def create_post! @post = Post.create!( title: @form.title, body: @form.body, component: @form.current_component, decidim_author_id: @current_user.id ) end def send_notification Decidim::EventsManager.publish( event: "decidim.events.blogs.post_created", event_class: Decidim::Blogs::CreatePostEvent, resource: @post, recipient_ids: @post.participatory_space.followers.pluck(:id) ) end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems