Class: Decidim::Proposals::PublishCollaborativeDraft

Inherits:
Rectify::Command
  • Object
show all
Defined in:
decidim-proposals/app/commands/decidim/proposals/publish_collaborative_draft.rb

Overview

A command with all the business logic when a user publishes a collaborative_draft.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collaborative_draft, current_user) ⇒ PublishCollaborativeDraft

Public: Initializes the command.

collaborative_draft - The collaborative_draft to publish. current_user - The current user. proposal_form - the form object of the new proposal


12
13
14
15
# File 'decidim-proposals/app/commands/decidim/proposals/publish_collaborative_draft.rb', line 12

def initialize(collaborative_draft, current_user)
  @collaborative_draft = collaborative_draft
  @current_user = current_user
end

Instance Attribute Details

#new_proposalObject

Returns the value of attribute new_proposal


37
38
39
# File 'decidim-proposals/app/commands/decidim/proposals/publish_collaborative_draft.rb', line 37

def new_proposal
  @new_proposal
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid and the collaborative_draft is published.

  • :invalid if the collaborative_draft's author is not the current user.

Returns nothing.


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'decidim-proposals/app/commands/decidim/proposals/publish_collaborative_draft.rb', line 23

def call
  return broadcast(:invalid) unless @collaborative_draft.open?
  return broadcast(:invalid) unless @collaborative_draft.authored_by? @current_user

  transaction do
    reject_access_to_collaborative_draft
    publish_collaborative_draft
    create_proposal!
    link_collaborative_draft_and_proposal
  end

  broadcast(:ok, @new_proposal)
end