Class: Decidim::Proposals::PublishCollaborativeDraft
- Inherits:
-
Command
- Object
- Command
- Decidim::Proposals::PublishCollaborativeDraft
- Defined in:
- 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
-
#new_proposal ⇒ Object
Returns the value of attribute new_proposal.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(collaborative_draft, current_user) ⇒ PublishCollaborativeDraft
constructor
Public: Initializes the command.
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 '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_proposal ⇒ Object
Returns the value of attribute new_proposal.
37 38 39 |
# File 'app/commands/decidim/proposals/publish_collaborative_draft.rb', line 37 def new_proposal @new_proposal end |
Instance Method Details
#call ⇒ Object
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 '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. @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 |