Class: Decidim::Amendable::PublishDraft
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Amendable::PublishDraft
- Defined in:
- app/commands/decidim/amendable/publish_draft.rb
Overview
A command with all the business logic when a user publishes an amendment draft.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ PublishDraft
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ PublishDraft
Public: Initializes the command.
form - A form object with the params.
10 11 12 13 14 15 16 17 |
# File 'app/commands/decidim/amendable/publish_draft.rb', line 10 def initialize(form) @form = form @amendment = form.amendment @amendable = form.amendable @emendation = form.emendation @amender = form.amender @current_user = form.current_user end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid, together with the amend.
-
:invalid if the amendment is not a draft.
-
:invalid if the form isn’t valid or the amender is not the current user.
Returns nothing.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/commands/decidim/amendable/publish_draft.rb', line 26 def call return broadcast(:invalid) unless form.valid? && amendment.draft? && amender == current_user transaction do set_first_emendation_version publish_emendation change_amendment_state_to_evaluating notify_emendation_state_change! end broadcast(:ok, emendation) end |