Class: Decidim::Plans::RequestAccessToPlan

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/plans/request_access_to_plan.rb

Overview

A command with all the business logic when a user requests access to edit a plan.

Instance Method Summary collapse

Constructor Details

#initialize(form, current_user) ⇒ RequestAccessToPlan

Public: Initializes the command.

form - A form object with the params. plan - A Decidim::Plans::Plan object. current_user - The current user and requester user



13
14
15
16
17
# File 'app/commands/decidim/plans/request_access_to_plan.rb', line 13

def initialize(form, current_user)
  @form = form
  @plan = form.plan
  @current_user = current_user
end

Instance Method Details

#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.



25
26
27
28
29
30
31
32
# File 'app/commands/decidim/plans/request_access_to_plan.rb', line 25

def call
  return broadcast(:invalid) if @form.invalid?
  return broadcast(:invalid) if @current_user.nil?

  @plan.collaborator_requests.create!(user: @current_user)
  notify_plan_authors
  broadcast(:ok, @plan)
end