Class: Decidim::Plans::RespondToAccessRequest
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Plans::RespondToAccessRequest
- Defined in:
- app/commands/decidim/plans/respond_to_access_request.rb
Overview
Common functionality for Accept,RejectAccessToPlan.
Direct Known Subclasses
Instance Method Summary collapse
- #authors_event ⇒ Object
- #authors_event_class ⇒ Object
-
#call ⇒ Object
Executes the command.
-
#initialize(form, current_user) ⇒ RespondToAccessRequest
constructor
Public: Initializes the command.
- #notify_plan_authors ⇒ Object
- #notify_plan_requester ⇒ Object
- #recipients ⇒ Object
- #requester_event ⇒ Object
- #requester_event_class ⇒ Object
Constructor Details
#initialize(form, current_user) ⇒ RespondToAccessRequest
Public: Initializes the command.
form - A form object with the params. plan - A Decidim::Plans::Plan object. current_user - The current user. requester_user - The user that requested to collaborate.
13 14 15 16 17 18 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 13 def initialize(form, current_user) @form = form @plan = form.plan @current_user = current_user @requester_user = form.requester_user end |
Instance Method Details
#authors_event ⇒ Object
67 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 67 def ; end |
#authors_event_class ⇒ Object
69 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 69 def ; end |
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if it wasn’t valid and we couldn’t proceed.
Returns nothing.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 26 def call return broadcast(:invalid) if @form.invalid? return broadcast(:invalid) if @current_user.nil? transaction do @plan.requesters.delete @requester_user Decidim::Coauthorship.create( coauthorable: @plan, author: @requester_user ) end notify_plan_requester broadcast(:ok, @requester_user) end |
#notify_plan_authors ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 44 def Decidim::EventsManager.publish( event: , event_class: , resource: @plan, followers: recipients.uniq, extra: { requester_id: @requester_user.id } ) end |
#notify_plan_requester ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 56 def notify_plan_requester Decidim::EventsManager.publish( event: requester_event, event_class: requester_event_class, resource: @plan, affected_users: [@requester_user] ) end |
#recipients ⇒ Object
65 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 65 def recipients; end |
#requester_event ⇒ Object
71 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 71 def requester_event; end |
#requester_event_class ⇒ Object
73 |
# File 'app/commands/decidim/plans/respond_to_access_request.rb', line 73 def requester_event_class; end |