Sha256: 5d88ec4789da79a651d6654e8968d480f4c69f8a49b1506fbf759bcdcc2c6504

Contents?: true

Size: 1.34 KB

Versions: 31

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # A command with all the business logic when an admin creates a private note proposal.
      class CreateProposalNote < Rectify::Command
        # Public: Initializes the command.
        #
        # form         - A form object with the params.
        # proposal - the proposal to relate.
        def initialize(form, proposal)
          @form = form
          @proposal = proposal
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid, together with the note proposal.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if form.invalid?

          create_proposal_note

          broadcast(:ok, proposal_note)
        end

        private

        attr_reader :form, :proposal_note, :proposal

        def create_proposal_note
          @proposal_note = Decidim.traceability.create!(
            ProposalNote,
            form.current_user,
            {
              body: form.body,
              proposal: proposal,
              author: form.current_user
            },
            resource: {
              title: proposal.title
            }
          )
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-proposals-0.21.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.20.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.20.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.19.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.18.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.19.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.17.2 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.18.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.17.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.16.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.17.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.16.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.15.2 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.15.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.15.0 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.14.4 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.14.3 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.14.2 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.14.1 app/commands/decidim/proposals/admin/create_proposal_note.rb
decidim-proposals-0.13.1 app/commands/decidim/proposals/admin/create_proposal_note.rb