Class: Decidim::Plans::AcceptAccessToPlan

Inherits:
RespondToAccessRequest show all
Defined in:
app/commands/decidim/plans/accept_access_to_plan.rb

Overview

A command with all the business logic to accept a user request to contribute to a plan.

Instance Method Summary collapse

Methods inherited from RespondToAccessRequest

#initialize, #notify_plan_authors, #notify_plan_requester

Constructor Details

This class inherits a constructor from Decidim::Plans::RespondToAccessRequest

Instance Method Details

#authors_eventObject



36
37
38
# File 'app/commands/decidim/plans/accept_access_to_plan.rb', line 36

def authors_event
  "decidim.events.plans.plan_access_accepted"
end

#authors_event_classObject



40
41
42
# File 'app/commands/decidim/plans/accept_access_to_plan.rb', line 40

def authors_event_class
  Decidim::Plans::PlanAccessAcceptedEvent
end

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if it wasn’t valid and we couldn’t proceed.

Returns nothing.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/commands/decidim/plans/accept_access_to_plan.rb', line 14

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
  notify_plan_authors
  broadcast(:ok, @requester_user)
end

#recipientsObject



32
33
34
# File 'app/commands/decidim/plans/accept_access_to_plan.rb', line 32

def recipients
  @plan.authors - [@requester_user]
end

#requester_eventObject



44
45
46
# File 'app/commands/decidim/plans/accept_access_to_plan.rb', line 44

def requester_event
  "decidim.events.plans.plan_access_requester_accepted"
end

#requester_event_classObject



48
49
50
# File 'app/commands/decidim/plans/accept_access_to_plan.rb', line 48

def requester_event_class
  Decidim::Plans::PlanAccessRequesterAcceptedEvent
end