Class: Decidim::Proposals::RequestAccessToCollaborativeDraft
- Inherits:
-
Command
- Object
- Command
- Decidim::Proposals::RequestAccessToCollaborativeDraft
- Defined in:
- app/commands/decidim/proposals/request_access_to_collaborative_draft.rb
Overview
A command with all the business logic when a user requests access to edit a collaborative draft.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, current_user) ⇒ RequestAccessToCollaborativeDraft
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, current_user) ⇒ RequestAccessToCollaborativeDraft
Public: Initializes the command.
form - A form object with the params. collaborative_draft - A Decidim::Proposals::CollaborativeDraft object. current_user - The current user and requester user
13 14 15 16 17 |
# File 'app/commands/decidim/proposals/request_access_to_collaborative_draft.rb', line 13 def initialize(form, current_user) @form = form @collaborative_draft = form.collaborative_draft @current_user = current_user end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if it was not valid and we could not proceed.
Returns nothing.
25 26 27 28 29 30 31 32 |
# File 'app/commands/decidim/proposals/request_access_to_collaborative_draft.rb', line 25 def call return broadcast(:invalid) if @form.invalid? return broadcast(:invalid) if @current_user.nil? @collaborative_draft.collaborator_requests.create!(user: @current_user) broadcast(:ok, @collaborative_draft) end |