Class: Decidim::Proposals::AcceptAccessToCollaborativeDraft
- Inherits:
-
Command
- Object
- Command
- Decidim::Proposals::AcceptAccessToCollaborativeDraft
- Defined in:
- app/commands/decidim/proposals/accept_access_to_collaborative_draft.rb
Overview
A command with all the business logic to accept a user request to contribute to a collaborative draft.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, current_user) ⇒ AcceptAccessToCollaborativeDraft
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, current_user) ⇒ AcceptAccessToCollaborativeDraft
Public: Initializes the command.
form - A form object with the params. collaborative_draft - A Decidim::Proposals::CollaborativeDraft object. current_user - The current user. requester_user - The user that requested to collaborate.
14 15 16 17 18 19 |
# File 'app/commands/decidim/proposals/accept_access_to_collaborative_draft.rb', line 14 def initialize(form, current_user) @form = form @collaborative_draft = form.collaborative_draft @current_user = current_user @requester_user = form.requester_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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/commands/decidim/proposals/accept_access_to_collaborative_draft.rb', line 27 def call return broadcast(:invalid) if @form.invalid? return broadcast(:invalid) if @current_user.nil? transaction do @collaborative_draft.requesters.delete @requester_user Decidim::Coauthorship.create( coauthorable: @collaborative_draft, author: @requester_user ) end notify_collaborative_draft_requester broadcast(:ok, @requester_user) end |